indior to signal on the current bar only
Results 1 to 5 of 35

Thread: indior to signal on the current bar only

  1. #1
    Hi,
    I have a moving averages cross indior that produces an alert each time that the moving averages cross.

    That I would enjoy the indior to create an alert only when a cross has just occurred (i.e. on the current bar). However, with this indior, each time I open up MT4 or switch between timeframes I'm getting alerts even though the cross has occurred 2-3 bars ago.

    Here's a copy of the code under. Many thanks.


    #property indior_chart_window
    #property indior_buffers 2
    #property indior_color1 DarkGoldenrod
    #property indior_color2 FireBrick
    double CrossUp[];
    double CrossDown[];
    extern int FasterEMA = 1;
    extern int SlowerEMA = 50;
    extern bool SoundON=true;
    double alertTag;
    double control=2147483647;

    // ------------------------------------------------------------------
    //| Custom indior initialization function |
    // ------------------------------------------------------------------
    int init()

    //-- indiors
    SetIndexStyle(0, DRAW_ARROW, EMPTY,1);
    SetIndexArrow(0, 233);
    SetIndexBuffer(0, CrossUp);
    SetIndexStyle(1, DRAW_ARROW, EMPTY,1);
    SetIndexArrow(1, 234);
    SetIndexBuffer(1, CrossDown);
    //--
    return(0);

    // ------------------------------------------------------------------
    //| Custom indior deinitialization function |
    // ------------------------------------------------------------------
    int deinit()

    //--
    //--
    return(0);

    // ------------------------------------------------------------------
    //| Custom indior iteration function |
    // ------------------------------------------------------------------
    int start()
    int limit, i, counter;
    double fasterEMAnow, slowerEMAnow, fasterEMAprevious, slowerEMAprevious, fasterEMAafter, slowerEMAafter;
    double Range, AvgRange;
    int counted_bars=IndiorCounted();
    //-- check for possible errors
    if(counted_barslt;0) return(-1);
    //-- last counted bar will be recounted
    if(counted_barsgt;0) counted_bars--;
    limit=Bars-counted_bars;

    for(i = 0; i lt;= limit; i )

    counter=i;
    Range=0;
    AvgRange=0;
    for (counter=i ;counterlt;=i 9;counter )

    AvgRange=AvgRange MathAbs(High[counter]-Low[counter]);

    Range=AvgRange/10;

    fasterEMAnow = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i);
    fasterEMAprevious = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i 1);
    fasterEMAafter = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);
    slowerEMAnow = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i);
    slowerEMAprevious = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i 1);
    slowerEMAafter = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);

    if ((fasterEMAnow gt; slowerEMAnow) (fasterEMAprevious lt; slowerEMAprevious) (fasterEMAafter gt; slowerEMAafter))
    CrossUp[i] = Low[i] - Range*0.5;

    else if ((fasterEMAnow lt; slowerEMAnow) (fasterEMAprevious gt; slowerEMAprevious) (fasterEMAafter lt; slowerEMAafter))
    CrossDown[i] = High[i] Range*0.5;

    if (SoundON==true i==1 CrossUp[i] gt; CrossDown[i] alertTag! =Time[0])
    Alert(MACD 0 cross DOWN on ,Symbol(), ,Period());
    alertTag = Time[0];
    SendNotifiion(MACD 0 cross DOWN on _Symbol);

    if (SoundON==accurate I==1 CrossUp[I] lt; CrossDown[I] alertTag! =Time[0])
    Alert(MACD 0 cross UP on ,Symbol(), ,Period());
    alertTag = Time[0];
    SendNotifiion(MACD 0 cross UP on _Symbol);




    return(0);

  2. #2
    #property indior_chart_window
    #property indior_buffers 2
    #property indior_color1 DarkGoldenrod
    #property indior_color2 FireBrick
    double CrossUp[];
    double CrossDown[];
    extern int FasterEMA = 1;
    extern int SlowerEMA = 50;
    extern bool SoundON=true;
    double alertTag;
    double control=2147483647;
    // ------------------------------------------------------------------
    //| Custom indior initialization function |
    // ------------------------------------------------------------------
    int init()

    //-- indiors
    SetIndexStyle(0, DRAW_ARROW, EMPTY,1);
    SetIndexArrow(0, 233);
    SetIndexBuffer(0, CrossUp);
    SetIndexStyle(1, DRAW_ARROW, EMPTY,1);
    SetIndexArrow(1, 234);
    SetIndexBuffer(1, CrossDown);
    //--
    return(0);

    // ------------------------------------------------------------------
    //| Custom indior deinitialization function |
    // ------------------------------------------------------------------
    int deinit()

    //--
    //--
    return(0);

    // ------------------------------------------------------------------
    //| Custom indior iteration function |
    // ------------------------------------------------------------------
    int start()
    int limit, I, counter;
    double fasterEMAnow, slowerEMAnow, fasterEMAprevious, slowerEMAprevious, fasterEMAafter, slowerEMAafter;
    double Range, AvgRange;
    int counted_bars=IndiorCounted();
    //-- check for possible errors
    if(counted_barslt;0) return(-1);
    //-- last counted bar is going to be recounted
    if(counted_barsgt;0) counted_bars--;
    limit=Bars-counted_bars;
    for(I = 0; I lt;= limit; I )
    counter=I;
    Range=0;
    AvgRange=0;
    for (counter=I ;counterlt;=I 9;counter )

    AvgRange=AvgRange MathAbs(High[counter]-Low[counter]);

    Range=AvgRange/10;
    fasterEMAnow = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, I);
    fasterEMAprevious = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, I 1);
    fasterEMAafter = iMA(NULL, 0, FasterEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);
    slowerEMAnow = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, I);
    slowerEMAprevious = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, I 1);
    slowerEMAafter = iMA(NULL, 0, SlowerEMA, 0, MODE_EMA, PRICE_CLOSE, i-1);
    if ((fasterEMAnow gt; slowerEMAnow) (fasterEMAprevious lt; slowerEMAprevious) (fasterEMAafter gt; slowerEMAafter))
    CrossUp[I] = Low[I] - Range*0.5;

    else if ((fasterEMAnow lt; slowerEMAnow) (fasterEMAprevious gt; slowerEMAprevious) (fasterEMAafter lt; slowerEMAafter))
    CrossDown[I] = High[I] Range*0.5;

    if (SoundON==true I==1 CrossUp[0] gt; CrossDown[0] alertTag! =Timing[0])
    Alert(MACD 0 cross DOWN on ,Symbol(), Stage());
    alertTag = Timing[0];
    SendNotifiion(MACD 0 cross DOWN on _Symbol);

    if (SoundON==accurate I==1 CrossUp[0] lt; CrossDown[0] alertTag! =Timing[0])
    Alert(MACD 0 cross UP on ,Symbol(), Stage());
    alertTag = Timing[0];
    SendNotifiion(MACD 0 cross UP on _Symbol);



    return(0);

  3. #3

  4. #4
    Is it cross over associated

  5. #5
    Quote Originally Posted by ;
    can it be macd cross related
    For the indior you can place any two moving averages. 12 and 26 cross signifies a 0 line cross on the MACD.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.