Hi folks,
I am a newbie need help for my code. I copied all the stuff from here and there. Till now everything is working as expected.
Trail & Breakeven both working individually. But if I activate them with "if else" both start working , SL moves to BE then TS and viceversa rapidly.
Any help will be appriciated.
Trailing code I took from below thread.
https://www.forexfactory.com/thread/...code-for-an-ea
if (OrderStopLoss() == OrderOpenPrice())
{
if(trail) trail(); //Trailing Stop Start
}
else //Break Even
{
int digits = MarketInfo(Symbol(),MODE_DIGITS);
double value = OrderOpenPrice();
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderSymbol()!=Symbol())
continue;
RefreshRates();
if(OrderType()==OP_BUY)
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),OrderExpiration());
if(OrderType()==OP_SELL)
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),OrderExpiration());
}
}
--------------------------------------------------------------------------------------------
Also is it possible to reduce the below code? It check single buy & Sell open orders on current chart.
bool CheckBuyOrder()
{
for( int i = 0 ; i < OrdersTotal() ; i++ )
{
OrderSelect( i, SELECT_BY_POS, MODE_TRADES );
if (OrderSymbol() == Symbol() && OrderType() == OP_BUY)
{
if (max >= OrdersTotal()) return(true);
}
}
return(false);
}
bool CheckSellOrder()
{
for( int i = 0 ; i < OrdersTotal() ; i++ )
{
OrderSelect( i, SELECT_BY_POS, MODE_TRADES );
if (OrderSymbol() == Symbol() && OrderType() == OP_SELL && max >= OrdersTotal()) return(true);
{
if (max >= OrdersTotal()) return(true);
}
}
return(false);
}
I am a newbie need help for my code. I copied all the stuff from here and there. Till now everything is working as expected.
Trail & Breakeven both working individually. But if I activate them with "if else" both start working , SL moves to BE then TS and viceversa rapidly.
Any help will be appriciated.
Trailing code I took from below thread.
https://www.forexfactory.com/thread/...code-for-an-ea
if (OrderStopLoss() == OrderOpenPrice())
{
if(trail) trail(); //Trailing Stop Start
}
else //Break Even
{
int digits = MarketInfo(Symbol(),MODE_DIGITS);
double value = OrderOpenPrice();
for(int i=OrdersTotal()-1;i>=0;i--)
{
if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
continue;
if(OrderSymbol()!=Symbol())
continue;
RefreshRates();
if(OrderType()==OP_BUY)
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),OrderExpiration());
if(OrderType()==OP_SELL)
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice(),OrderTakeProfit(),OrderExpiration());
}
}
--------------------------------------------------------------------------------------------
Also is it possible to reduce the below code? It check single buy & Sell open orders on current chart.
bool CheckBuyOrder()
{
for( int i = 0 ; i < OrdersTotal() ; i++ )
{
OrderSelect( i, SELECT_BY_POS, MODE_TRADES );
if (OrderSymbol() == Symbol() && OrderType() == OP_BUY)
{
if (max >= OrdersTotal()) return(true);
}
}
return(false);
}
bool CheckSellOrder()
{
for( int i = 0 ; i < OrdersTotal() ; i++ )
{
OrderSelect( i, SELECT_BY_POS, MODE_TRADES );
if (OrderSymbol() == Symbol() && OrderType() == OP_SELL && max >= OrdersTotal()) return(true);
{
if (max >= OrdersTotal()) return(true);
}
}
return(false);
}