Confirm on next Timeframe - page 2

 
Petr Nosek:

I think your problem is in the highlighted line:

Maybe there should be something like that:

I hope it helps.

You're awesome! Thank you!


Last question:

I forgot to add this one on my previous post... (sorry)

void CatchBearishDivergence(int shift)
{
    if(IsIndicatorPeak(shift) == false)
        return;

    int currentPeak = shift;
    int lastPeak = GetIndicatorLastPeak(shift);
    int shiftNextTimeFrame=iBarShift(_Symbol,NextTimeFrame(),iTime(_Symbol,_Period,shift));

    if(rsi[currentPeak] < rsi[lastPeak]
    && High[currentPeak] > High[lastPeak]
    && MarketInfo(Symbol(), MODE_BID) >= iBands(NULL, 0, 34, 2.5, 0, PRICE_CLOSE, 1, currentPeak)
    && iClose(_Symbol,NextTimeFrame(),shiftNextTimeFrame) >= iBands(NULL, NextTimeFrame(), 34, 2, 0, PRICE_CLOSE, 1, shiftNextTimeFrame))
    {
        bearishDivergence[currentPeak] = rsi[currentPeak] + arrowsDisplacement;
        divergencesRSIDiff[currentPeak] = MathAbs(rsi[currentPeak] - rsi[lastPeak]);
        divergencesPriceDiff[currentPeak] = MathAbs(High[currentPeak] - High[lastPeak]);
    }
}


I was using Close() before for this one, but I would like to receive the signal as soon as the bar touches the upper 2.5 BB.
For some reason though it is giving me signals that are not above 2.5 BB as per the condition...
I have been playing around with the shifts but no success there...
 
Any help please? 
 
Darkz0r:
 

I was using Close() before for this one, but I would like to receive the signal as soon as the bar touches the upper 2.5 BB.
For some reason though it is giving me signals that are not above 2.5 BB as per the condition...
I have been playing around with the shifts but no success there...

I'm sorry but you posted only a small piece of code. I can only guess what's wrong.

Maybe the else condition should be there:

    if(rsi[currentPeak] < rsi[lastPeak]
    && High[currentPeak] > High[lastPeak]
    && MarketInfo(Symbol(), MODE_BID) >= iBands(NULL, 0, 34, 2.5, 0, PRICE_CLOSE, 1, currentPeak)
    && iClose(_Symbol,NextTimeFrame(),shiftNextTimeFrame) >= iBands(NULL, NextTimeFrame(), 34, 2, 0, PRICE_CLOSE, 1, shiftNextTimeFrame))
    {
        bearishDivergence[currentPeak] = rsi[currentPeak] + arrowsDisplacement;
        divergencesRSIDiff[currentPeak] = MathAbs(rsi[currentPeak] - rsi[lastPeak]);
        divergencesPriceDiff[currentPeak] = MathAbs(High[currentPeak] - High[lastPeak]);
    }
    else
    {
        bearishDivergence[currentPeak] = 0.0;
        divergencesRSIDiff[currentPeak] = 0.0;
        divergencesPriceDiff[currentPeak] = 0.0;
    }
 

It's the same code from before:

int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
    if (!ValidateParameters())
        return(0);

    int bars = rates_total;
    if(prev_calculated > 0)
    {
        bars = rates_total - prev_calculated;
    }

    CalculateIndicator(bars, rates_total);

    return(rates_total);
}

void CalculateIndicator(int bars, int rates_total)
{
    int outOfRangeBuffer = 5;
    int maxBarBack;

    if (bars < rates_total - outOfRangeBuffer)
        maxBarBack = bars;
    else
        maxBarBack = bars - (outOfRangeBuffer - (rates_total - bars));

    for(int i = maxBarBack; i >= 0; i--)
    {
        CalculateRSI(i);
        CatchBearishDivergence(i + 1);
    }
}



void CalculateRSI(int i)
{
    rsi[i] = iRSI(NULL, 0, period, PRICE_CLOSE, i);             
}

void CatchBearishDivergence(int shift)
{
    if(IsIndicatorPeak(shift) == false)
        return;

    int currentPeak = shift;
    int lastPeak = GetIndicatorLastPeak(shift);
    int shiftNextTimeFrame=iBarShift(_Symbol,NextTimeFrame(),iTime(_Symbol,_Period,shift));

    if(rsi[currentPeak] < rsi[lastPeak]
    && High[currentPeak] > High[lastPeak]
    && MarketInfo(Symbol(), MODE_BID) >= iBands(NULL, 0, 34, 2.5, 0, PRICE_CLOSE, 1, currentPeak)
    && iClose(_Symbol,NextTimeFrame(),shiftNextTimeFrame) >= iBands(NULL, NextTimeFrame(), 34, 2, 0, PRICE_CLOSE, 1, shiftNextTimeFrame))
    {
        bearishDivergence[currentPeak] = rsi[currentPeak] + arrowsDisplacement;
        divergencesRSIDiff[currentPeak] = MathAbs(rsi[currentPeak] - rsi[lastPeak]);
        divergencesPriceDiff[currentPeak] = MathAbs(High[currentPeak] - High[lastPeak]);
    }
}

int NextTimeFrame()
{
    int TimeFrames[10] = { 1,5,15,30,60,240,1440,10080,43200,43200 };

    for(int i = 0; i < 9; i++)
        if(TimeFrames[i] == Period()) return(TimeFrames[i+1]);

    return(false);
}



It is not the else condition. As a matter of fact, if I use the else condition I will get my chart full of arrows at the bottom.


The indicator should send the signal as soon as the current bar touches the the BB 2.5, but instead it is giving signals below this Bollinger Band. I'm just not sure why...

Wrong Signal

 
Darkz0r:

It's the same code from before:
It is not the else condition. As a matter of fact, if I use the else condition I will get my chart full of arrows at the bottom.

  1. I can't help you without having the whole code. For example: I don't know what variables are Buffers, I can't see your function GetIndicatorLastPeak() and so on.
  2. If you want to avoid arrows at the bottom you should use SetIndexEmptyValue().
  3. I think you get to trouble calling CatchBearishDivergence(i + 1). The better way is calling CatchBearishDivergence(i) but you have to edit its code.
  4. I think your condition && MarketInfo(Symbol(), MODE_BID) >= iBands(NULL, 0, 34, 2.5, 0, PRICE_CLOSE, 1, currentPeak) is wrong because you compare current price with iBands(...,currentPeak), but currentPeak is always greater than zero. You compare current price with historical BB.
  5. It seems you are trying to add your code into a foreign code and you don't understand it much. Maybe it will be easier if you give the original code to someone with more experience and tell him what you want to add.


Reason: