referencing the previous high or previous low

 

Hello forum, hoping someone might steer me in the right direction with this query.

I have attached a very simple diagram where I show three candles, A, B and C and a previous low marked with an arrow.

I am looking for a way to filter entries based on previous lows (or highs for long trades) that does not involve me specifying the number of bars to look back.

In the diagram the previous low occurs 7 bars before candle A, but could occur 107 candles earlier.

I am trying to come up with an entry filter that other factors aside, would not allow entry at candles A and B but would at C because it takes out the previous low marked with the arrow

I have been looking at fractals and must confess am a bit confused by them and the coding.

I have 2 questions:

1. What is the simplest way of referencing a previous high or low? (is it fractals?), and

2. if the method uses a fractal approach, is it possible to specify just the previous fractal as opposed to all fractals of a certain pattern size.

I am happy to try and work out he code if someone would guide me as to a good place to start (maybe there is a simple approach I am not aware of....yet!)

thanks

Dave


 
pullend:

I am looking for a way to filter entries based on previous lows (or highs for long trades) that does not involve me specifying the number of bars to look back.

In the diagram the previous low occurs 7 bars before candle A, but could occur 107 candles earlier.

This will NOT work. No look back - all you can get is the all time low. You want the most recent low within a range. You could use fractals.

I use this:

//+------------------------------------------------------------------+
//| Find local extrema                                               |
//+------------------------------------------------------------------+
double  LEPrice(int length, int iBeg, double d=EMPTY_VALUE, int ePrice=EMPTY){
    double prcLE    = FindMax(length, iBeg, d, ePrice, true);   return(prcLE);
}
double  FindMax (int length, int& iMax, double d, int ePrice, bool LE){
//double DIR                                            // Import from SetDIR
//#define INF 0x6FFFFFFF // Not quite infinite, Jul 2029, or 1,879,048,191
    if (d == EMPTY_VALUE)   d       = DIR;
    if (ePrice == EMPTY)    ePrice  = IfI(PRICE_HIGH, PRICE_LOW, d);
    double  prcMax  = -d * INF;
    int     nBars   = GetBars(),
            iLimit  = MathMinI(nBars, iMax + length);
    for (int iBar = iMax; iBar < iLimit; iBar++){
        double value = GetPrice(iBar, ePrice);
        if ((prcMax - value)*d < 0.){
            prcMax = value; iMax = iBar;
            if (LE) iLimit  = MathMinI(nBars, iMax+length);
    }   }
    return(prcMax);
}

With a length of 6 it would find point A for candles between A and the Doji

With a length of 9 it would find point B for candles between A and point C

 
WHRoeder:

This will NOT work. No look back - all you can get is the all time low. You want the most recent low within a range. You could use fractals.

I use this:

With a length of 6 it would find point A for candles between A and the Doji

With a length of 9 it would find point B for candles between A and point C


Thank you I will explore with interest and report back
Reason: