Mike,

First I want to thank you for your detailed answer and all the help you have 
given me. 

I think that I understand what you are saying but I will have to ponder it some 
more. I gather that the loop is the culprit by allowing the highs and lows to 
gather information. 

So am I correct in saying that even a simple moving average crossover would not 
have a future leak, but if I included the crossover in a loop and identified 
all the crossovers it would then be considered a leak and backtesting should be 
forbidden?

Again thank you very much for your help and I look forward to reading more of 
your informative posts.

Sorry to drag this thread out, but it was well worth it to me. :)

--- In [email protected], "Mike" <sfclimb...@...> wrote:
>
> Booker,
> 
> Sounds like the code is fine for your intended usage (i.e. dynamically 
> changing chart for reference during live trading, with the understanding that 
> the labels will jump around as new data comes in).
> 
> AmiBroker's check for future leaks is limited. It cannot possibly analyze all 
> your logic to see how values are being used.
> 
> The reason that it's a future leak, and thus cannot be backtested in its 
> current form, is that you have looked all the way to the last bar and 
> produced some statistics (i.e. number of highs, lows) based on the 
> information found in those bars.
> 
> You then proceed to use those statistics at earlier bars (i.e. starting loop 
> over again) where the computed statistics could not possibly have been known 
> had it not been for the fact that you were able to look ahead.
> 
> Bar indexes in AmiBroker start at 0. The index of each subsequent bar is 
> increased by one. A bar's index never changes. Bar 5 will always be bar 5, 
> then, now and in the future.
> 
> With that in mind, and using your example; 495 trading days ago, when the 
> current bar was then 5, you would not have been able to count forward to bar 
> 500 (it didn't exist yet). Thus, today, at bar 500, you must not use bar 500 
> info when backtesting bar 5.
> 
> Your code has a value for highs and for lows. Any reference to these values, 
> in the context of any bar before the last bar, is a future leak.
> 
> Backtesting implies entry/exit rules. So, for example, if your code had a Buy 
> rule at HH3. You would have two problems:
> 
> 1. The code would never backtest the same way twice since new bars would 
> cause changing location of HH3.
> 2. HH3 can only be determined by looking forward to see where HH1 and HH2 
> are, which can not be done in real life.
> 
> In summary; For any given bar, you must not use any values that were 
> calculated from bars that came after the given bar. To do so is to introduce 
> a future leak. Future leaks are fine for charting. They are dangerous for 
> backtesting.
> 
> Mike
> 
> --- In [email protected], "booker_1324" <booker_1324@> wrote:
> >
> > What I am trying to do is use the last 3 or 4 of the highs and lows along 
> > with BarsSince of the last low to produce a pattern for trading, and yes I 
> > need for the highs and lows to change accordingly as price and time changes.
> > 
> > I fail to see the relevance of bar 5 if today's bar is 500 to determine a 
> > future leak as I am only using the last 3 or 4 of the highs and lows for a 
> > pattern. 
> > 
> > The code that I have now does not report a future leak in Code Check so I 
> > will proceed with using Scan and Expore to aid in RT as the pattern 
> > develops.
> > 
> > I had not planned on backtesting but since you brought it up; I would like 
> > to know why using a limited number of bars to fit a pattern of highs and 
> > lows can be a future leak. I thought I knew what a future leak is but I am 
> > not so sure anymore. If this pattern showed up on bar 5, it would have to 
> > be back in time and was probably bar 500 at that time. As time progressed 
> > and it became bar 5 then I would be looking at bar 500 now and it would not 
> > be relevant to the pattern. So I would be grateful if someone would take 
> > the time to explain it to me.
> > 
> > 
> > --- In [email protected], "Mike" <sfclimbers@> wrote:
> > >
> > > "Using the value of highs" for what?
> > > 
> > > If all you want to do is chart, then go for it. The chart will look fine. 
> > > It just won't look the same! It will constantly update as new bars come 
> > > in.
> > > 
> > > If you want to use it for discretionary trading *with the understanding* 
> > > that the signals you're trading will get revised as more data comes in. 
> > > Fine.
> > > 
> > > But, if you want to run a backtest, you cannot use the values. Full stop. 
> > > No way around it.
> > > 
> > > If at any bar you find yourself making use of information based upon 
> > > later bars, then you've got a future leak and your implementation is only 
> > > good for charting. It cannot be traded, and any backtest would be 
> > > meaningless.
> > > 
> > > For example; At bar 5 you *cannot* be allowed to know that the last swing 
> > > high takes place on bar 500. So, yes, I see something wrong with using 
> > > the values after the loop.
> > > 
> > > Finally, using BarsSince is fine. Just so long as you don't reference any 
> > > of its values beyond the current bar.
> > > 
> > > Mike
> > > 
> > > --- In [email protected], "booker_1324" <booker_1324@> wrote:
> > > >
> > > > Hi Mike,
> > > > 
> > > > Using your code
> > > > 
> > > > ...
> > > > if (bigHigh[bar]) {
> > > > lookingForHigh = false; // now looking for low
> > > > PlotText("HH" + highs, bar, High[bar], colorGreen);
> > > > highs++;
> > > > }
> > > > ...
> > > > 
> > > > Do you see anything wrong with using the value of highs after the loop
> > > > as the last swing high and (highs -1) as the second to last swing high 
> > > > and
> > > > (highs -2) as the third last swing high and doing the same with lows?
> > > > 
> > > > Also, is it feasible to use BarsSince(low)?
> > > > 
> > > > --- In [email protected], "Mike" <sfclimbers@> wrote:
> > > > >
> > > > > Sure, just initialize a variable to track the number of highs then 
> > > > > use  PlotText to write out the count. Do the same for lows.
> > > > > 
> > > > > e.g. (untested)
> > > > > 
> > > > > highs = 1;
> > > > > 
> > > > >     ...
> > > > >     if (bigHigh[bar]) {
> > > > >       lookingForHigh = false; // now looking for low
> > > > >       PlotText("HH" + highs, bar, High[bar], colorGreen);
> > > > >       highs++;
> > > > >     }
> > > > >     ...
> > > > > 
> > > > > Mike
> > > > > 
> > > > > --- In [email protected], "booker_1324" <booker_1324@> wrote:
> > > > > >
> > > > > > Nice code Mike, to take this a step farther, is it posible to 
> > > > > > attach a label to each HHV and LLV such as HH1, HH2, HH3, LL1, LL2, 
> > > > > > and LL3 without referencing future quotes?
> > > > > > 
> > > > > > --- In [email protected], "Mike" <sfclimbers@> wrote:
> > > > > > >
> > > > > > > What makes you think that you are changing the step size? From 
> > > > > > > what I see, you're still advancing a single bar at a time.
> > > > > > > 
> > > > > > > bigHigh = high >Ref (hhv(high,50),-1);
> > > > > > > smallLow = low < Ref (llv(low,50),-1);
> > > > > > > lookingForHigh = true;
> > > > > > > 
> > > > > > > for (bar = 0; bar < BarCount; bar++) {
> > > > > > >   if (lookingForHigh) {
> > > > > > >     if (bigHigh[bar]) {
> > > > > > >       lookingForHigh = false; // now looking for low
> > > > > > >     }
> > > > > > >   } else {
> > > > > > >     if (smallLow[bar]) {
> > > > > > >       lookingForHigh = true;
> > > > > > >     }
> > > > > > >   }
> > > > > > > }
> > > > > > > 
> > > > > > > Mike
> > > > > > > 
> > > > > > > --- In [email protected], "Markus Witzler" <funnybiz@> 
> > > > > > > wrote:
> > > > > > > >
> > > > > > > > Hello,
> > > > > > > > 
> > > > > > > > I wonder if I can step thru a loop where the step size is being 
> > > > > > > > computed WITHIN the loop.
> > > > > > > > 
> > > > > > > > An example:
> > > > > > > > 
> > > > > > > > I want the loop to check for every bar until high >Ref 
> > > > > > > > (hhv(high,50),-1).
> > > > > > > > 
> > > > > > > > From THAT bar on, the loop should check if low < Ref 
> > > > > > > > (llv(low,50),-1) occured.
> > > > > > > > 
> > > > > > > > Say, the first condition is true on bar 50, the loop should 
> > > > > > > > afterwards start to check for the second ccondition from bar 51 
> > > > > > > > until that condition is fullfilled, say on bar 80.
> > > > > > > >  
> > > > > > > > From THAT bar on, it again should check for the first condition 
> > > > > > > > etc.
> > > > > > > > 
> > > > > > > > The thing is that I can“t tell the loop the step size in 
> > > > > > > > ADVANCE and it may differ over the whole data range, depending 
> > > > > > > > on WHEN the condition beign checked for is true.
> > > > > > > > 
> > > > > > > > Any ideas on this?
> > > > > > > > 
> > > > > > > > Thanks
> > > > > > > > 
> > > > > > > > Markus
> > > > > > > >
> > > > > > >
> > > > > >
> > > > >
> > > >
> > >
> >
>


Reply via email to