Corrected: Using Plot() or PlotOHLC() causes chart vertical scaling to change

Hello,

[I could not delete the previous post. I wanted to use a better chart example]

I'lm using PlotOHLC() to plot horizontal zones on a chart. I notice that if the plotted approaches about 33% of either the bottom or top edge of the chart, it causes the entire chart to be be rescaled, such that the chart is compressed. This leaves an empty band at the top or bottom of the chart, where no price information is displayed.

I tried using the styleNoRescale option to the PlotOHLC(), but this cased the chart to be displayed referenced to the 0-line. I also tested using Plot(), with no difference.

What is also strange is thatthe PlotOHLC() at the bottom of the chart do not cause the chart to be rescaled.

Is there a way to stop this behaviour?

Thanks,
Polomora

My simplified code is

zoneListStr = GetTradingZones();
for( j = 0; ( zoneStr = StrExtract( zoneListStr, j ) ) != ""; j++ )
{
  zoneBottom = StrToNum(StrExtract(zoneStr,0));
  zoneTop = StrToNum(StrExtract(zoneStr,1));
  PlotOHLC(zoneTop, zoneTop, zoneBottom, zoneTop, "", colorDarkBlue, styleCloud);
}

This chart shows the scaling effect:
image

This is the same chart, with the upper two PlotOHLC() removed:
image

@polomora - first of all you shouldn't use Plot() in this case. Here is why:

I also don't see any effect of this line on your upper screenshots:

PlotOHLC(zoneTop, zoneTop, zoneBottom, zoneTop, "", colorDarkBlue, styleCloud);

On the contrary, they were visible on the screenshots from your prior thread (the one you want to delete):

obraz

If you want to draw such blue areas, you can use:

  1. GfxSetCoordsMode(1) :

bar / price mode where X is expressed in bar index and Y is expressed in price. This new mode allows way easier overlays on top of existing charts without need to do conversion between bars/price pixels and without any extra refresh normally required in old versions when Y scale changed.

... and:

  1. GfxFillSolidRect( x1, y1, x2, y2, color )

For instance:

// ---  Outside the loop
bi = BarIndex();
x1 = FirstVisibleValue(bi);
x2 = LastVisibleValue(bi);
// -- Inside the loop
GfxFillSolidRect(x1, zoneTop, x2, zoneBottom, colorDarkBlue);

Upper code was not tested because you have provided only a small part (not working as it is) of your whole solution.

If you use Gfx functions, you won't have any problems with scaling of the price.

Next time you might also use static variables or matrices instead of strings for storing different support/resistance levels.

https://www.amibroker.com/guide/afl/gfxsetcoordsmode.html
https://www.amibroker.com/guide/afl/gfxfillsolidrect.html

2 Likes

... to be precise - you shouldn't use PlotOHLC() in this case.

And I forgot about this line in the code:

GfxSetCoordsMode(1);

Thanks @Milosz for the detailed explanation.

The low-level graphics functions solved the problem.
I always have a browser tab open referring to the AFL reference page, when using the AFL functions.
The tip you mentioned, concerning the use of either Plot or the GFX function, was very good.
It would be useful to have these tips in the AFL reference pages.

For what it worth there is styleNoRescale that can be used to make sure that added Plot does not change existing scale.

3 Likes

Thanks @Tomasz,

I had tried that, without really understanding its purpose. Didn't make a difference in my case.
Have used the GFX functions instead, thanks to @Milosz

1 Like

You are simply using it wrong. When using styleNoRescale there must be at least ONE Plot() that is NOT using styleNoRescale. At least one 'regular' Plot() is needed to set the scale properly. And it should be first plot call.

4 Likes

Excellent, that was the problem. The scaling for all plots if completely wrong if the first one is with the styleNoRescale option.