How to code such EA

 

Hello!

I want my EA to open new order when price is x-pips from last open order. EA opens buy when price is x-pips over last candle close. Then I want to open another buy when price is x-pips over from last open buy. I try like this but doesn't work. Thanks!

for(cnt=OrdersTotal()-1;cnt>=0;cnt--){
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if( (OrderType()<=OP_SELL) && (OrderSymbol()==Symbol()) ){
        if(OrderType()==OP_BUY){           
            if(OrderOpenPrice() < Bid - Ordersdifference) {
               double Loti1=OrderLots();
               odprt=-1;
               while(odprt<0){
                  odprt=OrderSend(Symbol(),OP_BUY,Loti1,Ask,5*places,0,0,"HedgeEA",MagicNumber,0,Green);
                  RefreshRates();
                  Sleep(1000);
               }
               if(odprt>0){
                  if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order sent : ",OrderOpenPrice());
               }
               else{
                  Print("Error sending BUY order : ",GetLastError()); 
                  return(0); 
               }
               return(0);
            }
        }
 
01005379:

Hello!

I want my EA to open new order when price is x-pips from last open order. EA opens buy when price is x-pips over last candle close. Then I want to open another buy when price is x-pips over from last open buy. I try like this but doesn't work. Thanks!


First you need to loop throug all orders to determine the highest open buy/lowest open sell.

After the loop you can open the new one .. if (Close[0]>LastBuyPrice+x*Point) OrderSend(:::)

 

Isn't this loop throug all orders?

for(cnt=OrdersTotal()-1;cnt>=0;cnt--)
 

can i c please what the var. Ordersdifference contains

 

It extern variable.

extern double Ordersdifference=0.0003;
 

try to use NormalizeDouble for that

 

oops check out MarketInfo(Symbol(),MODE_STOPLEVEL)

i think it's to small 0.0003

 
Problem is that EA opens many orders when rule is OK. For BUY it opens one order, but then when price goes up about 3pips it opens many orders and not only one as I want. Maybe it does't chack last order open price...
 
qjol:

oops check out MarketInfo(Symbol(),MODE_STOPLEVEL)

i think it's to small 0.003


But there is no stop level or take profit level. Why would there be a problem?
 
01005379:
Problem is that EA opens many orders when rule is OK. For BUY it opens one order, but then when price goes up about 3pips it opens many orders and not only one as I want. Maybe it does't chack last order open price...

use return

 
Can you please tell me where and why?
Reason: