Modify an order

 

Hy,


Could you please help me to find a solution. I am working actually on an EA and would like to introduce a request to change the SL & TP limit according to the evolution of the market. You'll find below my request detailed but it seems that there's one more problem i can't fix. Any help is welcome and thank you.



//-------------------------------------------------------------------7
for(cnt = 0; cnt < total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if(OrderType() == OP_BUY) // long position is opened
{
// check for trailing stop
if(TrailingStop > 0)
{
if(Bid - OrderOpenPrice() > Point*TrailingStop)
{
{
OrderModify(OrderTicket(), OrderOpenPrice(),
Ask - (SL*Point+ 30*Point ),
Ask + (TP*Point+ 40*Point), Green);
return(0);
}
}
}
}
else // go to short position
{
// check for trailing stop
if(TrailingStop > 0)
{
if((OrderOpenPrice() - Ask) > (Point*TrailingStop))
{
OrderModify(OrderTicket(), OrderOpenPrice(),
Bid + (SL*Point-30*Point),
Bid - (TP*Point-40*Point), 0, Red);
return(0);
}
}
}
}
}
}
//----

 

In your case:



//-------------------------------------------------------------------7 
for(cnt = 0; cnt < total; cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
{
if(OrderType() == OP_BUY) // long position is opened
{
// check for trailing stop
if(TrailingStop > 0) 
{ 
if(Bid - OrderOpenPrice() > Point*TrailingStop&&Ask - SL*Point+ 30*Point>OrderStopLoss() )
{
{
OrderModify(OrderTicket(), OrderOpenPrice(), 
Ask - (SL*Point+ 30*Point ), 
Ask + (TP*Point+ 40*Point), Green);
return(0);
}
}
}
}
else // go to short position
{
// check for trailing stop
if(TrailingStop > 0) 
{ 
if((OrderOpenPrice() - Ask) > (Point*TrailingStop)&&(OrderStopLoss()>Bid + SL*Point-30*Point||OrderStopLoss()==0))
{
OrderModify(OrderTicket(), OrderOpenPrice(), 
Bid + (SL*Point-30*Point),
Bid - (TP*Point-40*Point), 0, Red);
return(0);
}
}
}
}
}
}
//----
 
Roger:

In your case:

Thank you but itried with the given infos and it still doesn't work :-(

 
kobayashi wrote >>

Thank you but itried with the given infos and it still doesn't work :-(

for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol()&&OrderMagicNumber() == MagicN)
{

if (OrderType()==OP_BUY)
{
if (TrailingStop>0&&Bid-OrderOpenPrice() > TrailingStop*Point)
{
if (OrderStopLoss() < Bid-(TrailingStop+TrailingStep-1)*Point || OrderStopLoss() == 0)
{
OrderModify(OrderTicket(),OrderOpenPrice(), Bid-TrailingStop*Point,OrderTakeProfit(), 0, Blue);
}
}
}
if (OrderType()==OP_SELL)
{
if (TrailingStop>0&&OrderOpenPrice()-Ask > TrailingStop*Point)
{
if (OrderStopLoss() > Ask+(TrailingStop+TrailingStep-1)*Point || OrderStopLoss() == 0)
{
OrderModify(OrderTicket(), OrderOpenPrice(), Ask+TrailingStop*Point, OrderTakeProfit(), 0, Red);
}
}
}
}
}

if this doesn't work show your full code, then something else is wrong ...

 
EADeveloper:

for(int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
if(OrderSymbol()==Symbol()&&OrderMagicNumber() == MagicN)
{

if (OrderType()==OP_BUY)
{
if (TrailingStop>0&&Bid-OrderOpenPrice() > TrailingStop*Point)
{
if (OrderStopLoss() < Bid-(TrailingStop+TrailingStep-1)*Point || OrderStopLoss() == 0)
{
OrderModify(OrderTicket(),OrderOpenPrice(), Bid-TrailingStop*Point,OrderTakeProfit(), 0, Blue);
}
}
}
if (OrderType()==OP_SELL)
{
if (TrailingStop>0&&OrderOpenPrice()-Ask > TrailingStop*Point)
{
if (OrderStopLoss() > Ask+(TrailingStop+TrailingStep-1)*Point || OrderStopLoss() == 0)
{
OrderModify(OrderTicket(), OrderOpenPrice(), Ask+TrailingStop*Point, OrderTakeProfit(), 0, Red);
}
}
}
}
}

if this doesn't work show your full code, then something else is wrong ...

Thank you again for your help but i am sorry could you please explain what is trailing step ?

 
kobayashi wrote >>

Thank you again for your help but i am sorry could you please explain what is trailing step ?

extern int TrailingStop=10;
extern int TrailingStep=1;

TrailingStep is moving the stoploss for so many points how u set here

if is TrailingStep=1 then the TrailingStop is moving the Stoploss for every Point

if u set to 5 for example is moving the stoploss all 5 Points.

Give a try and you see :-)

 
EADeveloper:

extern int TrailingStop=10;
extern int TrailingStep=1;

TrailingStep is moving the stoploss for so many points how u set here

if is TrailingStep=1 then the TrailingStop is moving the Stoploss for every Point

if u set to 5 for example is moving the stoploss all 5 Points.

Give a try and you see :-)

Thanks i will try and give you the results. :-)

 

Hy it seems to work but still have a question regarding your corrections.


What do you mean by this sentence is it equivalent to "and" (if OrderStopLoss() < Bid-(TrailingStop+TrailingStep-1)*Point "and"or "then" OrderStopLoss() == 0 ) ?

if (OrderStopLoss() < Bid-(TrailingStop+TrailingStep-1)*Point || OrderStopLoss() == 0)

Reason: