Visual gaps on chart

#1
Hi all,

I just created a simple afl to show gaps on the chart.
You can chose in percentage the minimum gapdifference.

_SECTION_BEGIN("_plot gap");

Difference=Param("difference",0,0,5,0.1);
Diff=((Ref(C,-1)/100)*Difference);

GapU=O>Ref(H,-1)+Diff;
GapUL=(O>Ref(H,-1)+Diff) AND L<=Ref(L,-1);
GapUC=(O>Ref(H,-1)+Diff) AND L<=Ref(C,-1);
GAPUH=(O>Ref(H,-1)+Diff) AND L<=Ref(H,-1);
GAPUM=(O>Ref(H,-1)+Diff) AND (L<=((Ref(H,-1)+Ref(L,-1))/2));

GapD=O<Ref(L,-1)-Diff;
GapDL=(O<Ref(L,-1)-Diff) AND H>=Ref(L,-1);
GapDC=(O<Ref(L,-1)-Diff) AND H>=Ref(C,-1);
GAPDH=(O<Ref(L,-1)-Diff) AND H>=Ref(H,-1);
GAPDM=(O<Ref(L,-1)-Diff) AND (H>=((Ref(H,-1)+Ref(L,-1))/2));

Gap_U= ParamToggle("gap up ","No|Yes",0);
Gap_UH= ParamToggle("gap up narrowed to previous high ","No|Yes",0);
Gap_UC= ParamToggle("gap up narrowed to previous close ","No|Yes",0);
Gap_UL= ParamToggle("gap up narrowed to previous low ","No|Yes",0);
Gap_UM= ParamToggle("gap up narrowed to previous middle ","No|Yes",0);

Gap_D= ParamToggle("gap down ","No|Yes",0);
Gap_DL= ParamToggle("gap down narrowed to previous low ","No|Yes",0);
Gap_DC= ParamToggle("gap down narrowed to previous close ","No|Yes",0);
Gap_DH= ParamToggle("gap down narrowed to previous high ","No|Yes",0);
Gap_DM= ParamToggle("gap down narrowed to previous middle ","No|Yes",0);

if (Gap_U)
PlotShapes(GapU*shapeSmallCircle,colorBlue);
if (Gap_UL)
PlotShapes(GapUL*shapeSmallCircle,colorBlue);
if (Gap_UC)
PlotShapes(GapUC*shapeSmallCircle,colorBlue);
if (Gap_UH)
PlotShapes(GapUH*shapeSmallCircle,colorBlue);
if (Gap_UM)
PlotShapes(GapUM*shapeSmallCircle,colorBlue);

if (Gap_D)
PlotShapes(GapD*shapeSmallCircle,colorOrange);
if (Gap_DL)
PlotShapes(GapDL*shapeSmallCircle,colorOrange);
if (Gap_DC)
PlotShapes(GapDC*shapeSmallCircle,colorOrange);
if (Gap_DH)
PlotShapes(GapDH*shapeSmallCircle,colorOrange);
if (Gap_DM)
PlotShapes(GapDM*shapeSmallCircle,colorOrange);

_SECTION_END();

What need improvement is still the visual aspect. I.e. if you selected "yes" in all the gap ups, that you get 5 dots vertical below the low, each a different color.
I'am still a bit struggeling with that.
Also im not sure I calculated the gap percentage the right way. Please correct me if im wrong.
 
#2
alright, a small update

_SECTION_BEGIN("_plot gap");

Difference=Param("difference",0,0,5,0.1);
Diff=((Ref(C,-1)/100)*Difference);

GapU=O>Ref(H,-1)+Diff;
GapUL=(O>Ref(H,-1)+Diff) AND L<=Ref(L,-1);
GapUC=(O>Ref(H,-1)+Diff) AND L<=Ref(C,-1);
GAPUH=(O>Ref(H,-1)+Diff) AND L<=Ref(H,-1);
GAPUM=(O>Ref(H,-1)+Diff) AND (L<=((Ref(H,-1)+Ref(L,-1))/2));

GapD=O<Ref(L,-1)-Diff;
GapDL=(O<Ref(L,-1)-Diff) AND H>=Ref(L,-1);
GapDC=(O<Ref(L,-1)-Diff) AND H>=Ref(C,-1);
GAPDH=(O<Ref(L,-1)-Diff) AND H>=Ref(H,-1);
GAPDM=(O<Ref(L,-1)-Diff) AND (H>=((Ref(H,-1)+Ref(L,-1))/2));

Gap_U= ParamToggle("gap up (blue)","No|Yes",0);
Gap_UH= ParamToggle("gap up narrowed to previous high (green)","No|Yes",0);
Gap_UC= ParamToggle("gap up narrowed to previous close (orange)","No|Yes",0);
Gap_UL= ParamToggle("gap up narrowed to previous low (red) ","No|Yes",0);
Gap_UM= ParamToggle("gap up narrowed to previous middle (black)","No|Yes",0);

Gap_D= ParamToggle("gap down (blue) ","No|Yes",0);
Gap_DL= ParamToggle("gap down narrowed to previous low (red)","No|Yes",0);
Gap_DC= ParamToggle("gap down narrowed to previous close (orange)","No|Yes",0);
Gap_DH= ParamToggle("gap down narrowed to previous high (green)","No|Yes",0);
Gap_DM= ParamToggle("gap down narrowed to previous middle (black) ","No|Yes",0);

if (Gap_U) PlotShapes(IIf(GapU, shapeSmallCircle, shapeNone),colorBlue, 0,L, Offset=-45);
if (Gap_UL) PlotShapes(IIf(GapUL, shapeSmallCircle, shapeNone),colorRed, 0,L, Offset=-55);
if (Gap_UC) PlotShapes(IIf(GapUC, shapeSmallCircle, shapeNone),colorOrange, 0,L, Offset=-65);
if (Gap_UH) PlotShapes(IIf(GapUH, shapeSmallCircle, shapeNone),colorGreen, 0,L, Offset=-75);
if (Gap_UM) PlotShapes(IIf(GapUM, shapeSmallCircle, shapeNone),colorBlack, 0,L, Offset=-85);

if (Gap_D) PlotShapes(IIf(GapD, shapeSmallCircle, shapeNone),colorBlue, 0,H, Offset=45);
if (Gap_DL) PlotShapes(IIf(GapDL, shapeSmallCircle, shapeNone),colorRed, 0,H, Offset=55);
if (Gap_DC) PlotShapes(IIf(GapDC, shapeSmallCircle, shapeNone),colorOrange, 0,H, Offset=65);
if (Gap_DH) PlotShapes(IIf(GapDH, shapeSmallCircle, shapeNone),colorGreen, 0,H, Offset=75);
if (Gap_DM) PlotShapes(IIf(GapDM, shapeSmallCircle, shapeNone),colorBlack, 0,H, Offset=85);

_SECTION_END();

With this simple afl I hope to get a bit more insight what market responses are when a gap occurs, and if it's interesting to take a low risk position in the direction of a trading system.

edit: gapcalculation difference should be changed. will update later on.
 
Last edited:
#3
small update

well, another small update,
probably last one, since there's no interest.

next on the list; analysing the 3 bars before the gap, the bar it's self, and the bar after, which you could enter a trade on a break.


_SECTION_BEGIN("_plot gap");

Difference=Param("difference",0,0,3,0.05);

//Diff=((Ref(C,-1)/100)*Difference);
DiffH=((Ref(H,-1)/100)*Difference);
DiffL=((Ref(L,-1)/100)*Difference);


GapU=O>Ref(H,-1)+DiffH;
GapUL=(O>Ref(H,-1)+DiffH) AND L<=Ref(L,-1);
GapUC=(O>Ref(H,-1)+DiffH) AND L<=Ref(C,-1);
GAPUH=(O>Ref(H,-1)+DiffH) AND L<=Ref(H,-1);
GAPUM=(O>Ref(H,-1)+DiffH) AND (L<=((Ref(H,-1)+Ref(L,-1))/2));

GapD=O<Ref(L,-1)-DiffL;
GapDL=(O<Ref(L,-1)-DiffL) AND H>=Ref(L,-1);
GapDC=(O<Ref(L,-1)-DiffL) AND H>=Ref(C,-1);
GAPDH=(O<Ref(L,-1)-DiffL) AND H>=Ref(H,-1);
GAPDM=(O<Ref(L,-1)-DiffL) AND (H>=((Ref(H,-1)+Ref(L,-1))/2));

Gap_U= ParamToggle("gap up (blue)","No|Yes",1);
Gap_UH= ParamToggle("gap up narrowed to previous high (green)","No|Yes",1);
Gap_UC= ParamToggle("gap up narrowed to previous close (orange)","No|Yes",1);
Gap_UL= ParamToggle("gap up narrowed to previous low (red) ","No|Yes",1);
Gap_UM= ParamToggle("gap up narrowed to previous middle (black)","No|Yes",1);

Gap_D= ParamToggle("gap down (blue) ","No|Yes",1);
Gap_DL= ParamToggle("gap down narrowed to previous low (red)","No|Yes",1);
Gap_DC= ParamToggle("gap down narrowed to previous close (orange)","No|Yes",1);
Gap_DH= ParamToggle("gap down narrowed to previous high (green)","No|Yes",1);
Gap_DM= ParamToggle("gap down narrowed to previous middle (black) ","No|Yes",1);

if (Gap_U) PlotShapes(IIf(GapU, shapeSmallCircle, shapeNone),colorBlue, 0,L, Offset=-45);
if (Gap_UL) PlotShapes(IIf(GapUL, shapeSmallCircle, shapeNone),colorRed, 0,L, Offset=-55);
if (Gap_UC) PlotShapes(IIf(GapUC, shapeSmallCircle, shapeNone),colorOrange, 0,L, Offset=-65);
if (Gap_UH) PlotShapes(IIf(GapUH, shapeSmallCircle, shapeNone),colorGreen, 0,L, Offset=-75);
if (Gap_UM) PlotShapes(IIf(GapUM, shapeSmallCircle, shapeNone),colorBlack, 0,L, Offset=-85);

if (Gap_D) PlotShapes(IIf(GapD, shapeSmallCircle, shapeNone),colorBlue, 0,H, Offset=45);
if (Gap_DL) PlotShapes(IIf(GapDL, shapeSmallCircle, shapeNone),colorRed, 0,H, Offset=55);
if (Gap_DC) PlotShapes(IIf(GapDC, shapeSmallCircle, shapeNone),colorOrange, 0,H, Offset=65);
if (Gap_DH) PlotShapes(IIf(GapDH, shapeSmallCircle, shapeNone),colorGreen, 0,H, Offset=75);
if (Gap_DM) PlotShapes(IIf(GapDM, shapeSmallCircle, shapeNone),colorBlack, 0,H, Offset=85);

_SECTION_END();

Have a nice day!
-BirdsEye
 
#4
nice approach.

I generally prefer a trading system with
buy on the pattern ( gap's in this case)
sell = 0
same optimized ,profit & loss targets through applystop.
& hope to get more than 66-70 % success rate .

good luck.
 

Similar threads