GraphXSpace - GraphXSpaceTop, GraphXSpaceBot Workaround - Guidance needed

Dear Friends,

For many years,I have wished for two supporting variables to the GraphXSpace variable in Graphs - GraphXSpaceTop, GraphXSpaceBot as I looked forward to plot some supporting indicators at the Bottom or Top area of the main chart while having PlotShapes in main plot. I thought that GraphXSpaceTop, GraphXSpaceBot would allow me to do it.

Today, It occurred to me that if I just rescaled the graph with the help of a StyleNoDraw call, then I could have the Extra Space at the top or Bottom as required. The Code I used is as follows:

if( ParamToggle( "Log Scale ?", "Yes|No", 0 ) == 0 )
	{
    SetChartOptions( 1, chartShowArrows | chartLogarithmic | chartWrapTitle );
    _log = 1;
    }
else
	{
    SetChartOptions( 1, chartShowArrows | chartWrapTitle );
    _log = 0;
    }


if( _log == 1 )
    Plot( LowestVisibleValue(L) - log((HighestVisibleValue(H) - LowestVisibleValue(L)) ), "OnlyReScale", colorBlack , styleLine|styleNoDraw, Null, Null, 0, 1  );// Just Setting Scale
else
    Plot( LowestVisibleValue(L) -  (HighestVisibleValue(H)-LowestVisibleValue(L)), "OnlyReScale", colorBlack , styleLine|styleNoDraw, Null, Null, 0, 1  );// Just Setting Scale

Plot( Close, "Close", colorYellow , 128, Null, Null, 0, 1  );

this code performs as desired in Linear scale, however in Log Scale the result is not as expected. Will appreciate it very much if experienced friends guide me how to manage it in Log Scale.

Secondly, I am thinking, if this approach is going to be robust: In case the HighestVisibleValue(H) is 80
and LowestVisibleValue(L) is 15, then
LowestVisibleValue(L) - (HighestVisibleValue(H)-LowestVisibleValue(L))
will become -50 (a negative value) - it might be inappropriate to try to plot a Negative Value in Log Scale.

Should I leave this wish to find a workaround for GraphXSpaceTop, GraphXSpaceBot and wait for robust solution from Mr. TJ.

(Noticed sometime after posting the initial querry - Unexpected Observation - I am not getting Errors in Graphs - and Chart is rescaling to negative values also

Sorry - This rescaling is happening in Linear scale, Could not even get basic solution working in Log Scale)

With Regards

Sanjiv Bansal

Math 101: Logarithm from NEGATIVE number (or zero) does not exist.

1 Like

@Sumangalam in this thread I discussed an alternative way to draw more graphs in the same pane (withoutthe logarithmic scale only).

@Tomasz Thank you very much for your guidance.
I find that my objective will be equally well served if the Extra Space is at the Top - in this case no possibility of Negative Values. So, I made a small change to my original code to have Space at the top:

if( ParamToggle( "Log Scale ?", "Yes|No", 0 ) == 0 )
	{
    SetChartOptions( 1, chartShowArrows | chartLogarithmic | chartWrapTitle );
    _log = 1;
    }
else
	{
    SetChartOptions( 1, chartShowArrows | chartWrapTitle );
    _log = 0;
    }


if( _log == 1 )
    Plot( HighestVisibleValue(H) + log((HighestVisibleValue(H) - LowestVisibleValue(L)) ), "OnlyReScale", colorBlack , styleLine|styleNoDraw, Null, Null, 0, 1  );// Just Setting Scale
else
    Plot( HighestVisibleValue(H) +  (HighestVisibleValue(H)-LowestVisibleValue(L)), "OnlyReScale", colorBlack , styleLine|styleNoDraw, Null, Null, 0, 1  );// Just Setting Scale


    Plot( Close, "Close", colorYellow , 128, Null, Null, 0, 1  );
    

Will look forward to guidance about how to manage Log Scaling in this case.

@beppe Thank you very much for your guidance, A nice and useful piece of code. Things remain stable in Log Scale also. However, I find that the Y Axis Scale Values continue to remain fixed in your code - I am not sure how it will behave when code for PlotShapes is added to the code. In the approach I just stumbled upon today, PLOTSHAPES in main plot are handled with no more effort (Yes, I find that members like you and @fxshrat are lot more systematic - I just stumbled upon an approach that seems to be working for me). I only have to extra manage the things plotted in the Extra Space at top only.

Thank you very much again for your time. Will be looking forward to guidance about the value that will appropriately rescale the chart in LogScale.

With Regards

Sanjiv Bansal

Hello Friends,

After a bit of working on the code, I could get what I was looking for. The Basic Working code is:

REL_INDEX = ParamStr("RS base ticker","NIFTY");

SetForeign( REL_INDEX , 1, False );

if( ParamToggle( "Log Scale ?", "Yes|No", 0 ) == 0 )
	{
    SetChartOptions( 1, chartShowArrows | chartLogarithmic | chartWrapTitle );
    Plot( exp( log (HighestVisibleValue(H)) + (log(HighestVisibleValue(H)) - log(LowestVisibleValue(L)) )), "OnlyReScale", colorBlack , styleLine|styleNoDraw, Null, Null, 0, -1  );// Just Setting Scale
	Plot( HighestVisibleValue(H) * 1.01, "OnlyReScale", colorGrey40 , styleLine| styleNoLabel | styleNoTitle, Null, Null, 0, -1  );
    }
else
	{
    SetChartOptions( 1, chartShowArrows | chartWrapTitle );
    Plot( HighestVisibleValue(H) + (HighestVisibleValue(H)-LowestVisibleValue(L)), "OnlyReScale", colorBlack , styleLine|styleNoDraw, Null, Null, 0, -1  );// Just Setting Scale
	Plot( HighestVisibleValue(H) * 1.01 , "OnlyReScale", colorGrey40 , styleLine| styleNoLabel | styleNoTitle, Null, Null, 0, -1  );
    }


_N( Title = Name() + StrFormat( " {{DATE}} O %g, H %g, L %g (%.1f%%) Vol " + WriteVal( V, 1.0 ) + " {{VALUES}}", O, H, L, SelectedValue( ROC( C, 1 ) ) ) );

Plot( Close, "Close", colorYellow , 128, Null, Null, 0, 1  );

DATAi = C; // Inside SetForeign

RestorePriceArrays();

_RSV = Close / DATAi;

Max_Scale = HighestVisibleValue(_RSV)  ;
Min_Scale = ( LowestVisibleValue(_RSV)-(HighestVisibleValue(_RSV)-LowestVisibleValue(_RSV)) ) * 1.1;

Plot( IIf( _RSV > 0, Prec( _RSV, 3 ), Null ) , "RSV", ColorRGB( 0, 255, 255 ), styleNoTitle | styleOwnScale,Min_Scale,HighestVisibleValue(_RSV) ); 

This is a Basic implementation of the concept - where I have tried to have two Legacy AFLs in one AFL [Price (foreign) and RS - Comparative Relative Strength]. The convenience that I get is that since there is one AFL, there is one Param. Real benefit is achieved in those instances when lot of similar calculations are done in two AFLs for two Plots. In those cases two AFLs can be merged in one AFL. I understand the Persistent StaticVars can also help for that objective, however, I found the approach of One AFL more convenient for my purpose.

There are two problems that I am still facing in this approach:

  1. I could not align the Y Axis Labels of "StyleOwnScale" with their plots - A few years ago @Tomasz had guided that there are some practical reasons for that - I should be happy with the reality. A workaround could be to use "StyleNoLabel" and then manually mark Y Axis label at its visually appropriate location with GFX functions - however, I am not yet much proficient with GFX functions.
  2. I could not plot the "StyleOwnScale" plots in Log Scale - There should be reasons for that also - Now that "StyleOwnScale" feature is there - Users like me keep desiring for more and more.

In the end I am still continuing with my two separate AFLs for two plots at the moment - Still it was a nice experience. Mr. Tomasz thank you again for the nice software.

With Regards

Sanjiv Bansal