Simple Coding Help - No Promise.

john302928

Well-Known Member
Travi,
I need a help on this one too.
its Supertrend AFL
I modified the below code with ATR period as 7 and the factor as 3 but it looks like producing different result than that of investing.com 's suertrend with 7 and 3 values.
I have provided the chart of banknifty in 5 min chart with supertrend 7 and 3 taken fron investing.com. if you use the below code in amibroker for banknifty, it is producing different result. Could you please help

Note: unfortunately I dont have banknifty chart from amibroker. its bit complicated.actually I am checking this afl with options contracts and Investing.com and my SAS online trading terminal are producing same results for 7 and 3. so I compared my optiones contract from my trading terminal with amibroker chart. they are producing different results

//Code taken from the below link
//http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-496.html#post1227583

_SECTION_BEGIN("Super Trend");
Factor=Param("Factor",4,1,10,0.1);
Pd=Param("ATR Periods",10,1,200,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

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

TrendUp = Null;TrendDown = Null; trend=1;
if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;
}


else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}


else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}


else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}


if (trend<0 && trend[i-1]>0) {flag=1;}
else {flag=0;}
if (trend>0 && trend[i-1]<0) {flagh=1;}
else {flagh=0;}
if (trend>0 && Dn<Dn[i-1]){Dn=Dn[i-1];}
if (trend<0 && Up>Up[i-1]){ Up=Up[i-1];}
if (flag==1){ Up=(H+L)/2+(Factor*iATR);}
if (flagh==1){ Dn=(H+L)/2-(Factor*iATR);}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}


else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}


Plot(TrendUp,"TrendUp",colorGreen);
Plot(TrendDown,"TrendDown",colorRed);


_SECTION_END();
1543569472880.png
 

john302928

Well-Known Member
Chart and Debugger in Editor are different.
That is why in my first post I told you to provide as much info as you can. so in this case, you should say i'm checking syntax in Editor.

If you want proof :D goto Tools > Preferences > Debugger

You can see the base interval and number of bars are separately defined. (Limit bar count and other settings)

Use the formula in the chart.
OK. Now i pulled the afl to charting pane and it is still showing the error as below
1543570590818.png
 

john302928

Well-Known Member
I am using 1 min time frame and 5 min time frame with 15 days of data but still I am getting the same error
View attachment 31210

There maybe problems with Daily and above TF. This is working example of 15m chart. Even 5m is ok.
 

john302928

Well-Known Member
Travi,
I need a help on this one too.
its Supertrend AFL
I modified the below code with ATR period as 7 and the factor as 3 but it looks like producing different result than that of investing.com 's suertrend with 7 and 3 values.
I have provided the chart of banknifty in 5 min chart with supertrend 7 and 3 taken fron investing.com. if you use the below code in amibroker for banknifty, it is producing different result. Could you please help

Note: unfortunately I dont have banknifty chart from amibroker. its bit complicated.actually I am checking this afl with options contracts and Investing.com and my SAS online trading terminal are producing same results for 7 and 3. so I compared my optiones contract from my trading terminal with amibroker chart. they are producing different results

//Code taken from the below link
//http://www.traderji.com/amibroker/90119-simple-coding-help-no-promise-496.html#post1227583

_SECTION_BEGIN("Super Trend");
Factor=Param("Factor",4,1,10,0.1);
Pd=Param("ATR Periods",10,1,200,1);
Up=(H+L)/2+(Factor*ATR(Pd));
Dn=(H+L)/2-(Factor*ATR(Pd));
iATR=ATR(Pd);
TrendUp=TrendDown=Null;
trend[0]=1;
changeOfTrend=0;
flag=flagh=0;

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

TrendUp = Null;TrendDown = Null; trend=1;
if (Close>Up[i-1]) {
trend=1;
if (trend[i-1] == -1) changeOfTrend = 1;
}


else if (Close<Dn[i-1]) {
trend=-1;
if (trend[i-1] == 1) changeOfTrend = 1;
}


else if (trend[i-1]==1) {
trend=1;
changeOfTrend = 0;
}


else if (trend[i-1]==-1) {
trend=-1;
changeOfTrend = 0;
}


if (trend<0 && trend[i-1]>0) {flag=1;}
else {flag=0;}
if (trend>0 && trend[i-1]<0) {flagh=1;}
else {flagh=0;}
if (trend>0 && Dn<Dn[i-1]){Dn=Dn[i-1];}
if (trend<0 && Up>Up[i-1]){ Up=Up[i-1];}
if (flag==1){ Up=(H+L)/2+(Factor*iATR);}
if (flagh==1){ Dn=(H+L)/2-(Factor*iATR);}
if (trend==1) {
TrendUp=Dn;
if (changeOfTrend == 1) {
TrendUp[i-1] = TrendDown[i-1];
changeOfTrend = 0;
}
}


else if (trend==-1) {
TrendDown=Up;
if (changeOfTrend == 1) {
TrendDown[i-1] = TrendUp[i-1];
changeOfTrend = 0;
}
}
}


Plot(TrendUp,"TrendUp",colorGreen);
Plot(TrendDown,"TrendDown",colorRed);


_SECTION_END();
View attachment 31208
@travi
Please check this also. thanks a ton in advance
 

john302928

Well-Known Member
Copy-paste formula properly from source again.
There is some user related error that you are facing.
I tried 3 times doing that. And I am still getting the same error. Could you please send me the afl file that is working in your amibroker
 

john302928

Well-Known Member
Hi John, Which version of Amibroker you are using?
hi I use 5.7. travi suggested to use insert options instead of drag and drop, i tried that it is displaying but when i zoom in it was not displaying data.
Meanwhile could you please look in to the post no 5550 on supertrend issue. Its very urgent. it would be of great help. thanks
 

Similar threads