Can someone take a look at this and see if there is something amiss...
I am testing exits if price exceeds the highest High or the lowest Low for the last x number of bars.
My ea routine is correctly exiting short positions as programmed but is exiting longs on the next bar regardless of price.
Both exit algorithms are mirror codes of each other, and I am completely baffled here...
Again my SHORT EXITS are working properly, but my LONG EXITS are exiting too soon and there are no stops or trailing stops here...Here is the code (most of this was developed by user Cch who has been very very helpful).
*****
for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderMagicNumber() == MagicNumber)
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
if (Close[0] < iLowest(NULL,0,MODE_LOW,5,1)) Order = LONG_EXIT;
if (Order == LONG_EXIT && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
if(UseTS && TS > 0) {
if(Bid - OrderOpenPrice() > Point * TS) {
if(OrderStopLoss() < Bid - Point * TS) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TS, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
}
else
{
if (Close[0] > iHighest(NULL,0,MODE_HIGH,5,1)) Order = SHORT_EXIT;
if (Order == SHORT_EXIT && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
if (UseTS && TS > 0) {
if((OrderOpenPrice() - Ask) > (Point * TS)) {
if((OrderStopLoss() > (Ask + Point * TS)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TS, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
}
}
}
****
END OF EXIT ROUTINE
I am testing exits if price exceeds the highest High or the lowest Low for the last x number of bars.
My ea routine is correctly exiting short positions as programmed but is exiting longs on the next bar regardless of price.
Both exit algorithms are mirror codes of each other, and I am completely baffled here...
Again my SHORT EXITS are working properly, but my LONG EXITS are exiting too soon and there are no stops or trailing stops here...Here is the code (most of this was developed by user Cch who has been very very helpful).
*****
for (int i = 0; i < Total; i ++) {
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if (OrderMagicNumber() == MagicNumber)
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
IsTrade = True;
if(OrderType() == OP_BUY) {
if (Close[0] < iLowest(NULL,0,MODE_LOW,5,1)) Order = LONG_EXIT;
if (Order == LONG_EXIT && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
if(UseTS && TS > 0) {
if(Bid - OrderOpenPrice() > Point * TS) {
if(OrderStopLoss() < Bid - Point * TS) {
OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TS, OrderTakeProfit(), 0, MediumSeaGreen);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
}
else
{
if (Close[0] > iHighest(NULL,0,MODE_HIGH,5,1)) Order = SHORT_EXIT;
if (Order == SHORT_EXIT && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
if (!EachTickMode) BarCount = Bars;
IsTrade = False;
continue;
}
if (UseTS && TS > 0) {
if((OrderOpenPrice() - Ask) > (Point * TS)) {
if((OrderStopLoss() > (Ask + Point * TS)) || (OrderStopLoss() == 0)) {
OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TS, OrderTakeProfit(), 0, DarkOrange);
if (!EachTickMode) BarCount = Bars;
continue;
}
}
}
}
}
}
****
END OF EXIT ROUTINE