Welcome to the Traders Laboratory Forums.
Coding Forum Collaborate, receive help, or discuss coding related issues.

Reply
Old 04-04-2009, 02:19 PM   #1

Join Date: Dec 2008
Location: Westport
Posts: 14
Ignore this user

Thanks: 2
Thanked 0 Times in 0 Posts

Future Data Error in TS Indicator

Below is the code for a simple indicator that tests for momentum high/low based on a moving average oscillator reading. The idea is to return a value/plot/alert if the criteria is true (i.e. the oscillator is at its highest/lowest point in 30 bars). The caveat is to disqualify points that are the highest while the momentum is still rising and vice versa, hence the test to see if it's higher/lower than the subsequent data point. I thought that I took care of the issue by first nesting the whole check withing "lastbaronchart=false " condition, however I still get "Tried to reference future data" error. Please help

inputs: shortMA(3), longMA(10);
vars: FastOsc(0), MomHigh(false), MomLow(false);

if lastbaronchart=false then begin

FastOsc=averagefc(c,short MA)-averagefc(c,longMA);


if FastOsc=highest(fastosc,3 0) and
fastosc>fastosc[-1] then begin
plot1(fastosc,"mom high");
MomHigh=true;
alert("Momentum High");
end;

if FastOsc=lowest(fastosc,30 ) and
fastosc<fastosc[-1] then begin
plot2(fastosc,"mom low");
MomLow=true;
alert("Momentum High");
end;
end;
blib is offline  
Reply With Quote
Old 04-04-2009, 02:27 PM   #2

Join Date: Nov 2006
Location: N/A
Posts: 612
Ignore this user

Thanks: 62
Thanked 294 Times in 177 Posts

Re: Future Data Error in TS Indicator

Your issue are these two lines:

fastosc>fastosc[-1] then begin

fastosc<fastosc[-1] then begin


The should be:

fastosc>fastosc[1] then begin

fastosc<fastosc[1] then begin


You cannot use negative values to reference the past bars/values. Today's value is fastosc[0], yesterday's is fastosc[1], two days ago is fastosc[2], etc. Tomorrow's bar theoretically would be fastosc[-1] and that is why you get the error.
sevensa is offline  
Reply With Quote
Old 04-04-2009, 03:47 PM   #3

Join Date: Dec 2008
Location: Westport
Posts: 14
Ignore this user

Thanks: 2
Thanked 0 Times in 0 Posts

Re: Future Data Error in TS Indicator

Sevensa,
The idea behind using [-1] is to prevent the indicator from giving a false true signal if the full momentum high or low has not yet been put in. In other words, I need to check the subsequent bar to see if it's higher/lower and give signal ONLY if it isn't. Any idea on how to accomplish that?
blib is offline  
Reply With Quote
Old 04-04-2009, 03:56 PM   #4

Tams's Avatar

Join Date: Sep 2008
Location: Geelong
Posts: 3,779
Ignore this user

Thanks: 2,084
Thanked 1,474 Times in 912 Posts

Re: Future Data Error in TS Indicator

search for "zigzag"
I have posted the code here on TL.
you can see how it is done.
Tams is offline  
Reply With Quote
Old 04-04-2009, 04:01 PM   #5

Join Date: Dec 2008
Location: Westport
Posts: 14
Ignore this user

Thanks: 2
Thanked 0 Times in 0 Posts

Re: Future Data Error in TS Indicator

I don't see any code under zigzag posted you you - if you have it, do you mind reposting it or post the URL - thanks
blib is offline  
Reply With Quote
Old 04-04-2009, 04:45 PM   #6

Join Date: Nov 2006
Location: N/A
Posts: 612
Ignore this user

Thanks: 62
Thanked 294 Times in 177 Posts

Re: Future Data Error in TS Indicator

Quote:
Originally Posted by blib »
Sevensa,
The idea behind using [-1] is to prevent the indicator from giving a false true signal if the full momentum high or low has not yet been put in. In other words, I need to check the subsequent bar to see if it's higher/lower and give signal ONLY if it isn't. Any idea on how to accomplish that?
Nope, sorry. Looking into the future is not something I have figured out how to do yet.
sevensa is offline  
Reply With Quote
Old 04-05-2009, 04:09 PM   #7

BlowFish's Avatar

Join Date: Mar 2007
Location: In Da House
Posts: 3,292
Ignore this user

Thanks: 129
Thanked 1,054 Times in 702 Posts

Re: Future Data Error in TS Indicator

Quote:
Originally Posted by blib »
Sevensa,
The idea behind using [-1] is to prevent the indicator from giving a false true signal if the full momentum high or low has not yet been put in. In other words, I need to check the subsequent bar to see if it's higher/lower and give signal ONLY if it isn't. Any idea on how to accomplish that?
You need to shift all your logic backwards by 1 bar. So [-1] becomes [0] --- [0] becomes [1] etc. You will need to shift the plot backwards too.
BlowFish is offline  
Reply With Quote

Reply

Thread Tools
Display Modes Help Others By Rating This Thread
Help Others By Rating This Thread:


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pair Trading (future Vs Future at CME/Eurex) Accumulator Futures Trading Laboratory 0 03-11-2009 02:52 PM
Url.dll Error - Help! brownsfan019 Tools of the Trade 5 09-16-2008 05:50 PM
Indicator with Data of Another Indicator Tresor Coding Forum 13 08-06-2008 10:48 AM
Error trying to check email address brownsfan019 Support Center 6 05-29-2007 10:41 AM

All times are GMT -4. The time now is 12:43 PM.
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
CS to VB integration by DeskLancer
©2006-2011 Traders Laboratory, All Rights Reserved.