EA opening positions at the same price

 

Hi there,


i am having a hard time trying to figure out why this script below is opening more than one position, as you can see, it opens a sell order when all the criteria are true, the problem is, when price hits stop(high) or take profit(lowestprice) and goes back to order price(close) it reopens the position. What can i do to change that,i need a insight, if anybody read this and reply, thank you so far.

if(((high>higheastprice)&&(close<open)&&(open<higheastprice)&&(signal==0)&&(signal1==0)&&(signal2==0)&&(signal3==0)&&(signal4==0)&&(signal5==0)&&(OrdersTotal()==0)&&(PositionsTotal()==0)))



{



trade.SellStop(0.10,close,_Symbol,high,lowestprice,ORDER_TIME_DAY,0,0);  

}
}
 
will_lipe:

Hi there,


i am having a hard time trying to figure out why this script below is opening more than one position, as you can see, it opens a sell order when all the criteria are true, the problem is, when price hits stop(high) or take profit(lowestprice) and goes back to order price(close) it reopens the position. What can i do to change that,i need a insight, if anybody read this and reply, thank you so far.

try this

if((OrdersTotal()==0)&&(PositionsTotal()==0) && ((high>higheastprice)&&(close<open)&&(open<higheastprice)&&(signal==0)&&(signal1==0)&&(signal2==0)&&(signal3==0)&&(signal4==0)&&(signal5==0)))



{



trade.SellStop(0.10,close,_Symbol,high,lowestprice,ORDER_TIME_DAY,0,0);  

}
}
 

EA


Still opening positions after stop loss, thank you though.

 

if signal is valid, it will still open position.

 
Thanks for the reply Dua Yong Rew, it makes sense, what could i do to invalid the signal after hit the stop or take profit, do you have any idea? It cound easily have lots of losses if prices keep ranging beetween the price order and the price stop loss, could you give me a clue. Once again, thank you.
 
Guys thanks to the replies, i just found a solution by simple changing the expiration time, now it not opening more positions after stop. If anybody having the same trouble out there i think it may solve.
int CandleTime;

datetime Time[];

ArraySetAsSeries(Time,true);

CopyTime(_Symbol,PERIOD_H4,0,2,Time);

CandleTime = ArrayMaximum(Time,0,2);

MqlRates TimeInformation[];

ArraySetAsSeries (TimeInformation, true);

int data=CopyRates(Symbol(),PERIOD_H4,0,2,TimeInformation);
 
datetime candletime = TimeInformation[CandleTime].time+300;

Comment(" Expiration: ",candletime);


if((OrdersTotal()==0)&&(PositionsTotal()==0) && ((high>higheastprice)&&(close<open)&&(open<higheastprice)&&(signal==0)&&(signal1==0)&&(signal2==0)&&(signal3==0)&&(signal4==0)&&(signal5==0))) 


{

trade.SellLimit(0.10,close,_Symbol,high,lowestprice,ORDER_TIME_SPECIFIED,candletime,0);

}
}
EA Solution
Reason: