0

LI have found a code which sends http request via MQL4 Expert Adviser and modified it for my personal EA logic.

Technically, it works, but there is a huge problem, it sends requests on every tick. I need to change it to - one request per each signal.

Please help me to solve it!

Code Example:

#import    "shell32.dll" // -------------------------------<BegOfImport>-section

int ShellExecuteW( int    hwnd,
                   string lpOperation,
                   string lpFile,
                   string lpParameters,
                   string lpDirectory,
                   int    nShowCmd
                   );

#import // "shell32.dll" // -------------------------------<EndOfImport>-section


if (  A > B
   && 1 > OrdersTotal()
      )
{
   if (  OrderSend( Symbol(), OP_SELL, 1, Bid, 10, 0, 0, 0, 0, 0, clrGreen )
         )
         OrderSelect( 0, SELECT_BY_POS, NULL );
   ShellExecuteW( 0, "open", linkS, "", "", 1 );
   }
user3666197
  • 1
  • 6
  • 50
  • 92
Tinto
  • 33
  • 5

1 Answers1

0

And how about trading?

Is EA sending trade requests on every tick?

Currently it tries to send a trade (which is not guaranteed, i.e. requote or slippage or market closed / trading disabled etc.)

If you need on each new signal - think maybe you need to check on each new bar, or keep the recent trade direction in memory or the recent time of signal in memory.

void OnTick(){ 
   if (  A > B && OrdersTotal() < 1 ){
         int ticket = OrderSend( Symbol(),OP_SELL,1,Bid,10,0,0,0,0,0,clrGreen );
         if (  ticket > 0 ){ // this means ticket is opened successfully, OrdersTotal = 1
               if (  OrderSelect( 0, SELECT_BY_POS ) ) { } // for what???
         ShellExecuteW( 0, "open", linkS, "", "", 1 );
      }
   }
}  

In such case, if ticket is opened, then ShellExecute() is called, in other cases - not.

Not sure why you OrderSelect() a ticket, maybe for stoplosses.

Anyway you should also find out why it is rejected in case it is

int   ticket  = OrderSend( Symbol(), OP_SELL, 1, Bid, 10, 0, 0, 0, 0, 0, clrGreen );
if (  ticket >  0 ){

}else{
   int error = GetLastError();
   Print( " failed to send. error#", error );
}
user3666197
  • 1
  • 6
  • 50
  • 92
Daniel Kniaz
  • 4,603
  • 2
  • 14
  • 20