create stoploss base on orderprofits.

 

Hi, i'm trying on stop-loss by referring to "OrderProfits" but it doesn't seem to work. perhaps as a newbie still need to learn more.

can any one advice if the following code had made any mistake?


----------------------------------------------------------------------------------------------------------------------------

//definition----------------

extern bool FinalStopLoss = false;
extern int stop_loss = 20;


if(OrderType() == OP_SELL)

{

if (FinalStopLoss == true) if (OrderProfit() <= -(stop_loss))
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
// Print(OrderTicket()," had close; as looses greater then $",stop_loss," ",OrderProfit());
return(0); // exit
}

}

----------------------------------------------------------------------------------------------------------------------------


regards

Leon.

 

can anyone help me regarding on how "OrderProfit()" works?

as i try to change to following; it doesn't seem to work as well.


if (NormalizeDouble(OrderProfits(),2) <= -(stop_loss))

{

//--codes--

}

 
Leonfoo:

Hi, i'm trying on stop-loss by referring to "OrderProfits" but it doesn't seem to work. perhaps as a newbie still need to learn more.

can any one advice if the following code had made any mistake?


----------------------------------------------------------------------------------------------------------------------------

//definition----------------

extern bool FinalStopLoss = false;
extern int stop_loss = 20;


if(OrderType() == OP_SELL)

{

if (FinalStopLoss == true) if (OrderProfit() <= -(stop_loss))
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet); // close position
// Print(OrderTicket()," had close; as looses greater then $",stop_loss," ",OrderProfit());
return(0); // exit
}

}

----------------------------------------------------------------------------------------------------------------------------


regards

Leon.

OrderProfits uses currency as a value and NOT pips - see this:

https://www.mql5.com/en/code/9295

Reason: