expand scale to analysis techniques

Questions about MultiCharts and user contributed studies.
kh_model
Posts: 43
Joined: 13 Jul 2005
Has thanked: 12 times

expand scale to analysis techniques

Postby kh_model » 05 Apr 2021

I have written a test indicator which plots 1 line on a chart at a user-specified offset above price. I have written another indicator which plots 1 line on a chart at a user-specified offset below price. Both indicators are intended to be applied to the same chart and the same data series at the same time in order to expand the vertical chart scale via powerlanguage. When "Format Instrument > Scaling > Expand Scale to Include Indicators" is checked for the data series to which both indicators have been assigned, it is expected that the chart scale will be automatically adjusted by MultiCharts in such a way that both plots become visible within the vertical space of the chart window. Please note that if the initial chart scale is already large enough to contain the two plotted lines then there may not be any significant change in chart scale. Also please note that the indicators plot into the future by the amount specified by the user input called "RightShift". For example, if "RightShift" is 50, then a chart needs to have "Format Window > X-Time Scale > Chart Shift" set to at least 50 bars in order to establish enough future bars to prevent an error. If that happens, MultiCharts will status the indicators off and display a message. If the user wishes to include other indicators on the same chart, it might be desireable to assign the two indicators which control chart scale only to a second data series. On the first data series, one may wish to uncheck "Format Instrument > Scaling > Expand Scale to Include Indicators" so that the plots of other indicators which are assigned to the first data series will not influence the scale of the chart.

In the first two attached screenshots, I have demonstrated the automatic expansion of chart scale with specific settings using the two indicators described above. I have varied the user-input called "offset_price" from 100, to 200, and finally to 400 across three copies of the same chart.

I modified original code which I thought was called "Last Price Line Arnie" but now I cannot locate the original thread. I want to express my thanks to the original authors.


Image

Image




1210405a_scale_00.jpg
(358.23 KiB) Not downloaded yet
1210405a_scale_01.jpg
(350.04 KiB) Not downloaded yet
scaling_line_hi_a.pla
(7.27 KiB) Downloaded 74 times
scaling_line_lo_a.pla
(7.25 KiB) Downloaded 68 times
ES-def-m0045_001a_gs_viz_a.wsp
(119.19 KiB) Downloaded 70 times


Here is the code for "scaling_line_hi_a":

Code: Select all

inputs: Color(rgb(255,255,255)), RightShift(50), offset_price(100) ; variables: firstBar(0), lastPrice(0) ; //+++++++++++++++++++++ //+++++++++++++++++++++ //+++++++++++++++++++++ ///////////////////////////////////////////////////////////////////////////////////////////////////// // // start: Scaling_Line_high // ///////////////////////////////////////////////////////////////////////////////////////////////////// if currentbar = 1 then firstBar = currentbar; lastPrice = high + offset_price; for value1 = 0 to (currentbar - firstBar) begin plot1[value1](lastPrice,"vizHi", Color); end; for value1 = 0 to RightShift begin Plot1[-value1](lastPrice, "vizHi", Color); end; noplot(1); ///////////////////////////////////////////////////////////////////////////////////////////////////// // // end: Scaling_Line_high // /////////////////////////////////////////////////////////////////////////////////////////////////////




Here is the code for "scaling_line_lo_a":

Code: Select all

inputs: Color(rgb(255,255,255)), RightShift(50), offset_price(100) ; variables: firstBar(0), lastPrice(0) ; //+++++++++++++++++++++ //+++++++++++++++++++++ //+++++++++++++++++++++ ///////////////////////////////////////////////////////////////////////////////////////////////////// // // start: Scaling_Line_low // ///////////////////////////////////////////////////////////////////////////////////////////////////// if currentbar = 1 then firstBar = currentbar; lastPrice = low - offset_price; for value1 = 0 to (currentbar - firstBar) begin plot1[value1](lastPrice,"vizLo", Color); end; for value1 = 0 to RightShift begin Plot1[-value1](lastPrice, "vizLo", Color); end; noplot(1); ///////////////////////////////////////////////////////////////////////////////////////////////////// // // end: Scaling_Line_low // /////////////////////////////////////////////////////////////////////////////////////////////////////

kh_model
Posts: 43
Joined: 13 Jul 2005
Has thanked: 12 times

Re: expand scale to analysis techniques

Postby kh_model » 05 Apr 2021

I have so far not been able to reproduce the results shown above with a single indicator. It seemed logical to me that only one indicator should be needed which contains two plots, instead of two indicators which each contain one plot. Here is the code which does not seem to work as expected. I hope that someone can suggest a way to modify the code to produce a working result.

As in my first example, I have varied the user input called "offset_price" from 100, to 200, and finally to 400 but there seems to be no effect after the initial chart is loaded.

Code: Select all

inputs: Color(rgb(255,255,255)), RightShift(50), offset_price(100) ; variables: firstBar(0), lastPrice(0) ; //+++++++++++++++++++++ //+++++++++++++++++++++ //+++++++++++++++++++++ ///////////////////////////////////////////////////////////////////////////////////////////////////// // // start: Scaling_Line_high // ///////////////////////////////////////////////////////////////////////////////////////////////////// if currentbar = 1 then firstBar = currentbar; lastPrice = high + offset_price; for value1 = 0 to (currentbar - firstBar) begin plot1[value1](lastPrice,"vizHi", Color); end; for value1 = 0 to RightShift begin Plot1[-value1](lastPrice, "vizHi", Color); end; noplot(1); ///////////////////////////////////////////////////////////////////////////////////////////////////// // // end: Scaling_Line_high // ///////////////////////////////////////////////////////////////////////////////////////////////////// //+++++++++++++++++++++ //+++++++++++++++++++++ //+++++++++++++++++++++ ///////////////////////////////////////////////////////////////////////////////////////////////////// // // start: Scaling_Line_low // ///////////////////////////////////////////////////////////////////////////////////////////////////// if currentbar = 1 then firstBar = currentbar; lastPrice = low - offset_price; for value1 = 0 to (currentbar - firstBar) begin plot2[value1](lastPrice,"vizLo", Color); end; for value1 = 0 to RightShift begin Plot2[-value1](lastPrice, "vizLo", Color); end; noplot(1); ///////////////////////////////////////////////////////////////////////////////////////////////////// // // end: Scaling_Line_low // /////////////////////////////////////////////////////////////////////////////////////////////////////
scaling_lines_hi_lo_a.pla
(9.62 KiB) Downloaded 70 times
ES-def-m0045_002a_gs_viz_a.wsp
(115.99 KiB) Downloaded 70 times
1210405a_scale_02.jpg
(316.89 KiB) Not downloaded yet

Image

kh_model
Posts: 43
Joined: 13 Jul 2005
Has thanked: 12 times

Re: expand scale to analysis techniques

Postby kh_model » 06 Apr 2021

I forgot to mention in my previous post that all of my tests were conducted in MultiCharts version 8.8. I apologize in advance in case there is a documented bug or bugfix which I have not yet learned about. In case someone discovers that my second example works in a newer version of MultiCharts please feel free to report back here. If I am not mistaken, certain newer versions of MultiCharts do not allow invisible plots to influence chart scale so I have kept the plots visible.

kh_model
Posts: 43
Joined: 13 Jul 2005
Has thanked: 12 times

Re: expand scale to analysis techniques

Postby kh_model » 07 Apr 2021

After further testing with MultiCharts 8.8, I have noticed that the previously posted indicator called "scaling_lines_hi_lo_a.pla" which combines two plots within a single indicator works properly under certain conditions. I have observed that when "Format Instrument > Scaling > Scaling Range" is set to "Screen", then the chart scale responds as expected to changes in the user-input called "offset_price". It may be desirable to uncheck "Use Margins". In my previously described tests which did not work properly, it seems that the cause for the problem was that "Format Instrument > Scaling > Scaling Range" was set to "Movement Size"

In the case of using two indicators which each plot a single line on the chart, one may notice the seemingly wrong behavior of allowing an extra "margin" to exist above and below the plotted lines which seems to occur only when "Format Instrument > Scaling > Scaling Range" is set to "Movement Size". The seemingly "wrong" behavior has an advantage as follows: a window resize event which normally is hard to detect in PowerLanguage might be detectable by checking the value of "GetAppInfo(aiHighestDispValue) - GetAppInfo(aiLowestDispValue)" for changes, until an optimal value is reached.


Return to “MultiCharts”