help coding ea

 

hello,


i'm trying to code an ea that will notify me if some conditions occurs on multitimeframe.

I m using it on M15, M30 and H1, the ea work BUT as i'm attaching it to the m15 charts, when the H1 conditions occurs, it send me the same notification on every new m15 bar until a new H1 bar appear.

how can i have it working on 3 differents cycles independently, so a new bar on smaller timeframe doesn't re-check higher timeframe conditions that have already been notified ?


PS: hope you understand what i mean, english isn't my first language ;-)

 
jopopo:

hello,


i'm trying to code an ea that will notify me if some conditions occurs on multitimeframe.

I m using it on M15, M30 and H1, the ea work BUT as i'm attaching it to the m15 charts, when the H1 conditions occurs, it send me the same notification on every new m15 bar until a new H1 bar appear.

how can i have it working on 3 differents cycles independently, so a new bar on smaller timeframe doesn't re-check higher timeframe conditions that have already been notified ?


PS: hope you understand what i mean, english isn't my first language ;-)

Let me see if I understand, at xx:00 you want to notify about H1 but not M30 or M15, at xx:15 you want to notify about M15, at xx:30 you want to notify about M30 but not M15 ? you need to remember when you last notified about the different timeframes and check before you notify again on these timeframes, so maybe H1NotifyTime, M30NotifyTime, M15NotifyTime, these times would be set from the relevant bar times when the notify was sent, before you send a notification you check if the time for the bar for timeframe you are about to notify upon matches the last notification time, if it does you don't notify again, if the time is later you notify and update the time held in the variable.
 

thank for the answer, but not exactly, a M15 notification can occurs on every M15 new bar, including xx:00 or xx:30.

Maybe a sample of the code could clarify this.


And this will be attached on a M15 chart. so "Oneverynewbar" function will re-check every conditions and re-send notifications from higher timeframe that have already been signaled.

So basicaly i would need 3 "Oneverynewbar" block, one for each timeframe. But i don't know how to do that..


    void OnEveryNewBar1()
    {
    if (true == false && false) PipValue = 10;
    if (true && (NDigits == 3 || NDigits == 5)) PipValue = 10;
    if (BarTime1 < Time[0])
    {
    // we have a new bar opened
    BarTime1 = Time[0]; // keep the new bar open time

    TechnicalAnalysisvolH1();

    TechnicalAnalysisvolM30();

    TechnicalAnalysisvolM15();
    }
    }

    void TechnicalAnalysisvolH1()

    {
    if (iCustom(NULL, PERIOD_H1, "volume MA mod3",0,2) > iCustom(NULL, PERIOD_H1, "volume MA mod3",1,2))
    {
    SendNotificationH1 ();
    }
    }


    void SendNotificationH1 ()
    {
    SendNotification( Symbol() + "alert buy H1? ");
    }

    void TechnicalAnalysisvolM30()

    {
    if (iCustom(NULL, PERIOD_M30, "volume MA mod3",0,2) > iCustom(NULL, PERIOD_M30, "volume MA mod3",1,2))
    {

    SendNotificationM30 ();
    }
    }

    void SendNotificationM30 ()
    {
    SendNotification( Symbol() + "alert buy M30? ");
    }


    void TechnicalAnalysisvolM15()

    {
    if (iCustom(NULL, PERIOD_M15, "volume MA mod3",0,2) > iCustom(NULL, PERIOD_M15, "volume MA mod3",1,2))
    {

    SendNotificationM15 ();
    }
    }

    void SendNotificationM15 ()
    {
    SendNotification( Symbol() + "alert buy M15? ");
    }

    int deinit()
    {
    if (false) ObjectsDeleteAll();

    } 

 
jopopo:

thank for the answer, but not exactly, a M15 notification can occurs on every M15 new bar, including xx:00 or xx:30.

Maybe a sample of the code could clarify this.


And this will be attached on a M15 chart. so "Oneverynewbar" function will re-check every conditions and re-send notifications from higher timeframe that have already been signaled.

So basicaly i would need 3 "Oneverynewbar" block, one for each timeframe. But i don't know how to do that..

Please edit your post . . . please use the SRC button to post code: How to use the SRC button.
 
jopopo:

thank for the answer, but not exactly, a M15 notification can occurs on every M15 new bar, including xx:00 or xx:30.

Maybe a sample of the code could clarify this.


And this will be attached on a M15 chart. so "Oneverynewbar" function will re-check every conditions and re-send notifications from higher timeframe that have already been signaled.

So basicaly i would need 3 "Oneverynewbar" block, one for each timeframe. But i don't know how to do that..




Errors in your code !

Let current chart is M15, and you want to get some indicator value, from, say, M30, or even from other symbol.

You should write something like this:

   int LastError = 1;  
   while(LastError != 0)
   {
      double d_MACD_Red_ValueBar2 = iCustom(NULL, 0, es_MACD_IndicatorName, ei_FastEMA, ei_SlowEMA, ei_SignalEMA, 1, 2);
      LastError = GetLastError();
   }

See documentation : Any indicator can be calculated on the data of not only current chart, but also on the data of any available symbol/period. If data (symbol name and/or timeframe differ from the current ones) are requested from another chart, the situation is possible that the corresponding chart was not opened in the client terminal and the necessary data must be requested from the server. In this case,error ERR_HISTORY_WILL_UPDATED (4066 - the requested history data are under updating) will be placed in the last_errorvariable, and one will has to re-request ...

 

would something like that do the trick??


void TechnicalAnalysisvolH1()

{
double volH1 = iCustom(NULL, PERIOD_H1, "volume MA mod3",MA_Period, MA_Shift, MA_Method,0,2);
double volH1x1 = iCustom(NULL, PERIOD_H1, "volume MA mod3",MA_Period, MA_Shift, MA_Method,1,2);
  {
    if (volH1 > volH1x1)
    {
        TechnicalAnalysisCANDLEH1();
        SendNotificationH1 ();
    }   
  }
}
 
 if (iCustom(NULL, PERIOD_H1, "volume MA mod3",0,2) > iCustom(NULL, PERIOD_H1, "volume MA mod3",1,2))
  1. Why are you looking at two bars back?
  2. Why are you not doing it as a standard bidirectional crossover?
    double buf0Cur = iCustom(NULL, PERIOD_H1, "volume MA mod3",0,1),
           buf0Pre = iCustom(NULL, PERIOD_H1, "volume MA mod3",0,2),
           buf1Cur = iCustom(NULL, PERIOD_H1, "volume MA mod3",1,1),
           buf1Pre = iCustom(NULL, PERIOD_H1, "volume MA mod3",1,2);
    bool   wasGTR  = buf0Pre > buf1Pre,
            isGTR  = buf0Cur > buf0Pre;
    if(isGTR != wasGTR) // Crossed.
    
  3. or unidirectional crossover?
    if(isGTR && !wasGTR) // Just went above.
    

  4. Don't write things more than once. Why did you not factor the three functions into one function since the only thing changing is the TF?
  5. Don't write things more than once. You should also encapsulate the iCustom calls as one simple function. Detailed explanation of iCustom - MQL4 forum
 
WHRoeder:
  1. Why are you looking at two bars back?
  2. Why are you not doing it as a standard bidirectional crossover?
  3. or unidirectional crossover?
  4. Why did you not factor the code into a function since the only thing changing is the TF?

i'm not a programmer, just learning slowly...


1- yes 2 bars back, others conditions come @ current+1

2-3 just don't know how to do all that

4- looks interresting, same thing, don't know how to...

 
jopopo:

i'm not a programmer, just learning slowly...


4- looks interresting, same thing, don't know how to...



Hi, here is a link about using function parameters. https://book.mql4.com/basics/functions