Skip to main content

Swing Trading ST for Amibroker (AFL)

casoni over 11 years ago Amibroker (AFL)

  • Rating:
    3 / 5 (Votes 7)
  • Tags:
    swing, Gap, amibroker

Hello Everone,

This concept was discussed on Traderji by Smart_Trader

and this concept is coded By Edward Pottasch

Many Many Thanks to Edward Pottasch , for taking out his precious time and coded this concept

for Details about this concept check this
http://www.traderji.com/day-trading/49521-thoughts-day-swing-trading.html

Indicator / Formula

Copy & Paste Friendly
// Edward Pottasch 24dec2014
SetBarsRequired(sbrAll,sbrAll); 
xx=BarIndex();x=xx;Lx=LastValue(x); 
rightStrength=Optimize("R_S",Param("R_S",3,1,50,1) ,1,50,1); 
leftStrength=Optimize("L_S",Param("L_S",3,1,50,1), 1,50,1); 

function pkID(rightStrength,leftStrength) 
{ 
pk=H>Ref(HHV(H,leftStrength),-1) AND H>=Ref(HHV(H,rightStrength),rightStrength); 
return pk; 
} 
function trID(rightStrength,leftStrength) 
{ 
tr=L<Ref(LLV(L,leftStrength),-1) AND L<=Ref(LLV(L,rightStrength),rightStrength); 
return tr; 
} 

pk=pkID(rightStrength,leftStrength); 
tr=trID(rightStrength,leftStrength); 


SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0 ,chartShowDates); 
SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorR ed,colorLightGrey))); 
Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,col orDarkRed,colorLightGrey)),64,null,null,0,0,1); 
PlotShapes(shapeSmallCircle*tr,IIf(Lx-ValueWhen(tr,x)>rightStrength,ColorRGB(0,100,0),co lorWhite),0,L,-10); 
PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>rightStrength,ColorRGB(255,0,0),co lorWhite),0,H,10); 

pkHigh1=Ref(ValueWhen(pk,H,1),-(rightStrength+1)); 
trLow1=Ref(ValueWhen(Tr,L,1),-(rightStrength+1)); 
pkHigh0=ValueWhen(pk,H,0); 
trLow0=ValueWhen(Tr,L,0); 

upGap=Cross(C,pkHigh1) AND pkHigh1<trLow0; 
dnGap=Cross(trLow1,C) AND trLow1>pkHigh0; 

gapBaseUp=ValueWhen(upGap,pkHigh1); 
gapBaseDn=ValueWhen(dnGap,trLow1); 
gapExtrUp=ValueWhen(upGap,trLow0); 
gapExtrDn=ValueWhen(dnGap,pkHigh0); 

upGapArea=Flip(upGap,dnGap); 
dnGapArea=Flip(dnGap,upGap); 

gapBase=IIf(upGapArea,gapBaseUp,gapBaseDn); 
gapExtr=IIf(upGapArea,gapExtrUp,gapExtrDn); 

Plot(pkHigh1,"",colorBlue,24,Null,Null,0,2,1); 
Plot(trLow1,"",colorRed,24,Null,Null,0,2,1); 
Plot(gapBase,"",colorlightgrey,styledashed,Null,Nu ll,0,2,1); 
Plot(gapExtr,"",colorlightgrey,styledashed,Null,Nu ll,0,2,1); 
PlotOHLC(gapBase,gapBase,gapExtr,gapExtr,"",IIf(ga pExtr>gapBase,colorseaGreen,colorOrange),styleClou d|styleNoRescale,Null,Null,0,-1,1);


strWeekday = StrMid("SunMonTueWedThuFriSat", SelectedValue(DayOfWeek())*3,3);
Title = EncodeColor(colorWhite)+ "Gap _ST style by Edward.P" + " - " + Name() + " - "+ "" + fullName() + " " +
EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +" - " + Date() + " # "+strWeekday + 
StrFormat("\nOp %g, Hi %g, Lo %g, Cl %g, Vol %g", O, H, L, C, V)+
"\nRight Bars: " + rightStrength + 
"\nLeft Bars : " + leftStrength;

//============================================

13 comments

1. pras
over 11 years ago

please give the link again because above link broken

3. casoni
over 11 years ago

error due to older version of Amibroker
Try this

Plot(pkHigh1,"",colorBlue,24); 
Plot(trLow1,"",colorRed,24); 
Plot(gapBase,"",colorlightgrey,styledashed); 
Plot(gapExtr,"",colorlightgrey,styledashed); 
PlotOHLC(gapBase,gapBase,gapExtr,gapExtr,"",IIf(gapExtr>gapBase,
colorseaGreen,colorOrange),styleCloud|styleNoRescale);
 
7. bsedoha
over 11 years ago

Please provide the correct Trader ji link.

Thanks in advance

8. bsedoha
over 11 years ago

@ Casoni,

Is there is anyway by which we can add the buy and sell signal in it ??

Thanks in advance

11. davidalan
over 11 years ago
Buy = upGap; Sell = dnGap; Buy = ExRem( Buy, Sell ); Sell = ExRem( Sell, Buy ); PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,Low,-25); PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWHITE, 0,High,-25)
over 11 years ago

you can’t always immediately say that a code looks into the future without understanding the code. Fractal type pivots always look into the future. That is why you need to wait until a pivot is completed before you can use it. Fractal type pivots are used to bring some structure in the price movement but you can’t buy/short at a fractal low or high as shown in the chart (unless you get lucky). Before a pivot is confirmed you always have to wait rightstrength + 1 bars.

here some code that adds signals (you can also toggle to system type signals):

http://wisestocktrader.com/indicatorpasties/1434-gapfill3b

13. davidalan
over 11 years ago

Mr Pottasch very solid idea, best programmer,i am a big fan, keep up your get work thanks, wishing you and yours a happy and healthy New Years

14. standris
almost 10 years ago

try this:

// Edward Pottasch 24dec2014
SetBarsRequired(sbrAll,sbrAll); 
xx=BarIndex();x=xx;Lx=LastValue(x); 
rightStrength=Optimize("R_S",Param("R_S",3,1,50,1) ,1,50,1); 
leftStrength=Optimize("L_S",Param("L_S",3,1,50,1), 1,50,1); 

function pkID(rightStrength,leftStrength) 
{ 
pk=H>Ref(HHV(H,leftStrength),-1) AND H>=Ref(HHV(H,rightStrength),rightStrength); 
return pk; 
} 
function trID(rightStrength,leftStrength) 
{ 
tr=L<Ref(LLV(L,leftStrength),-1) AND L<=Ref(LLV(L,rightStrength),rightStrength); 
return tr; 
} 

pk=pkID(rightStrength,leftStrength); 
tr=trID(rightStrength,leftStrength); 


SetChartBkColor(ColorRGB(0,0,0));SetChartOptions(0 ,chartShowDates); 
SetBarFillColor(IIf(C>O,colorGreen,IIf(C<=O,colorRed,colorLightGrey))); 
Plot(C,"Price",IIf(C>O,colorDarkGreen,IIf(C<=O,colorDarkRed,colorLightGrey)),64,null,null,0,0,1); 
PlotShapes(shapeSmallCircle*tr,IIf(Lx-ValueWhen(tr,x)>rightStrength,ColorRGB(0,100,0),colorWhite),0,L,-10); 
PlotShapes(shapeSmallCircle*pk,IIf(Lx-ValueWhen(pk,x)>rightStrength,ColorRGB(255,0,0),colorWhite),0,H,10); 

pkHigh1=Ref(ValueWhen(pk,H,1),-(rightStrength+1)); 
trLow1=Ref(ValueWhen(Tr,L,1),-(rightStrength+1)); 
pkHigh0=ValueWhen(pk,H,0); 
trLow0=ValueWhen(Tr,L,0); 

upGap=Cross(C,pkHigh1) AND pkHigh1<trLow0; 
dnGap=Cross(trLow1,C) AND trLow1>pkHigh0; 

gapBaseUp=ValueWhen(upGap,pkHigh1); 
gapBaseDn=ValueWhen(dnGap,trLow1); 
gapExtrUp=ValueWhen(upGap,trLow0); 
gapExtrDn=ValueWhen(dnGap,pkHigh0); 

upGapArea=Flip(upGap,dnGap); 
dnGapArea=Flip(dnGap,upGap); 

gapBase=IIf(upGapArea,gapBaseUp,gapBaseDn); 
gapExtr=IIf(upGapArea,gapExtrUp,gapExtrDn); 

Plot(pkHigh1,"",colorBlue,24,Null,Null,0,2,1); 
Plot(trLow1,"",colorRed,24,Null,Null,0,2,1); 
Plot(gapBase,"",colorlightgrey,styledashed,Null,Null,0,2,1); 
Plot(gapExtr,"",colorlightgrey,styledashed,Null,Null,0,2,1); 
PlotOHLC(gapBase,gapBase,gapExtr,gapExtr,"",IIf(gapExtr>gapBase,colorseaGreen,colorOrange),styleCloud|styleNoRescale,Null,Null,0,-1,1);


strWeekday = StrMid("SunMonTueWedThuFriSat", SelectedValue(DayOfWeek())*3,3);
Title = EncodeColor(colorWhite)+ "Gap _ST style by Edward.P" + " - " + Name() + " - "+ "" + fullName() + " " +
EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +" - " + Date() + " # "+strWeekday + 
StrFormat("\nOp %g, Hi %g, Lo %g, Cl %g, Vol %g", O, H, L, C, V)+
"\nRight Bars: " + rightStrength + 
"\nLeft Bars : " + leftStrength;

//============================================

Leave Comment

Please login here to leave a comment.