AFL for Pivot Point (static)

toocool

Well-Known Member
#11


@kelvinhand , is it possible to draw only current pivot , using your afl? just like the image i posted from java chart?

i cannot get it done


as you can see its possible in my java chart and i dont need previous gone pivots drawn at all

thanks
 

rrrajguru

Well-Known Member
#12


@kelvinhand , is it possible to draw only current pivot , using your afl? just like the image i posted from java chart?

i cannot get it done


as you can see its possible in my java chart and i dont need previous gone pivots drawn at all

thanks
toocool, Have you got the afl, shown above by you?
 

KelvinHand

Well-Known Member
#14


@kelvinhand , is it possible to draw only current pivot , using your afl? just like the image i posted from java chart?

i cannot get it done


as you can see its possible in my java chart and i dont need previous gone pivots drawn at all

thanks

// To calculate the Pivot Levels
PP = (H1 + L1 + C1) / 3;
R1 = (2 * PP) - L1 ;
S1 = (2 * PP) - H1 ;
R2 = PP - s1 + r1;
S2 = PP - (r1 - s1) ;
R3 = 2 * (PP - L1) + H1 ;
S3 = L1 - (2 * (H1 - PP));


place the following code before above
PHP:
x=PP[BarCount-1];
for(i=BarCount-2; i>0; i--)
    if (PP[i]!=x) 
    {
      i++;
      break;
    }  


for(j=0; j<i; j++)
{
pp[j]=null;
R1[j]=null;
S1[j]=null;
R2[j]=null;
S2[j]=null;
R3[j]=null;
S2[j]=null;
}

//    Plot Pivot Levels in the charts
Plot (PP,"",PP_Color,PP_Style|styleNoRescale);

Plot (R1,"",Rn_Color,R1S1_Style|styleNoRescale)
Plot (S1,"",Sn_Color,R1S1_Style|styleNoRescale)

Plot (R2,"",Rn_Color,R2S2_Style|styleNoRescale)
Plot (S2,"",Sn_Color,R2S2_Style|styleNoRescale)

Plot (R3,"",Rn_Color,R3S3_Style|styleNoRescale)
Plot (S3,"",Sn_Color,R3S3_Style|styleNoRescale)
I tested the day pivot OK, i cannot test the week & month pivots.
Try and see whether it work for you
 
Last edited:
#15
// To calculate the Pivot Levels
PP = (H1 + L1 + C1) / 3;
R1 = (2 * PP) - L1 ;
S1 = (2 * PP) - H1 ;
R2 = PP - s1 + r1;
S2 = PP - (r1 - s1) ;
R3 = 2 * (PP - L1) + H1 ;
S3 = L1 - (2 * (H1 - PP));


place the following code before above
PHP:
x=PP[BarCount-1];
for(i=BarCount-2; i>0; i--)
    if (PP[i]!=x) 
    {
      i++;
      break;
    }  


for(j=0; j<i; j++)
{
pp[j]=null;
R1[j]=null;
S1[j]=null;
R2[j]=null;
S2[j]=null;
R3[j]=null;
S2[j]=null;
}

//    Plot Pivot Levels in the charts
Plot (PP,"",PP_Color,PP_Style|styleNoRescale);

Plot (R1,"",Rn_Color,R1S1_Style|styleNoRescale)
Plot (S1,"",Sn_Color,R1S1_Style|styleNoRescale)

Plot (R2,"",Rn_Color,R2S2_Style|styleNoRescale)
Plot (S2,"",Sn_Color,R2S2_Style|styleNoRescale)

Plot (R3,"",Rn_Color,R3S3_Style|styleNoRescale)
Plot (S3,"",Sn_Color,R3S3_Style|styleNoRescale)
I tested the day pivot OK, i cannot test the week & month pivots.
Try and see whether it work for you



Lots of errors coming
 

amitrandive

Well-Known Member
#17
Lots of errors coming

Please read the entire thread again to get the context.


Code:
_SECTION_BEGIN ("Chart Setup");
SetChartBkColor(ParamColor("Outer panel",colorSkyblue));
SetChartBkGradientFill(
ParamColor("Upper Inner panel",colorLightBlue),
ParamColor("Lower Inner panel",colorLightYellow)); 

SetChartOptions(0,chartShowDates|chartShowArrows|chartLogarithmic|chartWrapTitle);

//basic price plotting
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorBlack ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() ); 
_SECTION_END ();

_SECTION_BEGIN ("Pivot Levels");

//--- Created by : KelvinHand -------
T_F =ParamList("TF Multiplier","Hour|Min|Day|Week|Month");
iInterval = Param("Interval", 1, 1);

Note1=ParamStr("-- Colors --", "PP, S1..S3, R1..R3");
PP_Color=ParamColor("PP Color",colorViolet);
Rn_Color=ParamColor("Rn Color",colorDarkRed);
Sn_Color=ParamColor("Sn Color",colorDarkGreen);
 
Note1=ParamStr("-- Styles --", "PP, R1S1, R2S2, R3S3");
PP_Style=ParamStyle("PP", styleDots|styleThick, maskAll);
R1S1_Style=ParamStyle("R1S1 Style", styleThick, maskAll);
R2S2_Style=ParamStyle("R2S2 Style", styleLine,  maskAll);
R3S3_Style=ParamStyle("R3S3 Style", styleDashed,maskAll);



_SECTION_END ();


shift=-1;

switch (T_F)
{
    case "Day":     iPeriod  = inDaily;        break;
    case "Hour":    iPeriod  = inHourly;    break;
    case "Min":        iPeriod  = in1Minute;    break;
}
     
  
     xTF = iInterval*iPeriod;
        H1 = TimeFrameGetPrice( "H", xTF, shift );
        L1 = TimeFrameGetPrice( "L", xTF, shift );
        C1 = TimeFrameGetPrice( "C", xTF, shift );

// To calculate the Pivot Levels 
      PP = (H1 + L1 + C1) / 3;

    R1 = (2 * PP) - L1 ;
    S1 = (2 * PP) - H1 ;
    R2 = PP - s1 + r1;
    S2 = PP - (r1 - s1) ;
    R3 = 2 * (PP - L1) + H1 ;
    S3 = L1 - (2 * (H1 - PP));

//    Plot Pivot Levels in the charts

//Plot (PP,"",PP_Color,PP_Style);

//Plot (R1,"",Rn_Color,R1S1_Style);
//Plot (S1,"",Sn_Color,R1S1_Style);

//Plot (R2,"",Rn_Color,R2S2_Style);
//Plot (S2,"",Sn_Color,R2S2_Style);

//Plot (R3,"",Rn_Color,R3S3_Style);
//Plot (S3,"",Sn_Color,R3S3_Style);

/*
BC = (High + Low)/2
TC = (Pivot - BC) + Pivot
*/

BC = (H1 + L1)/2;
TC = (PP - BC) + PP;
PlotOHLC(TC,BC,TC,BC,"",colorGrey50,styleNoLabel|styleCloud);


//    Add Pivot levels on charts as text
Title = Title + EncodeColor(colorDarkTeal)+
"\nPivot T_F = "+NumToStr(iInterval,1.0)+" "+T_F + "\n" +
EncodeColor(Rn_Color)+"R3 = "+ r3 +"\n"+
EncodeColor(Rn_Color)+"R2 = "+ r2 + "\n"+
EncodeColor(Rn_Color)+"R1 = "+ r1 + "\n"+ "\n"+
EncodeColor(PP_Color)+"PP = "+ PP + "\n"+ "\n" +
EncodeColor(Sn_Color)+"S1 = "+ s1 + "\n"+
EncodeColor(Sn_Color)+"S2 = "+ s2 + "\n"+
EncodeColor(Sn_Color)+"S3 = "+ s3 + "\n";

_SECTION_END ();  

x=PP[BarCount-1];
for(i=BarCount-2; i>0; i--)
    if (PP[i]!=x) 
    {
      i++;
      break;
    }  


for(j=0; j<i; j++)
{
pp[j]=Null;
R1[j]=Null;
S1[j]=Null;
R2[j]=Null;
S2[j]=Null;
R3[j]=Null;
S2[j]=Null;
}

//    Plot Pivot Levels in the charts
Plot (PP,"",PP_Color,PP_Style|styleNoRescale);

Plot (R1,"",Rn_Color,R1S1_Style|styleNoRescale);
Plot (S1,"",Sn_Color,R1S1_Style|styleNoRescale);

Plot (R2,"",Rn_Color,R2S2_Style|styleNoRescale);
Plot (S2,"",Sn_Color,R2S2_Style|styleNoRescale);

Plot (R3,"",Rn_Color,R3S3_Style|styleNoRescale);
Plot (S3,"",Sn_Color,R3S3_Style|styleNoRescale);
 

KelvinHand

Well-Known Member
#19
Modified to suit Post#12 platform by toocool


PHP:
_SECTION_BEGIN("Chart Setup");
//-- Author : KelvinHand
SetChartBkColor(ParamColor("Outer panel",colorGrey50));
SetChartBkGradientFill( 
ParamColor("Upper Inner panel",    colorBlack),
ParamColor("Lower Inner panel", colorBlack)
);

pStyle = ParamList("Price Style", "Candle|Solid Candle|Bar|Line|Heikin-Ashi|None");
cBull = ParamColor("Price Bull", colorLime);
CBear = ParamColor("Price Bear", colorRed);

cLine = ParamColor("Price Line", colorWhite);

SetChartOptions(0,chartShowDates|chartShowArrows|chartLogarithmic|chartWrapTitle);
_N(Title = StrFormat("{{NAME}}- {{INTERVAL}} {{DATE}} O= %g, H= %g, L= %g, C= %g (%.1f%%) V= " +WriteVal( V, 1.0 ) +"\n{{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));

ThisStyle = styleCandle;
ThisTitle = "";

_O=O; _C=C; _H=H; _L=L;
ThisColor = IIf( _C>_O, cBull, IIf(_C<_O, CBear, CLine));

switch (pStyle )
{

  case "Solid Candle":   
        SetBarFillColor( ThisColor ); 
        break;


  case "Bar": 
       ThisStyle = styleBar;
       break;

  case "Line": 
      ThisStyle = styleLine;
      ThisColor = cLine;
       break;


  case "Heikin-Ashi": 

            iPeriod=6;
            Om=MA(O,iPeriod);
            hm=MA(H,iPeriod);
            lm=MA(L,iPeriod);
            Cm=MA(C,iPeriod);
       _C = (Om+Hm+Lm+Cm)/4; 
          _O = AMA( Ref( _C, -1 ), 0.5 ); 
       _H = Max( Hm, Max( _C, _O ) ); 
       _L = Min( Lm, Min( _C, _O ) ); 

       ThisColor = IIf(_C >= _O,CBull, CBear);
       SetBarFillColor( ThisColor );
 
       ThisColor = IIf(_C >= _O,cLine, cLine);
          ThisTitle = "Heikin-Ashi";
       break;

  case "None":
       break;

  default:   
        SetBarFillColor( ThisColor ); 
        ThisColor = cLine;

       break;

}

  if (pStyle !="None")
  PlotOHLC( _O, _H, _L, _C, ThisTitle, ThisColor, ThisStyle); 
 
  GraphXSpace = 8;

_SECTION_END();

_SECTION_BEGIN ("Pivot Levels");

//--- Created by : KelvinHand -------
T_F =ParamList("TF Multiplier","Monthly|Weekly|Daily",2);

LevelPivot=ParamToggle("Pivot Point Levels", "No|Yes",1);
LevelS1R1=ParamToggle("Primary support and resistance levels (S1, R1)", "No|Yes",1);
LevelS2R2=ParamToggle("Secondary support and resistance levels (S1, R1)", "No|Yes",1);
CurPivot=ParamToggle("Display Pivot levels", "All Calulated|Most Recently Only");


Note1=ParamStr("-- Colors --", "PP, S1..S2, R1..R2");
PP_Color=ParamColor("PP Color",colorAqua);

R1_Color=ParamColor("R1 Color",colorLime);
S1_Color=ParamColor("S1 Color",colorRed);

R2_Color=ParamColor("R2 Color",colorGreen);
S2_Color=ParamColor("S2 Color",colorDarkRed);
 
Note1=ParamStr("-- Styles --", "PP, R1S1, R2S2");

xstyle = styleNoLabel|styleNoRescale;
PP_Style=ParamStyle("PP",             styleThick|xstyle, maskAll);
R1S1_Style=ParamStyle("R1S1 Style", xstyle, maskAll);
R2S2_Style=ParamStyle("R2S2 Style", xstyle,  maskAll);
//R3S3_Style=ParamStyle("R3S3 Style", xstyle,maskAll);

function WeekDay()
{
 dd = DayOfWeek();
  return (dd>0 and dd<6);

}

shift=-1;
switch (T_F)
{
    
    case "Weekly":    iPeriod  = inWeekly;       
                      ww=WeekDay();
                      dwm = ww != Ref(ww, -1);
                      break;
                      
    case "Monthly":   iPeriod  = inMonthly;        
                      dwm = Month() != Ref(Month(), -1);
                      break;
    default:           iPeriod  = inDaily;      
                      dwm = Day() != Ref(Day(), -1);    
                      break;
}
     
  
     xTF = iPeriod;
        H1 = TimeFrameGetPrice( "H", xTF, shift );
        L1 = TimeFrameGetPrice( "L", xTF, shift );
        C1 = TimeFrameGetPrice( "C", xTF, shift );

// To calculate the Pivot Levels 
  PP = (H1 + L1 + C1) / 3;
    R1 = (2 * PP) - L1 ;
    S1 = (2 * PP) - H1 ;
    R2 = PP - s1 + r1;
    S2 = PP - (r1 - s1) ;
 


PP =IIf(dwm, Null, PP);
R1= IIf(dwm, Null, R1);
R2= IIf(dwm, Null, R2);
S1= IIf(dwm, Null, S1);
S2= IIf(dwm, Null, S2);

if (CurPivot)
{
x=PP[BarCount-1];
for(i=BarCount-2; i>0; i--)
    if (PP[i]!=x) 
    {
      i++;
      break;
    }  


for(j=0; j<i; j++)
{
pp[j]=Null;
R1[j]=Null;
S1[j]=Null;
R2[j]=Null;
S2[j]=Null;
R3[j]=Null;
S2[j]=Null;
}



}


if (LevelPivot) 
{
  Plot (PP,"",PP_Color,PP_Style);
}
if (LevelS1R1)
{
Plot (R1,"",R1_Color,R1S1_Style);
Plot (S1,"",S1_Color,R1S1_Style);
}
if (LevelS2R2)
{
Plot (R2,"",R2_Color,R2S2_Style);
Plot (S2,"",S2_Color,R2S2_Style);
}

Title = Title + EncodeColor(colorWhite)+
EncodeColor(R2_Color)+"\n"+t_f+ "R2 = "+ r2 + 
EncodeColor(R1_Color)+"\n"+t_f+ "R1 = "+ r1 + 
EncodeColor(PP_Color)+"\n"+t_f+ "PP = "+ PP + 
EncodeColor(S1_Color)+"\n"+t_f+ "S1 = "+ s1 + 
EncodeColor(S2_Color)+"\n"+t_f+ "S2 = "+ s2 + "\n";

_SECTION_END ();
 
Last edited:

anjanbm

Active Member
#20
KelvinHand,
Please give afl code of dashed lines with different colors for different times frames for 60min pvt, 30min pvt and 15min pvt separate dashed lines when applied on 5min charts.
anjanbm
 

Similar threads