help for debug codes

Questions about MultiCharts and user contributed studies.
valabhi
Posts: 45
Joined: 25 Jun 2007

help for debug codes

Postby valabhi » 24 Jan 2013

[attached code compiles ok but when try to plot on a chart itgives error message "trying to excess future data , bar reference -1" can some one help
code for function DSMI
{Type : Function, Name :DSMI}

input:
length1(NumericSimple),


DMILength( NumericSimple ),
length2(NumericSimple),
length3(NumericSimple);

var:
MyHH(0),DMIOsc( 0 ),MyH(o),MyL(o),MyC(o),
MyLL(0);
MyH=high[DMIOsc][-1];
MyL=low[DMIOsc][-1];
MyC=close[DMIOsc][-1];



MyHH = Highest(MyH,length1);
MyLL = Lowest (MyL,length1);
DMIOsc = _DMI_Oscillator( DMILength ) ;
DSMI = 100 * (XAverage(XAverage(MyC-(0.5*(MyHH+MyLL)),length2),length3) /
(0.5 * XAverage(XAverage(MyHH-MyLL,length2),length3)));


code for Indicator _DSMI

Input:Length1(13),Length2(25),Length3(2),AlertLevel(40),DMILength(10),


UpColor(green), DwnColor(magenta);

var:
double DMIOsc( 0 ) ;
DMIOsc = _DMI_Oscillator( DMILength ) ;

Value1 = DSMI(length1,length2,length3,DMILength);


plot1( value1, "DSMI" );
plot2( AlertLevel, "Sell line" );
plot3(-AlertLevel, "Buy line" );
plot4(0, "Zero");


if plot1 crosses above -AlertLevel then
alert("SMI crosses above buy line");

if plot1 crosses below AlertLevel then
alert("DSMI crosses below sell line");

If value1>value1[1] then begin
plot1[1](value1[1],"DSMI",upcolor);
plot1(value1,"DSMI",upcolor);
end else begin
plot1[1](value1[1],"DSMI",dwncolor);
plot1(value1,"DSMI",dwncolor);
end;

User avatar
TJ
Posts: 7739
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1032 times
Been thanked: 2221 times

Re: help for debug codes

Postby TJ » 24 Jan 2013

Please see How to Post Codes
viewtopic.php?f=16&t=11713

valabhi
Posts: 45
Joined: 25 Jun 2007

Re: help for debug codes

Postby valabhi » 24 Jan 2013

I did go thru instructions for posting codes but couldn't make it work
Sorry TJ

User avatar
TJ
Posts: 7739
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1032 times
Been thanked: 2221 times

Re: help for debug codes

Postby TJ » 24 Jan 2013

I did go thru instructions for posting codes but couldn't make it work
Sorry TJ
There are only 2 steps. Which step did not work?

User avatar
TJ
Posts: 7739
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1032 times
Been thanked: 2221 times

Re: help for debug codes

Postby TJ » 24 Jan 2013

[attached code compiles ok but when try to plot on a chart itgives error message "trying to excess future data , bar reference -1" can some one help
Try a search; paste the error message in the search box and press enter.
The search box is located at the top right corner of this page.

valabhi
Posts: 45
Joined: 25 Jun 2007

Re: help for debug codes

Postby valabhi » 25 Jan 2013

TJ -Error message appears on chart window onlower right corner with big red x this cannot be copied

User avatar
Andrew MultiCharts
Posts: 1587
Joined: 11 Oct 2011
Has thanked: 931 times
Been thanked: 559 times

Re: help for debug codes

Postby Andrew MultiCharts » 25 Jan 2013

Hello Valabhi,

You should modify your strategy. It is trying to access values from next (future) bar. You should get rid out of [-1] or change it to a positive number (reference to past data, not future).
The problem comes from this line:

Code: Select all

Value1 = DSMI(length1,length2,length3,DMILength);
Somewhere inside the DSMI function the script tries to reference data from future bars. Please debug this function and it will work.

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: help for debug codes

Postby bowlesj3 » 25 Jan 2013

These are worth a reading.

EL debugging (trouble shooting) guide
viewtopic.php?f=16&t=10397

MC/EL frequently triggered traps (how to avoid)
viewtopic.php?f=16&t=7665

Dru
Posts: 107
Joined: 28 Aug 2007
Has thanked: 4 times
Been thanked: 171 times

Re: help for debug codes

Postby Dru » 29 Jan 2013

Code: Select all

...
MyH=high[DMIOsc][-1];
MyL=low[DMIOsc][-1];
MyC=close[DMIOsc][-1];
...
end;
is equal to

Code: Select all

...
MyH=high[DMIOsc-1];
MyL=low[DMIOsc-1];
MyC=close[DMIOsc-1];
...


Return to “MultiCharts”