I wrote a function for a trailing stoploss and the logid seems air tight. however while testing, the stoploss is stuck an interval away from the current price no matter which way it moves. what could be the problem?
heres the code (MQL5)
Help would be much appreciated..
void SLmodify()
{
// if(PositionGetInteger(POSITION_MAGIC) == 444444)//adding magic number, if you want you can delete this if you don't want to use magic number// {for(int i=PositionsTotal()-1; i>=0; i--)
{
ulong PositionTicket = PositionGetTicket(i);
long trade_type = PositionGetInteger(POSITION_TYPE);
if (trade_type == 0)
{
double ask = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);
if (ask - meanEntryPriceBuy() > (2*Grid*_Point))
{
trade.PositionModify(PositionTicket,NormalizeDouble(ask - Grid*_Point,_Digits),PositionGetDouble(POSITION_TP));
}
if (PositionGetDouble(POSITION_SL) < NormalizeDouble(ask - Grid*_Point, _Digits))
{
trade.PositionModify(PositionTicket,NormalizeDouble(ask - Grid*_Point,_Digits),PositionGetDouble(POSITION_TP));
}
}
if (trade_type == 1)
{
double bid = NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);
if ( meanEntryPriceSell() - bid > (2*Grid*_Point))
{
trade.PositionModify(PositionTicket,NormalizeDouble(bid + Grid*_Point, _Digits) ,PositionGetDouble(POSITION_TP));
}
if (PositionGetDouble(POSITION_SL) > NormalizeDouble(bid + Grid*_Point, _Digits))
{
trade.PositionModify(PositionTicket,NormalizeDouble(bid + Grid*_Point, _Digits) ,PositionGetDouble(POSITION_TP));
}
}
}
}
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 wrote a function for a trailing stoploss and the logid seems air tight. however while testing, the stoploss is stuck an interval away from the current price no matter which way it moves. what could be the problem?
heres the code (MQL5)
Help would be much appreciated..