Advanced support resistence and trendlines afl

Joined
May 9, 2009
Messages
107
Likes
23
#22
///////////////////////////////////////////////////////////////////////////////////////////
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} ,{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot(C, "", IIf(O>=C, colorOrange, colorGreen),styleCandle);

SetChartBkGradientFill( ParamColor("Inner panel upper",colorBlack),ParamColor("Inner panel lower",colorBlack));
_N(Title = EncodeColor(colorWhite)+StrFormat(" {{NAME}} - {{INTERVAL}} {{DATE}} Open:%g, Close:%g ,{{VALUES}}",O,C ));

/////////////////////////////////////////////////////////////////////////////////////////////

Plot(EMA(C,13),"",colorYellow);
/////////////////////////////////////////////////////////////

per1=Param ("per1", 0.325,0.1,50,0.10);

per=per1;
x = Cum(1);
s1=L;
s11=H;
pS = TroughBars( s1, per, 1 ) == 0;
endt= SelectedValue(ValueWhen( pS, x, 1 ));
startt=SelectedValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = SelectedValue(ValueWhen( pS, s1, 1 ) );
startS = SelectedValue( ValueWhen( pS, s1, 1 ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;
g3= IIf(x>startt-10,trendlineS,-1e10);
Plot(g3,"",colorRed,styleDashed);

pR = PeakBars( s11, per, 1 ) == 0;
endt1= SelectedValue(ValueWhen( pR, x, 1 ));
startt1=SelectedValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = SelectedValue(ValueWhen( pR, s11, 1 ) );
startR = SelectedValue( ValueWhen( pR, s11, 1 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
g4= IIf(x>startT1-10,trendlineR,-1e10);
Plot(g4,"",colorGreen,styleDashed);
//////////////////////////////////////////////////////////////////////////////////////////////////
perc=per1;
x=BarIndex();xx=SelectedValue(x);
t1=SelectedValue(ValueWhen(PeakBars(C,perc)==0,x));
H1=SelectedValue(ValueWhen(PeakBars(C,perc)==0,C));
t11=SelectedValue(ValueWhen(TroughBars(C,perc)==0,x));
H11=SelectedValue(ValueWhen(TroughBars(C,perc)==0,C));
g=t1>t11;
shape=IIf(g,shapeDownArrow*(x==t1),shapeUpArrow*(x==t11));
Color=IIf(g,colorRed,colorGreen);
PlotShapes(shape,color);
/////////////////////////////////////////////////////////////////////////////////////////////////

per=per1;

x = Cum(1);
s1=C;
s11=C;
pS = TroughBars( s1, per, 1 ) == 0;
endt= SelectedValue(ValueWhen( pS, x, 1 ));
startt=SelectedValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = SelectedValue(ValueWhen( pS, s1, 1 ) );
startS = SelectedValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;
g3= IIf(x>startt-10,trendlineS,-1e10);
Plot(g3,"",colorRed,styleThick);

pR = PeakBars( s11, per, 1 ) == 0;
endt1= SelectedValue(ValueWhen( pR, x, 1 ));
startt1=SelectedValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = SelectedValue(ValueWhen( pR, s11, 1 ) );
startR = SelectedValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
g4= IIf(x>startT1-10,trendlineR,-1e10);
Plot(g4,"",colorGreen,styleThick);
//////////////////////////////////////////////////////////////////////////////

Goodwork today only i opted my trading system
:thumb:
 
Joined
Mar 26, 2005
Messages
68
Likes
30
#23
It is amazing that I could see a very promising afl. Thank you Vijayan, your this afl influenced me to think that I must learn the afl language and must also be a a partner in the project in stead of sitting on the fence.
Cheers!!!:clapping:
 

vijayanscbe

Well-Known Member
Joined
Apr 10, 2008
Messages
322
Likes
528
Location
coimbatore
#24
today 1st two trades failed
in 1st trade got uparrow and crossed green line but sl got hitted



in 2nd trade gotsell arrow and crossed red line but failed



3rd trade got arrow and crossed green line and this profit recovers the 1st two trades loss



so in gud movement day this afl missed the gud profit ......this a bug hav to improve :confused:
 

vijayanscbe

Well-Known Member
Joined
Apr 10, 2008
Messages
322
Likes
528
Location
coimbatore
#25
I will react in more detail later when I have time. For now maybe it could be helpful when you indicate in the chart when a signal is known in real time. For instance Eric Tangen wrote this code:

can't post links so it seems, but it is in the Amibroker library, search by Zig. His post is called:

"Zig Zag Indicator with Valid Entry and Exit Points"

here he indicates where a buy / short is valid. That would we useful in your chart.
Reply With Quote
i hav added this trendline with ziz zag

//////////////////////////////////////////////////////////////////////////////////////////


//z_ZigZagValid
// ******** CHARTING
per=Param ("per1", 0.325,0.1,50,0.10);

PercentChange = per;
mystartbar = SelectedValue(BarIndex()); // FOR GRAPHING

mystartbardate = LastValue(ValueWhen(mystartbar == BarIndex(), DateNum(),1));

InitialValue = LastValue(ValueWhen(mystartbardate == DateNum(), C , 1 ) ) ;
Temp1 = IIf(BarIndex() >= mystartbar, InitialValue, Null) ;
Plot(Temp1, " ", colorBlack,styleLine);
Plot((1+(LastValue(PercentChange)/100))*(Temp1), " ", colorGreen, styleLine) ;
Plot((1-(LastValue(PercentChange)/100))*(Temp1), " ", colorRed, styleLine) ;

ZZ = Zig(C,LastValue(PercentChange)) ;
PivotLow = Ref(IIf(Ref(ROC(ZZ,1),-1) < 0 AND ROC(ZZ,1) > 0, 1, Null),1);
PivotHigh = Ref(IIf(Ref(ROC(ZZ,1),-1) > 0 AND ROC(ZZ,1) < 0, 1, Null),1);

PlotShapes( shapeCircle*PivotLow, colorGreen,0, L, -20) ;
PlotShapes( shapeCircle*PivotHigh,colorRed,0,H, 20) ;

Buy_Valid = IIf(C>(1+(LastValue(PercentChange)/100))*(ValueWhen(PivotLow, C,
1))
AND ROC(ZZ,1) > 0,1,0);
Sell_Valid = IIf(C<(1-(LastValue(PercentChange)/100))*(ValueWhen(PivotHigh, C,
1))
AND ROC(ZZ,1) < 0,1,0);

Buy_Valid = ExRem(Buy_Valid,Sell_Valid);
Sell_Valid = ExRem(Sell_Valid,Buy_Valid);

PlotShapes( shapeUpArrow*Buy_Valid, colorGreen,0, L, -20);
PlotShapes( shapeDownArrow*Sell_Valid, colorRed,0,H, -20) ;

BarColors =
IIf(BarsSince(Buy_Valid) < BarsSince(Sell_Valid)
AND BarsSince(Buy_Valid)!=0, colorGreen,
IIf(BarsSince(Sell_Valid) < BarsSince(Buy_Valid)
AND BarsSince(Sell_Valid)!=0, colorRed, colorBlue));

Plot(C, " ", BarColors, styleCandle ) ;
Plot(ZZ," ", colorLightGrey,styleLine|styleThick);
Plot(ZZ," ", BarColors,styleDots|styleNoLine);

Title = Name() + " " + Date() + WriteIf(PivotLow, " Up Pivot
","")+WriteIf(PivotHigh," Down Pivot ","")+ WriteIf(Buy_Valid, " Buy Point ",
"") + WriteIf(Sell_Valid, " Sell Point ", "") ;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

x = Cum(1);
s1=C;
s11=C;
pS = TroughBars( s1, per, 1 ) == 0;
endt= SelectedValue(ValueWhen( pS, x, 1 ));
startt=SelectedValue(ValueWhen( pS, x, 2 ));
dtS =endt-startt;
endS = SelectedValue(ValueWhen( pS, s1, 1 ) );
startS = SelectedValue( ValueWhen( pS, s1, 2 ));
aS = (endS-startS)/dtS;
bS = endS;
trendlineS = aS * ( x -endt ) + bS;
g3= IIf(x>startt-10,trendlineS,-1e10);
Plot(g3,"",colorRed,styleThick);

pR = PeakBars( s11, per, 1 ) == 0;
endt1= SelectedValue(ValueWhen( pR, x, 1 ));
startt1=SelectedValue(ValueWhen( pR, x, 2 ));
dtR =endt1-startt1;
endR = SelectedValue(ValueWhen( pR, s11, 1 ) );
startR = SelectedValue( ValueWhen( pR, s11, 2 ));
aR = (endR-startR)/dtR;
bR = endR;
trendlineR = aR * ( x -endt1 ) + bR;
g4= IIf(x>startT1-10,trendlineR,-1e10);
Plot(g4,"",colorGreen,styleThick);

//////////////////////////////////////////////////////////////////////////////////////
 
Joined
May 9, 2009
Messages
107
Likes
23
#26
today 1st two trades failed
in 1st trade got uparrow and crossed green line but sl got hitted



in 2nd trade gotsell arrow and crossed red line but failed



3rd trade got arrow and crossed green line and this profit recovers the 1st two trades loss



so in gud movement day this afl missed the gud profit ......this a bug hav to improve :confused:

for 10 min what is the value of per 1 ?
 

vijayanscbe

Well-Known Member
Joined
Apr 10, 2008
Messages
322
Likes
528
Location
coimbatore
#27
^^^^^

kirthi am mostly do trades with 5min chart with 0.325%...........

i hav not tested with other time frames with other %...........

any how my idea is u can opt 0.5% for 10min but do back test and use.........

dont forgot to post ur results :clap:
 
Joined
Nov 17, 2008
Messages
196
Likes
110
Location
Hyderabad
#29
last long trade gave at 4978 .........

today reversed to short at 5086............ 108 points profit ..........:clap:

let see how this last short trade going to give how much profit ...... :thumb:
My Friend, I think you missed two trades as per your system.

One short signal was given at the opening bar of today.
And then a buy signal was given at 12:55 bar today.

It seems you are not taking all signals generated. Is it correct?
 

Mangafreakz

Well-Known Member
Joined
Apr 6, 2009
Messages
537
Likes
630
#30
Are you using any RT data source to you Amibroker ? Which one ?
Also i saw the arrows appear after 2-3 bars , can we take the Buy/Sell decisions after the arrow signals appear?
 

Similar threads

Broker Special Offers