Conditional Plot() something or nothing

Hi,

probably something simple but cant get it to work ...
conditions been my biggest struggle in afl
any help appreciated

thanks

Plot( Close, "Price", colorWhite, styleCandle );
Hi_D = TimeFrameGetPrice( "H", inDaily, -1 ); Lo_D = TimeFrameGetPrice( "L", inDaily, -1
x= BarCount -1 ;

// if C > Hi_D do this and nothing else
{
Plot(Hi_D,"",colorGreen,styleDashed|styleNoRescale | styleNoLabel,null,null,0,0,2);
GfxTextOut("ENTER", X+10 , ENTERA );
}

// if C < Lo_D do this and nothing else

{
ENTER = LO_D;
Plot(Lo_D,"",colorRed,styleDashed|styleNoRescale | styleNoLabel,null,null,0,0,2);
GfxTextOut("ENTER", X+10 , ENTERA );
}

As I wrote already many times, bar-by-bar conditional Plot() is not done by not calling Plot() but by passing NULL in places when you don't want plot

So

Plot( IIF( C < Lo_D, Lo_D, Null ), "Title", colorRed );

This is so because you generally WANT to PLOT() but only skip some bars.

Last but not least:

When posting the formula, please make sure that you use Code Tags (using </> code button) as explained here: How to use this site.

Using code button

Code tags are required so formulas can be properly displayed and copied without errors.

Ok thanks
But how do you handle other conditions ? Do they have to be approached the same way?
ie

GfxTextOut("ENTER", X+10 , ENTERA );
need to set the pen to null or text to null somehow?

color = LastValue( IIF( C < Lo_D, colorwhite, null ) );
GfxSelectPen( color ) ;

You need to read this:
http://www.amibroker.com/guide/h_understandafl.html
and
http://www.amibroker.com/guide/a_mistakes.html

It is fundamental to understand the difference between array and scalar value and differences between if-else and IIF IIf function versus if statement
These subjects were addressed dozens of times on the forum and in the manual. Please read.

Ok,

l'm still confused is there an example of a simple way that a condition can call a function or a procedure or you can just set a path to follow under certain circumstances?

IIF( C < Lo_D, Lo_D, ProcedureA,ProcedureB);

or

If (C<Lo_D)
ProcedureA
EndIf

I know those do not work but what does?

Neither.

As explained in documents I pointed out you need a SCALAR VALUE (single number) to use if-else. Neither C or Lo_D are scalar values. These are arrays (multiple values, separate value for each bar). To use if-else you need a value for single bar. Such as Close[ 0 ] - that is the close for very first bar.
Did you read the documents carefully? I mean really carefully. I guess not. You responded in 15 minutes. That is not enough time to read the documents I pointed out.

You really need to read and understand. Posting copy-paste code is useless as it does not make you understand.

There are plenty of examples in the Knowledge Base including

that show how to write text conditionally on chart

So GFX is not a good option but it seems more manageable with plottext.
I'll play around with the plottext as for now I get print on both sides since GFX cant be called under a condition.
thanks for the help

This was the code by passing the Null to the color where I didn't need text, instead of using GFX.
It's simple enter signal , that plots a line with the "Enter" on far right. Additional stops , targets can be added using similar code. Still needs some cleanup but the idea is coming together. Its for intra-day trades with a simple momentum daily signal.

// Short Enter
Lo_D = TimeFrameGetPrice( "L", inDaily, -1 );
x= BarCount -1 ;shift =10; width =5;
color = LastValue( IIF( C < Lo_D, colorwhite, colorBlack ) );
bkcolor = LastValue( IIF( C < Lo_D, colorred, colorblack ) );
ENTER = LO_D; ENTERA= LastValue(ENTER); ENTERB= LineArray( x-shift, ENTERA, x-width, ENTERA);
Plot(IIF( C < lo_D, ENTERB, Null ),"",colorRed,styleDashed|styleNoRescale | styleNoLabel,null,null,10,0,2);
PlotText( "ENTER" ,x+10, enterA, color, bkcolor, yoffset = 0 );

@ak47, did you not see this!

Thanks, out of time can't edit it so it stays lol

You could always delete it and re-post it properly!

3 Likes

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.