Conditional PLOT

Hi,
I haveCode button (use to enter/paste AFL formula) attached an AFL of Classic Pivot.
I want to plot R2/R3 levels only if Today’s high crossed above R1,Else those lines should not be plotted.
Likewise i want to plot S2/S3 lines only if today’s Low crossed below S1,Else those lines should not be plotted.
I am looking for help to modify the Plot lines in the Attached AFL.
Thanks and Regards,
Gloria Filamino

_SECTION_BEGIN ("Chart Setup");
SetChartBkColor(ParamColor("Outer panel",colorBlack));
SetChartBkGradientFill(
ParamColor("Upper Inner panel",colorBlack),
ParamColor("Lower Inner panel",colorBlack)); 

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

xH=BarsSince(Day()!=Ref(Day(),-1));
yH=HHV(H,xH+1);
Hightoday=IIf(xH==0,yH,Ref(yH,0));

xL=BarsSince(Day()!=Ref(Day(),-1));
yL=LLV(L,xL+1);
LowTODAY=IIf(xL==0,yL,Ref(yL,0));

//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","Day|Min|Hour|Week|Month");
iInterval = Param("Interval", 1, 1);

Note1=ParamStr("-- Colors --", "PP, S1..S3, R1..R3");
PP_Color=ParamColor("PP Color",coloryellow);
Rn_Color=ParamColor("Rn Color",colorRed);
Sn_Color=ParamColor("Sn Color",colorbrightGreen);
 
Note1=ParamStr("-- Styles --", "PP, R1S1, R2S2, R3S3");
PP_Style=ParamStyle("PP", styleLine,  maskAll);
R1S1_Style=ParamStyle("R1S1 Style", styleLine,  maskAll);
R2S2_Style=ParamStyle("R2S2 Style", styleLine,  maskAll);
R3S3_Style=ParamStyle("R3S3 Style", styleLine,  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);

//    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 ();

Hello @Gloriafilamino
Let me ask you why you don’t like to plot the r2, r3. Is this because the candlestick on your chart are shrink?

Yes,Absolutely Correct,Also sometimes too many lines lead to misconception.

Thanks and regards,

Gloria Filamino

Hi @Gloriafilamino
Ok then, in that case Amibroker can handle easily your problem
http://www.amibroker.com/guide/afl/plot.html
Plot function has so many parameters that you can choose.
Read about plot because we are using a lot and you really need to know how to.
concentrate about the «style»

for this afl now. What you need is styleNoRescale.
You have two choice, to open parameters window and in the to click ON styleNoRescale
Or you can chance that 3 line in that code

R1S1_Style=ParamStyle("R1S1 Style", styleLine|styleNoRescale,  maskAll);
R2S2_Style=ParamStyle("R2S2 Style", styleLine|styleNoRescale ,  maskAll);
R3S3_Style=ParamStyle("R3S3 Style", styleLine|styleNoRescale ,  maskAll);

P.S do you mine if i change the subject to “How to fix shrinking Candlesticks” instead “Conditional PLOT” for other users benefit?

1 Like

Thanks for Reply,
But i wanted to know how PLOT can be used with given conditions.
Thats why i titlted it that way,
Because i could not find the examples in Google too.

Thanks
Gloria Filamino

1 Like

there are so many ways to do that
I dont know what you like to achieve? Here is one example using IIF()

Cont1= IIf(C>pp AND C<R1, pp ,Null);
Plot (Cont1,"",PP_Color,PP_Style);
1 Like

@Gloriafilamino

Plot_Null

2 Likes

Check here,.. may be useful ..same like PanoS indicated

2 Likes

Thanks a Lot Pano.
Heartfelt Thanks.

Gloria Filamino.

Thanks a Lot Amsai.

Gloria Filamino