The robot places many buy/sell market orders during a crossover please help

To add comments, please log in or register
17003821
30
17003821  
#include<Trade\Trade.mqh>
CTrade trade;

void OnTick()
  {
//---
   double wma54MovingAverageArray[],sma5MovingAverageArray[];
   double wma54=iMA(NULL,5,54,0,MODE_LWMA,PRICE_CLOSE);
   double sma5=iMA(NULL,5,5,0,MODE_SMA,PRICE_CLOSE);
   ArraySetAsSeries(wma144MovingAverageArray,true);
   ArraySetAsSeries(sma5MovingAverageArray,true);

   CopyBuffer(wma54,0,0,3,wma54MovingAverageArray);
   CopyBuffer(sma5,0,0,3,sma5MovingAverageArray);
   double Ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
   double Bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);


   if(
      (sma5MovingAverageArray[0]>wma54MovingAverageArray[0])
      && (sma5MovingAverageArray[1]<wma54MovingAverageArray[1])
      )
     {
      
         trade.Buy(0.01,NULL,Ask,Ask-150*_Point,Ask+200*_Point,NULL);
     }
      
     
                 
               if(
                  (sma5MovingAverageArray[0]<wma54MovingAverageArray[0])
                  && (sma5MovingAverageArray[1]>wma54MovingAverageArray[1])
                  )
                 {
                  trade.Sell(0.01,NULL,Bid,Bid+150*_Point,Bid-200*_Point,NULL);
                 }

Sergey Golubev
Moderator
106148
Sergey Golubev  
17003821
30
17003821  
Sergey Golubev:


Thank you I edited it

Osama Shaban
1549
Osama Shaban  
Sergey Golubev:


As long as it places those many orders just after the condition is met, then you should add return(0) or just return after the ordersend function

to stop opening more orders. Also, you need to show the code in some way (depends on the method you use) that the condition is met or a new bar

is opened, or, ...

Showing the code is the only way to solve such problem.

17003821
30
17003821  
Osama Shaban:

As long as it places those many orders just after the condition is met, then you should add return(0) or just return after the ordersend function

to stop opening more orders. Also, you need to show the code in some way (depends on the method you use) that the condition is met or a new bar

is opened, or, ...

Showing the code is the only way to solve such problem.


Thank Osama.  I have attached the code where exactly should I place return (0) 

Anthony Garot
1818
Anthony Garot  
17003821:

Check out the example code on this page under the heading "Putting It All Together."

https://www.mql5.com/en/articles/496


Specifically, you probably want to use this line to see if a position already exists and act accordingly.

m_Position.Select(my_symbol)
17003821
30
17003821  
Anthony Garot:

Check out the example code on this page under the heading "Putting It All Together."

https://www.mql5.com/en/articles/496


Specifically, you probably want to use this line to see if a position already exists and act accordingly.


Thank you let me try that

To add comments, please log in or register