.

High Low With Pivot And Target - Amibroker AFL Code

Click Image To Enlarge. Please Rate And Comment.

High Low With Pivot And Target

_SECTION_BEGIN("Price+FPSR+ZG+WW+StoDiv+CCI+"); 
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

 
periods = Param( "Periods", 45, 1, 200, 1 );
K1smooth = Param( "%K1 avg", 4, 1, 200, 1 );
//Plot( StochK( periods , K1smooth), _DEFAULT_NAME(), colorCustom3, styleNoLabel  | styleThick | styleDots);


periods = Param( "Periods", 45, 1, 200, 1 );
K1smooth = Param( "%K1 avg", 4, 1, 200, 1 );
D1smooth = Param( "%D1 avg", 2, 1, 200, 1 );
//Plot( StochD( periods , K1smooth, D1Smooth ), _DEFAULT_NAME(), colorCustom3, styleNoLabel  | styleThick | styleDots);


 
A = StochK( periods , K1smooth);
B = StochD( periods , K1smooth, D1Smooth );



Plot( C, "Close", IIf(a > 80 OR a < 20, colorWhite,IIf(a > b,colorBlue,colorRed)), styleNoTitle | styleCandle ); 




//////////////////////////////////////////////////  DP TOGGLE ///////////////////////////////////////////////////////




Show_Prev = ParamToggle( "Display Pivots", "No|Yes", 1);
 
// Get Previous Day's close, Low and High
DayC=Prev_Close = TimeFrameGetPrice( "C", inDaily, -1, expandFirst) ;
DayL=Prev_Low = TimeFrameGetPrice( "L", inDaily, -1, expandFirst) ;
DayH=Prev_High = TimeFrameGetPrice( "H", inDaily, -1, expandFirst) ;
Today = LastValue(Day( ) );
P = (Prev_High + Prev_Low + Prev_Close)/ 3;


R6 = (DayH / DayL) * DayC * 1.002;
R5 = (DayH / DayL) * DayC;
R4 = (((DayH / DayL) + 0.83) / 1.83) * DayC;
R3 = ( ( (DayH / DayL) + 2.66) / 3.66) * DayC;
R2 = ( ( (DayH / DayL) + 4.5) / 5.5) * DayC;
R1 = ( ( (DayH / DayL) + 10) / 11) * DayC;
 
S1 = (2- ( ( (DayH / DayL) + 10) / 11)) * DayC;
S2 = (2-( (DayH / DayL) + 4.5) / 5.5) * DayC;
S3 = (2-(( DayH / DayL) + 2.66) / 3.66) * DayC;
S4 = (2-( (DayH / DayL) + 0.83) / 1.83) * DayC;
S5 = (2-( DayH / DayL)) * DayC;
S6 = (2-( DayH / DayL)) * DayC * 0.998;
//////////////////////////////  FPSR  30 MT STRATEGY /////////////////////////////////////////////////////////////

//TimeFrameSet( inDaily );

BS=(Prev_High-Prev_Low)/3;
Y=Prev_Close+BS;
X=Prev_Close-BS;


MULT=0.0003;


YT=Y+MULT*Y;
YB=Y-MULT*Y;

XT=X+MULT*X;
XB=X-MULT*X;


//PlotOHLC( 0, Prev_High ,Prev_Low ,Prev_Low, "", HLColor, styleCloud|styleNoLabel);
HLColor = ColorRGB(70,70,70);

if(Show_Prev)
//{Plot(IIf(Today == Day(),R5, Null), "R5", ParamColor("R5", colorBlue),styleDots|styleThick|styleNoRescale);
Plot(IIf(Today == Day(),R4, Null), "R4", ParamColor("R4",colorRed),styleDashed|styleThick|styleNoRescale);
Plot(IIf(Today == Day(),R3, Null), "R3", ParamColor("R3",colorRed),styleDashed|styleThick|styleNoRescale);
//Plot(IIf(Today == Day(),R2, Null), "R2", ParamColor("R2", colorDarkRed),styleDots|styleThick|styleNoRescale|styleNoLabel);
//Plot(IIf(Today == Day(),R1, Null), "R1", ParamColor("R1",colorDarkRed),styleDashed|styleThick|styleNoRescale|styleNoLabel);
Plot(IIf(Today == Day(),P, Null), "P", ParamColor("P",colorYellow),styleDashed|styleThick|styleNoRescale);
//Plot(IIf(Today == Day(),S1, Null), "S1", ParamColor("S1", colorDarkGreen),styleDots|styleThick|styleNoRescale|styleNoLabel);
//Plot(IIf(Today == Day(),S2, Null), "S2", ParamColor("S2",colorDarkGreen),styleDashed|styleThick|styleNoRescale|styleNoLabel);
Plot(IIf(Today == Day(),S3, Null), "S3", ParamColor("S3",colorGreen),styleDashed|styleThick|styleNoRescale);
Plot(IIf(Today == Day(),S4, Null), "S4", ParamColor("S4", colorGreen),styleDashed|styleThick|styleNoRescale );
//Plot(IIf(Today == Day(),S5, Null), "S5", ParamColor("S5", colorDarkGreen),styleDashed|styleThick|styleNoRescale);



Plot(IIf(Today == Day(), Prev_High, Null), "Prev_High", ParamColor(" Prev_High", HLColor),styleDots|styleThick|styleNoRescale );
Plot(IIf(Today == Day(), Prev_Low, Null), "Prev_Low", ParamColor(" Prev_Low", HLColor),styleDots|styleThick|styleNoRescale );
//}


/////////////////////////////////////EMA 34  10 /////////////////////////////////////////////////////////////////

B10=EMA(C,3);
MULT=0.0002;
TB10 = B10+MULT*B10;
BB10 = B10-MULT*B10;
Col_cci = IIf(CCI(14) > BBandTop(CCI(14),5,0.5),colorDarkGreen,IIf(CCI(14) < BBandBot(CCI(14),5,0.5),colorDarkRed,colorYellow));
PlotOHLC( 0, TB10 , BB10 , BB10 , "", Col_cci, styleCloud | styleNoLabel);




B34=EMA(C,34);
MULT=0.0002;
TB34 = B34+MULT*B34;
BB34 = B34-MULT*B34;
//PlotOHLC( 0, TB34 , BB34 , BB34 , "EMA34", colorYellow, styleCloud );

//////////////////////////////  DAY HILO SHADOW /////////////////////////////////////////////////////////////


BSColor = ColorRGB(80,80,80);
HLColor = ColorRGB(20,20,40);
//PlotOHLC( 0, Prev_High ,Prev_Low ,Prev_Low, "", HLColor, styleCloud|styleNoLabel);

///////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////  DOUBLE TOP //////////////////////////////////////////


/* Detecting double tops */
percdiff = 5; /* peak detection threshold */
fwdcheck = 5; /* forward validity check */
mindistance = 10;
validdiff = percdiff/400;
PK= Peak( H, percdiff, 1 ) == High;

x = Cum( 1 );
XPK1 =  ValueWhen( PK, x, 1 ); 
XPK2 = ValueWhen( PK, x, 2 ); 

peakdiff = ValueWhen( PK, H, 1 )/ValueWhen( PK, H, 2 );
doubletop = PK AND abs( peakdiff - 1 ) < validdiff AND (XPK1 - XPK2)>mindistance AND High > HHV( Ref( H, fwdcheck ), fwdcheck - 1 );
SellDT = doubletop;
Buy = 0;
//Filter=SellDT;
WriteIf( Highest( doubletop ) == 1, "AmiBroker has detected some possible
double top patterns for " + name() + "\nLook for green arrows on the price
chart.", "There are no double top patterns for " + name() );



PlotShapes(SellDT*shapeHollowDownTriangle,colorPink, 0, High, Offset =-25);
PlotShapes(SellDT*shapeDigit0,colorPink, 0, High, Offset =40);
PlotShapes(SellDT*shapeDigit0,colorPink, 0, High, Offset =50);

_SECTION_END();


_SECTION_BEGIN("Fibo for all bars");

TimeFrameSet( inDaily ); 
DH=Ref(H,-1); 
DL=Ref(L,-1);
DC=Ref(C,-1);


pd = (O+ DH+ DL + DC )/4;
sd1 = (2*pd)-DH;
sd2 = pd -(DH - DL);
sd3 = Sd1 - (DH-DL); 
rd1 = (2*pd)-DL;
rd2 = pd +(DH -DL);
rd3 = rd1 +(DH-DL);

H4 =  (dH - dL) * 1.1 / 2 + dC;
H3 = (dH - dL) * 1.1 / 4 + dC;
h2 = (dH - dL) * 1.1 / 6 + dC;
H1 = (dH - dL) * 1.1 / 12 + dC;
L1 = dC - (dH - dL) * 1.1 / 12;
L2 = dC - (dH - dL) * 1.1 / 6;
L3 = dC - (dH - dL) * 1.1 / 4;
L4 = dC - (dH - dL) * 1.1 / 2 ;



//Plot (pd,"Pivot",colorBlue,styleDots);
//Plot (rd1," R1 ",35,styleDots);
//Plot (rd2," R2 ",35,styleDots);
//Plot (rd3," R3 ",35,styleDots);

//Plot (sd1," S1 ",4,styleDots);
//Plot (Sd2," S2 ",4,styleDots);
//Plot (Sd3," S3 ",4,8+16);
/*
style = IIf(ParamList("Chart style", "styleCandle|styleBar")=="styleCandle",64,128+4);
Plot (C,Date ()+" close",1,style); //ENABLE THIS TO HAVE CANDLES AS WELL
*/
TimeFrameRestore();

tgt_up = H4*5/1000 + H4;
tgt_up2 = H4*10/1000 + H4;
tgt_dn = L4-L4*5/1000;
tgt_dn2 = L4-L4*10/1000;

Title = EncodeColor(colorWhite)+ "" + " - " +  Name() + " - " + EncodeColor(colorRed)+ Interval(2) + EncodeColor(colorWhite) +
 "  - " + Date() +" - "
//+ WriteIf(Col_action==colorGreen, EncodeColor(colorGreen)+"stay LONG","")+ WriteIf(Col_action==colorRed, EncodeColor(colorRed)+"stay SHORT","")+  WriteIf(Col_action==colorBlack, EncodeColor(colorYellow)+"No Trend","")+"\n"
+ "Vol= "+ WriteVal(V) +WriteIf ( V > MA(V,26) ,EncodeColor(colorGreen)+"  UP "+ (V/MA(V,26))*100 + " %", EncodeColor(colorRed)+"  DOWN "+ (V/MA(V,26))*100 + " %")
+ EncodeColor(colorGreen)+   "\n H4 : "+ EncodeColor(colorWhite)+H4+ EncodeColor(colorGreen)+   "    tgt : "+ EncodeColor(colorWhite)+tgt_up +EncodeColor(colorGreen)+   "    tgt2 : "+ EncodeColor(colorWhite)+tgt_up2 
+ EncodeColor(colorGreen)+   "\n H3 : "+ EncodeColor(colorWhite)+H3 
+ EncodeColor(colorGreen)+   "\n H2 : "+ EncodeColor(colorWhite)+H2 
+ EncodeColor(colorGreen)+   "\n H1 : "+ EncodeColor(colorWhite)+H1+ EncodeColor(colorGreen)+   "`            Hi: "+ EncodeColor(colorWhite)+H
+ EncodeColor(colorBlue)+   "\n Pivot : "+ EncodeColor(colorWhite)+pd + EncodeColor(colorYellow)+   "`   Op: "+ EncodeColor(colorWhite)+O+ EncodeColor(colorAqua)+   "Cl: "+ EncodeColor(colorBrightGreen)+C
+ EncodeColor(colorRed)+   "\n L1 : "+ EncodeColor(colorWhite)+L1+ EncodeColor(colorRed)+   "`            Lo: "+ EncodeColor(colorWhite)+L
+ EncodeColor(colorRed)+   "\n L2 : "+ EncodeColor(colorWhite)+L2
+ EncodeColor(colorRed)+   "\n L3 : "+ EncodeColor(colorWhite)+L3
+ EncodeColor(colorRed)+   "\n L4 : "+ EncodeColor(colorWhite)+L4+ EncodeColor(colorRed)+      "     tgt : "+ EncodeColor(colorWhite)+tgt_dn + EncodeColor(colorRed)+      "     tgt2 : "+ EncodeColor(colorWhite)+tgt_dn2
;

_SECTION_END();

Plot(6, "", IIf(ADX(7) > Ref(ADX(7),-1) AND ADX(7) > 20,colorBlue,colorBlack), styleOwnScale| styleArea|styleNoLabel,-0.5,100);
Previous Post Next Post