Plot using IIF(value > 0, value, Null) still scaling to min value of zero

I’ve used the IIF(value > 0, value, Null) trick many times to plot an array when the value is greater than zero. For some reason in this one particular chart it is still scaling the minimum value of the chart to zero even when the array contains all Null values.

Plot(IIf(value > 0, value, Null), "StopLoss", colorRed, styleDashed);

In fact, when I use this line it still scales the chart to a minimum value of zero:

Plot(Null, "AllNulls", colorRed, styleDashed);

When I comment out this line the scaling returns to normal. Under what circumstances can this happen? I’ve started a chart from scratch and added this same code snippet and it works properly - i.e., it doesn’t affect the scaling at all.

It works 100% correct.

Plot(IIf(value > 0, value, Null), "StopLoss", colorRed, styleDashed);

Uses zero scale because any value > 0 is actually plotted, so for example 0.00012312 is plotted as well, and AmiBroker engine ROUNDS Y scale to NICE round numbers, so it will use 0 instead of 0.0012312.

Plot(Null, "AllNulls", colorRed, styleDashed);

This uses zero because you passed “NOTHING”. If you passed NOTHING AmiBroker needs to pick some arbitrary Y value, which is 0.

You would see that AmiBroker works perfectly correct using THIS code:

value = Close;
Plot(IIf(value > 15, value, Null), "StopLoss", colorRed, styleDashed);

You will see that scale starts from 15 (if your close prices are in range below and above 15)

1 Like

OK, thanks for the reply. So is there a style I can use to tell it to ignore this plot for the purposes of determining the min and max visible values on the Y-Axis of the chart? It seems like styleNoRescale would do it but it doesn’t seem to change anything when I apply it.

Plot(Null, "AllNulls", colorAqua, styleNoRescale);

styleNoRescale does NOT change existing scale but you simply have to have AT LEAST ONE other Plot call that actually sets the scale to meaningful values.

As I explained in my previous reply, you simply have to have Y-axis scale and it has to have some min/max values. If you don’t have ANY plot with normal (not-null) values AmiBroker would use arbitrary scale that starts from zero.

Really having single Plot() statement with ALL NULLs and nothing else is pretty much pointless.

Correct way of using styleNoRescale is shown below:

// THIS sets the scale
Plot( Close, "Close", colorRed ); 
// THIS 2000 does NOT change the scale
Plot( 2000, "Two Thousand", colorBlue, styleNoRescale | styleNoLabel ); 

also if you used all NULL plot together with something ELSE that sets the scale you would see that all NULLs does NOT affect the scale:

// THIS sets the scale
Plot( Close, "Close", colorRed ); 
// All NULL does NOT change the scale
Plot( Null, "AllNull", colorBlue ); 
1 Like

Ah, yes, that was it. I had the main OHLC candles in a plot in a different _SECTION. When I moved that plot to the same section as the other plots it works as expected.

Thanks for your help as always, Tomasz.

For what it is worth the location in different section does not matter with regards to scaling. Sections matter for parameters, not for scaling. The only thing that matters is that you have to have at least one scale setting Plot() somewhere (preferably in front of others).