explain where did you do that after orderopening ??
Sorry for not explaining this very well.
int start()
{
switch (TrendSignal)
{
case1 : OpenOrders("Buy"); break; // if Trend = 1 (Buy) case2 : OpenOrders("Sell"); break; // if Trend = 2 (Sell)
}
}
void OpenOrders(string BuySell)
{
// Trade Context Handling (https://www.mql5.com/en/articles/1412)// Wait until the trade context is free and then occupy it globally (if an error occurs, leave it)if(_IsTradeAllowed() >= 0)
{ // Trading Occupied Globally, check the terminal for activityif(TradeIsBusy() < 0)
return(-1);
// Refresh the market infoRefreshRates();
// Open orders using BuySell as criterion for OrderTypeint ticket=OrderSend(Symbol(),intBuySell,LotSize(),BidAsk,3,0,0,"EA Order",Magic.Number,0,ColorCode); //Open execution cannot include TP and SL, modify after executionif(ticket<0)
{
Print("OrderSend failed with error #",GetLastError());
}else// Order was successful, Add SL and TP
{
if(ModifyOpenOrder(ticket,BuySell) < 0)
Print("OrderModify failed with error #",GetLastError());
}
// Set the trade context back to free
TradeIsNotBusy();
return(0);
}
}
int ModifyOpenOrder(int ticket,string BuySell)
{
// Function Returns 1 for success, -1 for failureOrderSelect(ticket,SELECT_BY_TICKET);
// Set SL and TP according to Buy or Sell signsif(BuySell == "Buy") { SL = OrderOpenPrice()-SL*Point; TP = OrderOpenPrice()+TP*Point; }
if(BuySell == "Sell"){ SL = OrderOpenPrice()+SL*Point; TP = OrderOpenPrice()-TP*Point; }
if(OrderModify(ticket, OrderOpenPrice(),SL,TP,0,Blue) == true)
return(1);
elsereturn(-1);
}
Assume you call the function correctly then look to above....
What is this doing ???
What is it doing the next trade ???
What is SL ???
TP same
GENIUS! Thanks a million. I understand completely now. I set SL and TP as globals via extern, then when another order is created the old SL value is re-called and is thus completely beyond the scope of price. That is why an OrderModify() would succeed and then fail later on.
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
I may be being stupid here but how about something simple like
explain where did you do that after orderopening ??
Sorry for not explaining this very well.
Assume you call the function correctly then look to above....
What is this doing ???
What is it doing the next trade ???
What is SL ???
TP same
Assume you call the function correctly then look to above....
What is this doing ???
What is it doing the next trade ???
What is SL ???
TP same
GENIUS! Thanks a million. I understand completely now. I set SL and TP as globals via extern, then when another order is created the old SL value is re-called and is thus completely beyond the scope of price. That is why an OrderModify() would succeed and then fail later on.
Thanks a million.
Happy Trading DeVries