Australian (ASX) Stock Market Forum

Bug on my indicator with Amibroker

Joined
10 October 2008
Posts
14
Reactions
0
Lol !

I have typed a kind of relative strenght .The purpose is to compare two graphs on 60 days .
(stock vs indice) .

Here is the code .I don't find the bug sorry and I am beginner with trading strategies ...

Code:
_SECTION_BEGIN("TEST");

SetBarsRequired(10000,10000); /* this ensures that the charts include all bars AND NOT just those on screen */
pt = 0; 
indicator1 =  Foreign("^FCHI","close);

i = 0; 
while (i < BarCount); 
 {
pt[i] =Close[i+60]/Close[i];
indicator1[i]= Close[i+60]/Close[i];
Plot(pt[i] , "graph0" , colorBlue);
Plot(indicator1[i] , "graph1", colorRed);
i++; 
 }
_SECTION_END();
 
Lol !

I have typed a kind of relative strenght .The purpose is to compare two graphs on 60 days .
(stock vs indice) .

Here is the code .I don't find the bug sorry and I am beginner with trading strategies ...

Code:
_SECTION_BEGIN("TEST");

SetBarsRequired(10000,10000); /* this ensures that the charts include all bars AND NOT just those on screen */
pt = 0; 
indicator1 =  Foreign("^FCHI","close);

i = 0; 
while (i < BarCount); 
 {
pt[i] =Close[i+60]/Close[i];
indicator1[i]= Close[i+60]/Close[i];
Plot(pt[i] , "graph0" , colorBlue);
Plot(indicator1[i] , "graph1", colorRed);
i++; 
 }
_SECTION_END();


Your code currently looks into the future by 60 days and you will have received an error from AB. If your intention is to look at the previous 60 days instead of the next 60 days then use

pt =Close[i-60]/Close;
indicator1= Close[i-60]/Close;
 
Even if I do

Code:
i = 0; 
while (i < BarCount); 
 {
pt[i] =Close[i-60]/Close[i];
indicator1[i]= Close[i-60]/Close[i];
Plot(pt[i] , "graph0" , colorBlue);
Plot(indicator1[i] , "graph1", colorRed);
i++; 
 }

I receive the message
Error syntax 31 , expecting ')' or ','
:confused:

NB : I will watch the code of "Relative Performance" .
The purpose is to type the code myself .Otherwise I will use a indicator that I don't understand ...
 
error #1: you have semicolon at end of while loop. actually infinite loop since you never increment i. remove the semicolon.

error #2: subscript out of range error. if i=0, then close[i-60] is -ve and array starts at 0. you need to do this

i=60;

pt = close[i-60]/close;
...
 
Nothing happened !:banghead:

Code:
_SECTION_BEGIN("TEST");

a= 0 ;
b= Foreign("^FCHI","Close");

Curve1 = 1;
Plot(Curve1,"Horizontal line",colorBlack);

for(i=60 ; i>BarCount ; i++)
{

a = Close[i]/Close[i-60];
Curve2  = b[i]/Close[i-60];

Plot(a,"current Stock",colorBlue);
Plot(Curve2,"Indice",colorRed);
}

_SECTION_END();
 
Nothing happened !:banghead:

Code:
_SECTION_BEGIN("TEST");

a= 0 ;
b= Foreign("^FCHI","Close");

Curve1 = 1;
Plot(Curve1,"Horizontal line",colorBlack);

for(i=60 ; i>BarCount ; i++)
{

a = Close[i]/Close[i-60];
Curve2  = b[i]/Close[i-60];

Plot(a,"current Stock",colorBlue);
Plot(Curve2,"Indice",colorRed);
}

_SECTION_END();

Your original attempt was closer to the mark if you had implemented the changes suggested by tcoates.

1) your For loop conditions are incorrect, i>BarCount will never be true unless your charts holds < 60 bars, therefore code within loop will only get executed for charts with less than 60 bars, and even then you'll get another subscript error as you're in another infinite loop.
2) as you are attempting to define a value for each individual element in the array, you need to use the index reference, ie a = Close/Close[i-60]; etc
3) finally take your plot statements outside of the loop. You want to plot only after the entire array has been defined and not during.

Putting this all together, you get

Code:
a= 0 ;
b= Foreign("^FCHI","Close");

Curve1 = 1;
Plot(Curve1,"Horizontal line",colorBlack);

for(i=60 ; i<BarCount-1 ; i++)
{

a[i] = Close[i]/Close[i-60];
Curve2[i]  = b[i]/Close[i-60];


}

Plot(a,"current Stock",colorBlue);
Plot(Curve2,"Indice",colorRed);
 
Great !!
Here the code that I attempted to do . 2 curves oscillating beetween the value "1"

Code:
a= 0 ;
b= Foreign("^FCHI","Close");

Curve1 = 1;
Plot(Curve1,"Horizontal line",colorBlack);

for(i=60 ; i<BarCount-1 ; i++)
{

a[i] = Close[i]/Close[i-60];
Curve2[i]  = b[i]/b[i-60];

}

Plot(a,"current Stock",colorBlue);
Plot(Curve2,"Indice",colorRed);

Many thanks for your patience .
 
Top