Re: Coding Help

1531
alpha24 wrote: Sat Aug 12, 2023 9:29 pm Dear Ogee,
Same problem with your given indicator. I am comfortable with Tick Volume Indicator I just want that color change if current bar is greater than previous bar should show green and vice versa. If our Masters make this code as I wish will be great.
I'm trying some code, but without success for now...


Re: Coding Help

1533
Hi everyone. Please, I have an mt5 EA I am coding but for some reason the trailing stop function just isn't working. The trailing stop functions is below. I have no errors or warnings in my code. Is the function correct or am I just not calling the function in the appropriate place? Any help would be much appreciated.
Full EA code attached below.

Code: Select all

void ApplyTrailingStop()
{
    if(!PositionSelect(Symbol())) return; // If no position for this symbol, exit the function
    
    double openPrice = PositionGetDouble(POSITION_PRICE_OPEN);
    double currentPrice = SymbolInfoDouble(Symbol(), (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) ? SYMBOL_BID : SYMBOL_ASK);

    double trailingStopInPoints = 10; // 15 pips = 150 points
    double distanceToTrail = trailingStopInPoints * SymbolInfoDouble(Symbol(), SYMBOL_POINT);

    double currentStopLoss = PositionGetDouble(POSITION_SL);
    double newStopLoss = 0;

    if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
    {
        newStopLoss = currentPrice - distanceToTrail;
        if(currentStopLoss < newStopLoss || currentStopLoss == 0)
        {
            trade.PositionModify(Symbol(), newStopLoss, PositionGetDouble(POSITION_TP));
        }
    }
    else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
    {
        newStopLoss = currentPrice + distanceToTrail;
        if(currentStopLoss > newStopLoss || currentStopLoss == 0)
        {
            trade.PositionModify(Symbol(), newStopLoss, PositionGetDouble(POSITION_TP));
        }
    }
}

Re: Coding Help

1534
DaffyTaffy wrote: Sun Sep 10, 2023 5:36 pm Hi everyone. Please, I have an mt5 EA I am coding but for some reason the trailing stop function just isn't working. The trailing stop functions is below. I have no errors or warnings in my code. Is the function correct or am I just not calling the function in the appropriate place? Any help would be much appreciated.
Full EA code attached below.

Code: Select all

void ApplyTrailingStop()
{
    if(!PositionSelect(Symbol())) return; // If no position for this symbol, exit the function
    
    double openPrice = PositionGetDouble(POSITION_PRICE_OPEN);
    double currentPrice = SymbolInfoDouble(Symbol(), (PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) ? SYMBOL_BID : SYMBOL_ASK);

    double trailingStopInPoints = 10; // 15 pips = 150 points
    double distanceToTrail = trailingStopInPoints * SymbolInfoDouble(Symbol(), SYMBOL_POINT);

    double currentStopLoss = PositionGetDouble(POSITION_SL);
    double newStopLoss = 0;

    if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY)
    {
        newStopLoss = currentPrice - distanceToTrail;
        if(currentStopLoss < newStopLoss || currentStopLoss == 0)
        {
            trade.PositionModify(Symbol(), newStopLoss, PositionGetDouble(POSITION_TP));
        }
    }
    else if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL)
    {
        newStopLoss = currentPrice + distanceToTrail;
        if(currentStopLoss > newStopLoss || currentStopLoss == 0)
        {
            trade.PositionModify(Symbol(), newStopLoss, PositionGetDouble(POSITION_TP));
        }
    }
}
Not very familiar with mt5 EA's so just guessing here, maybe try

Code: Select all

if (trailingStopLossPercent>0) ApplyTrailingStop();
Hope this helps, but not really for sure.
These users thanked the author mrtools for the post:
DaffyTaffy


CodeRe: Coding Help

1536
mrtools wrote: Mon Sep 11, 2023 2:53 am

Code: Select all

if (trailingStopLossPercent>0) ApplyTrailingStop();
Hi Mr.Tools. It worked. The issue came from where I called the function. I placed it right after the buy and sell conditions, then I added conditions to check if the trade was in a certain amount of profit. And that seemed to do the trick.
Thank you!
These users thanked the author DaffyTaffy for the post (total 2):
Jimmy, mrtools

Re: Coding Help

1538
Tradehunter wrote: Sat Sep 23, 2023 1:23 am

Code: Select all

void go_alerts(string msg)
{
   Alert(msg);
   SendNotification("msg");
}
Im trying to add push notifications to this, it works.
But I would like to send the symbol and time.
Thanks!
Maybe something like

Code: Select all

void go_alerts(string msg)
{
   msg = timeFrameToString(_Period)+" "+_Symbol+" at "+TimeToString(TimeLocal(),TIME_SECONDS)+" indicator name "+doWhat;
   Alert(msg);
   SendNotification("msg");
}
These users thanked the author mrtools for the post:
Tradehunter


Who is online

Users browsing this forum: No registered users and 2 guests