ModifyOrder Error 4051 & 4108 - page 2 12 New comment C0mput3r 2017.01.06 12:40 #11 Keith Watford: I have deleted your new topic.If you can't resolve your problems here, starting a new topic will not bring any different results.Okay Keith, I posted my code for whroeder1 but he didn't respond. Could you possibly help me? C0mput3r 2017.01.06 12:44 #12 C0mput3r: Okay Keith, I posted my code for whroeder1 but he didn't respond. Could you possibly help me?This is where I am stuck at the moment, I'm not sure why code won't move my SL to breakeven once it passes my TrailingStop mark.//************************************************************ //EXECUTE SELL CONDITION//************************************************************ { if( sell_condition_1 && sell_condition_2 && sell_condition_3 && sell_condition_4 && sell_condition_5 && sell_condition_6 && sell_condition_7) { double ShortStopLoss = Bid + (StopLoss * Point*10); double ShortTakeProfit = Bid - (TakeProfit * Point*10); //------------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------- ShortTicket = OrderSend(Symbol(),OP_SELL,LotSize,Bid,0,ShortStopLoss,ShortTakeProfit,"Sell Order",MagicNumber,0,Red); //------------------------------------------------------------------------------------------------------------------- //------------------------------------------------------------------------------------------------------------------- double ShortOpen = OrderOpenPrice(); for(int S = OrdersTotal()-1; S >= 0; S--) OrderSelect(S,SELECT_BY_POS, MODE_TRADES); { if((ShortOpen-Ask)>TrailingStop*Point*10) { int res=OrderModify(OrderTicket(),OrderOpenPrice(),(Ask+(Point*(TrailingStop)*10)),OrderTakeProfit(),0,Blue); if(!res) Print("Error in OrderModify. Error code=",GetLastError()); else Print("Order modified successfully."); } } Open another Order Code won't execute sell Modify an order Keith Watford 2017.01.06 13:27 #13 Your formatting is a total mess. What are you trying to do, make it pretty or something?IF you remove all that crap and format it sensibly if(sell_condition_1 && sell_condition_2 && sell_condition_3 && sell_condition_4 && sell_condition_5 && sell_condition_6 && sell_condition_7) { double ShortStopLoss=Bid+(StopLoss*Point*10); double ShortTakeProfit=Bid -(TakeProfit*Point*10); ShortTicket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,0,ShortStopLoss,ShortTakeProfit,"Sell Order",MagicNumber,0,Red); double ShortOpen=OrderOpenPrice(); for(int S=OrdersTotal()-1; S>=0; S--) OrderSelect(S,SELECT_BY_POS,MODE_TRADES); { if((ShortOpen-Ask)>TrailingStop*Point*10) { int res=OrderModify(OrderTicket(),OrderOpenPrice(),(Ask+(Point*(TrailingStop)*10)),OrderTakeProfit(),0,Blue); if(!res) Print("Error in OrderModify. Error code=",GetLastError()); else Print("Order modified successfully."); } }you find exactly as WHRoeder has already told you.The whole block of code is reliant on the very first if, so the break even will only be checked immediatley after the order is opened. Open another Order Please Help needed : Need help buy & William Roeder 2017.01.06 14:01 #14 C0mput3r: Okay Keith, I posted my code for whroeder1 but he didn't respond. Could you possibly help me? This isn't a service desk, people have to sleep. Asked and answered. #8/Item 5/Last line: You check your conditions, open an order, and immediately try to trail it. The trail code must not be inside condition.Had you printed your variable like I suggested, you would have know the trailing code isn't being called. Attention VPS problem OrderSelect needs a 2nd New MetaTrader 4 Platform 12 New comment
I have deleted your new topic.
If you can't resolve your problems here, starting a new topic will not bring any different results.
Okay Keith, I posted my code for whroeder1 but he didn't respond. Could you possibly help me?
//EXECUTE SELL CONDITION
//************************************************************
{
if( sell_condition_1 && sell_condition_2 && sell_condition_3 && sell_condition_4 && sell_condition_5 && sell_condition_6 && sell_condition_7)
{
double ShortStopLoss = Bid + (StopLoss * Point*10);
double ShortTakeProfit = Bid - (TakeProfit * Point*10);
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
ShortTicket = OrderSend(Symbol(),OP_SELL,LotSize,Bid,0,ShortStopLoss,ShortTakeProfit,"Sell Order",MagicNumber,0,Red);
//-------------------------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------------------------
double ShortOpen = OrderOpenPrice();
for(int S = OrdersTotal()-1; S >= 0; S--)
OrderSelect(S,SELECT_BY_POS, MODE_TRADES);
{
if((ShortOpen-Ask)>TrailingStop*Point*10)
{
int res=OrderModify(OrderTicket(),OrderOpenPrice(),(Ask+(Point*(TrailingStop)*10)),OrderTakeProfit(),0,Blue);
if(!res)
Print("Error in OrderModify. Error code=",GetLastError());
else
Print("Order modified successfully.");
}
}
Your formatting is a total mess. What are you trying to do, make it pretty or something?
IF you remove all that crap and format it sensibly
if(sell_condition_1 && sell_condition_2 && sell_condition_3 && sell_condition_4 && sell_condition_5 && sell_condition_6 && sell_condition_7)
{
double ShortStopLoss=Bid+(StopLoss*Point*10);
double ShortTakeProfit=Bid -(TakeProfit*Point*10);
ShortTicket=OrderSend(Symbol(),OP_SELL,LotSize,Bid,0,ShortStopLoss,ShortTakeProfit,"Sell Order",MagicNumber,0,Red);
double ShortOpen=OrderOpenPrice();
for(int S=OrdersTotal()-1; S>=0; S--)
OrderSelect(S,SELECT_BY_POS,MODE_TRADES);
{
if((ShortOpen-Ask)>TrailingStop*Point*10)
{
int res=OrderModify(OrderTicket(),OrderOpenPrice(),(Ask+(Point*(TrailingStop)*10)),OrderTakeProfit(),0,Blue);
if(!res)
Print("Error in OrderModify. Error code=",GetLastError());
else
Print("Order modified successfully.");
}
}
you find exactly as WHRoeder has already told you.
The whole block of code is reliant on the very first if, so the break even will only be checked immediatley after the order is opened.