Hi everybody,
I come to you because I need a clarification. So I programmed an Expert advisor, he uses the ATR as SL. What I would like to be able to do is tell my expert advisor not to take into account the SL of the ATR if it is more than 200 pips for example.
If the ATR wants to place an SL at more than 200 pips, then our Expert Advisor will not take into account the SL of the ATR, but the one that will have defined by default, 200 pips.
This is the part of the code that interests us:
void BUY()
{
double SL=0, TP=0;
int T=0;
bool OpenBar=true;
//---
if(EnterOpenBar) if(iVolume(NULL,0,0)>1) OpenBar=false;
//---
if (OpenBar)
{
//---
if(StopLoss>0)
SL=Ask-StopLoss*point;
else
if(StopLoss<=0)
SL=Bid-ATR_Multiplicator*iATR(Symbol(),0,ATR_Level,0);
//---
if(TakeProfit>0)
TP=Ask+TakeProfit*point;
else
if(TakeProfit<=0)
TP=Bid+ATR_Multiplicator*iATR(Symbol(),0,ATR_Level,0);
{
//---
if (TotalOrders()<1
//---
&& (MarketInfo(Symbol(),MODE_ASK) > iBands(Symbol(),Band_Time_Frames,P1,P2,Band_Shift,PRICE_CLOSE,MODE_UPPER,1))
&& (iMA(Symbol(),MA_Time_Frames,P3,0,MA_MODE,MA_Applied_Price,1) > iMA(Symbol(),MA_Time_Frames,P4,0,MA_MODE,MA_Applied_Price,1)))
//---
{
if (Alert_Buy)
{
Alert(EA_Comment+" "+Symbol()+" BUY");
}
//---
T=OrderSend(Symbol(),OP_BUY,Lots_B,Ask,Slippage,SL,TP,EA_Comment,MagicNumber,0,Blue);
{
(Print(EA_Comment+" "+Symbol()+" BUY"));
}
//---
}
}
}
}
As can be seen, one has an SL that can be programmed with the number of pips we want, otherwise if the SL is at 0 in the parameters then the ATR calculates the SL.
But how do you explain to EA that you do not want to have a SL of more than 200 pips ?!
If SL of ATR > 200 pips them SL = 200 pips.
How do you code that?
If anyone could help me please. thank you.