Hello Guys,
I found a pretty good trading stategy, but I am not familiar with AFL writing. I use an AFL created by Dimitris Tsokakis, called Slow Stochastic and Trendlines. I paste the code here:
_SECTION_BEGIN("sto");
/*Slow Stochastic and Trendlines
for Indicator Builder,
by Dimitris Tsokakis*/
D1=5;
MaxGraph=8;
ST3=StochK(D1);
ST33=StochD(D1);
Graph0=ST3;
Graph1=ST33;
Title=Name()+" - %K="+WriteVal(st3,FORMAT=1.2)+", %D="+
WriteVal(ST33,FORMAT=1.2)+
WriteIf(Cross(st3,st33)," POSITIVE CROSS"," ")+
WriteIf(Cross(ST33,ST3)," NEGATIVE CROSS","");
x = Cum(1);
per = 0.1;
s1=st33;
s11=st33;
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;
Graph6 = IIf(x>startt-1 AND TRENDLINES>0 AND TRENDLINES<100,trendlineS,-1e10);
Graph6Style = 1;
Graph6Color = 5;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
Graph7 = IIf(x>startT1-1 AND TRENDLINER>0 AND
TRENDLINER<100,trendlineR,-1e10);
Graph7Style = 1;
Graph7Color = 2;
_SECTION_END();
Let me explain how I use this. I have an indicator with parameter D1=5 and in another pane with D1=50. Let me name the indicator having D1=5 as STO5 and the other STO50. When both STO5 and STO50 says POSITIVE CROSS I would like to see a BUY signal. When both STO5 and STO50 says NEGATIVE CROSS I would like to have a SELL signal. What I would like to have is an AFL giving buy and sell signals according to these.
I am not able to create an indicator like this. Could anybody please help? And I also am interested in your opinion in using this strategy. I intend to use it in EOD trading, not intraday. I attach a picture showing the days of buy and sell (indicated by the pink lines).
Cheers,
s
I found a pretty good trading stategy, but I am not familiar with AFL writing. I use an AFL created by Dimitris Tsokakis, called Slow Stochastic and Trendlines. I paste the code here:
_SECTION_BEGIN("sto");
/*Slow Stochastic and Trendlines
for Indicator Builder,
by Dimitris Tsokakis*/
D1=5;
MaxGraph=8;
ST3=StochK(D1);
ST33=StochD(D1);
Graph0=ST3;
Graph1=ST33;
Title=Name()+" - %K="+WriteVal(st3,FORMAT=1.2)+", %D="+
WriteVal(ST33,FORMAT=1.2)+
WriteIf(Cross(st3,st33)," POSITIVE CROSS"," ")+
WriteIf(Cross(ST33,ST3)," NEGATIVE CROSS","");
x = Cum(1);
per = 0.1;
s1=st33;
s11=st33;
pS = TroughBars( s1, per, 1 ) == 0;
endt= LastValue(ValueWhen( pS, x, 1 ));
startt=LastValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = LastValue(ValueWhen( pS, s1, 1 ) );
startS = LastValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;
Graph6 = IIf(x>startt-1 AND TRENDLINES>0 AND TRENDLINES<100,trendlineS,-1e10);
Graph6Style = 1;
Graph6Color = 5;
pR = PeakBars( s11, per, 1 ) == 0;
endt1= LastValue(ValueWhen( pR, x, 1 ));
startt1=LastValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = LastValue(ValueWhen( pR, s11, 1 ) );
startR = LastValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
Graph7 = IIf(x>startT1-1 AND TRENDLINER>0 AND
TRENDLINER<100,trendlineR,-1e10);
Graph7Style = 1;
Graph7Color = 2;
_SECTION_END();
Let me explain how I use this. I have an indicator with parameter D1=5 and in another pane with D1=50. Let me name the indicator having D1=5 as STO5 and the other STO50. When both STO5 and STO50 says POSITIVE CROSS I would like to see a BUY signal. When both STO5 and STO50 says NEGATIVE CROSS I would like to have a SELL signal. What I would like to have is an AFL giving buy and sell signals according to these.
I am not able to create an indicator like this. Could anybody please help? And I also am interested in your opinion in using this strategy. I intend to use it in EOD trading, not intraday. I attach a picture showing the days of buy and sell (indicated by the pink lines).
Cheers,
s
Last edited: