Changing/Overwriting an already plotted/calculated plot  [SOLVED]

Questions about MultiCharts and user contributed studies.
kajkanjan
Posts: 33
Joined: 12 Feb 2012
Has thanked: 4 times
Been thanked: 1 time

Changing/Overwriting an already plotted/calculated plot

Postby kajkanjan » 12 Mar 2013

Hi All,

Hoping this is simple: How do I go back and change the historical value of a plot ?

I have a trailing stop that will change depending on what happens the 'following day' after an event has been triggered. Sometimes this causes a zig zag plot as it re calculates
Yes, it is all in hindsight, but for pure visual aesthetic purposes when looking backwards I want to override the zig zaging and manually change the value.

I want to basically overwrite the calculated plot with another value when an event is triggered.

But because the plot has already been calculated on that day (which is fine) that is the value it sticks at. I don't know how to tell MultiCharts to go back, say, as at 2 days ago, and change the plot value, overriding what it had calculated.

The calculations won't make a loop error (I don't think) ... I just want to go back and change the value of a plot as of a certain day to a certain value.

Is this at all possible?

Thanks for your time and help!

If it helps, here is the exact code with notes I have put together. If you plot this on a chart and look especially at times when a stop even occurs and the price trades sideways, you get this zig-zag effect.

Code: Select all

inputs:
Price( Close ),
ATRLength( 14 ),
Multiplier ( 2 );

variables:
ATRvalue(0),
ATR_StopValue(0),
TriggerVar(0);

{Calculate the ATR of the stock times the multipler and minus that
from the price to give the ATR stop level as of a certain day}
ATRvalue = Price - (AvgTrueRange( ATRLength )* Multiplier );

{if the current ATR Stop value is higher than the previous ATR Stop value,
then move the previous ATR stop value up to the current ATR stop value.
Basically this creates a trailing stop. the ATR stop moves higher, never lower}
if ATRvalue > ATR_StopValue then
ATR_StopValue = ATRvalue;

{if the price drops below the current ATR stop value then trigger a stop event
and reset the current ATR stop value down to the actual ATR Stop calculation}
if price < ATR_StopValue then
begin
ATR_StopValue = ATRvalue ;
TriggerVar = 1;
end;

{If there has been a trigger event i.e. the price on the last bar fell below the ATR stop value
then check if todays close/last price is above or below the last bars close
If the close is below the last bars close, then continue on and calulate the ATR stop as needed untill an uptrend resumes again
If however the price is HIGHGER the next day after a stop event, then i want to INGORE the stop that happened the previous day
and set the stop value to what it was the day before the stop value got triggered
***** Here is where i would like to then over write yesterdays caluclated stop value with the value of the stop 2 days ago}
if TriggerVar = 1 then
if close > close of 1 day ago then
begin
ATR_StopValue = ATR_StopValue of 2 days ago;
TriggerVar = 0;
end;

Plot1 (ATRvalue, "ATR Value"); {I normally hide this plot. There just to see what is happening if needed}
plot2 (ATR_StopValue, "MAIN ATR Stop"); {The main plot to show}
plot3 (ATR_StopValue of 1 days ago, "ATR Stop 1 day ago"); {I normally hide this plot. There just to see what is happening if needed}

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Changing/Overwriting an already plotted/calculated plot  [SOLVED]

Postby TJ » 12 Mar 2013

Hi All,

Hoping this is simple: How do I go back and change the historical value of a plot ?

I have a trailing stop that will change depending on what happens the 'following day' after an event has been triggered. Sometimes this causes a zig zag plot as it re calculates
Yes, it is all in hindsight, but for pure visual aesthetic purposes when looking backwards I want to override the zig zaging and manually change the value.

I want to basically overwrite the calculated plot with another value when an event is triggered.

But because the plot has already been calculated on that day (which is fine) that is the value it sticks at. I don't know how to tell MultiCharts to go back, say, as at 2 days ago, and change the plot value, overriding what it had calculated.

The calculations won't make a loop error (I don't think) ... I just want to go back and change the value of a plot as of a certain day to a certain value.

Is this at all possible?

Thanks for your time and help!

If it helps, here is the exact code with notes I have put together. If you plot this on a chart and look especially at times when a stop even occurs and the price trades sideways, you get this zig-zag effect.
You can change any past plots with [1] bar reference.

The following code means to change the plot #1 ONE bar ago to the value of 100.

Code: Select all

PLOT1[1](100);

kajkanjan
Posts: 33
Joined: 12 Feb 2012
Has thanked: 4 times
Been thanked: 1 time

Re: Changing/Overwriting an already plotted/calculated plot

Postby kajkanjan » 12 Mar 2013

You my friend are a genius!

That was such an easy solution!!! (makes me kinda embarrassed) .... but to us lesser mortals, it was no less brilliant a solution.

thanks!

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Changing/Overwriting an already plotted/calculated plot

Postby TJ » 12 Mar 2013

You my friend are a genius!

That was such an easy solution!!! (makes me kinda embarrassed) .... but to us lesser mortals, it was no less brilliant a solution.

thanks!
You are welcome. Enjoy!

kajkanjan
Posts: 33
Joined: 12 Feb 2012
Has thanked: 4 times
Been thanked: 1 time

Re: Changing/Overwriting an already plotted/calculated plot

Postby kajkanjan » 14 Mar 2013

Just a follow up question:

Changing the plot as you showed with e.g. Plot[1] (100) ... that only changes the value visually on the chart, doesn't it?

I am also showing the values of the above code/plots in a Watch-list screen.
It seems though the Watch-list value of the Plot is showing the value as originally calculated, whereas the plot on the chart is showing/changing with the overwrite i put in place.

The chart plot value is showing correct, the watch-list plot is not. It seems to be ignoring the new plot change code.

Is there a way to get the watch-list synced with the chart plot data?
Or do I need to fundamentally restructure the way I do the code and possibly create a new plot for the watch-list?
I think I know how I can re-do the code, but the preferable (lazy) option I hope is that I don't need to!

Thanks again! :)

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: Changing/Overwriting an already plotted/calculated plot

Postby TJ » 14 Mar 2013

Just a follow up question:
Changing the plot as you showed with e.g. Plot[1] (100) ... that only changes the value visually on the chart, doesn't it?
Correct.
I am also showing the values of the above code/plots in a Watch-list screen.
It seems though the Watch-list value of the Plot is showing the value as originally calculated, whereas the plot on the chart is showing/changing with the overwrite i put in place.
The chart plot value is showing correct, the watch-list plot is not. It seems to be ignoring the new plot change code.
Is there a way to get the watch-list synced with the chart plot data?
Or do I need to fundamentally restructure the way I do the code and possibly create a new plot for the watch-list?
I think I know how I can re-do the code, but the preferable (lazy) option I hope is that I don't need to!
Thanks again! :)
You cannot retroactively change the past value of a variable.
You have to create a new variable if you want to have a new value.


Return to “MultiCharts”