Page 154 of 180

Re: Coding Help

Posted: Sun Aug 13, 2023 4:53 am
by kvak
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

Posted: Wed Aug 16, 2023 4:28 am
by hesam-moon
kvak wrote: Sun Aug 13, 2023 4:53 am I'm trying some code, but without success for now...
Hello teacher. I had sent you a message in the private chat. Is it not possible to do that project? I really need it. It really works.

Re: Coding Help

Posted: Sun Sep 10, 2023 5:36 pm
by DaffyTaffy
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

Posted: Mon Sep 11, 2023 2:53 am
by mrtools
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.

Re: Coding Help

Posted: Mon Sep 11, 2023 6:07 pm
by DaffyTaffy
mrtools wrote: Mon Sep 11, 2023 2:53 am 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.
Thank you so much for responding. I've added that line of code and forward testing it. Hopefully it works.

Re: Coding Help

Posted: Mon Sep 11, 2023 9:48 pm
by DaffyTaffy
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!

Re: Coding Help

Posted: Sat Sep 23, 2023 1:23 am
by Tradehunter

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!

Re: Coding Help

Posted: Sat Sep 23, 2023 2:23 am
by mrtools
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");
}

Re: Coding Help

Posted: Sun Sep 24, 2023 12:37 am
by ArtūrasF
Hello,

I would like to ask maybe some can help me and add arrows or any kind of symbol to Absolute Strength Oscillator as shown in the attached photo?
Thank you very much for your time.

Re: Coding Help

Posted: Sun Sep 24, 2023 1:20 am
by kvak
ArtūrasF wrote: Sun Sep 24, 2023 12:37 am Hello,

I would like to ask maybe some can help me and add arrows or any kind of symbol to Absolute Strength Oscillator as shown in the attached photo?
Thank you very much for your time.
try...