Scripting study to start at specified time


Category:
0
0

Would it be possible to script an indicator to start at a specified time?  For instance, the bollinger bands carry the effect of prior expansion, and lag to show a full squeeze as it forms.  But is it possible to add options to the code to force it to start  at an arbitrary point, such as the open of the market, without carrying the prior day’s activity.  This would be like the market profile that starts at the open, not reflecting the prior days influence.  Thanks!

 

input price = close;
input displace = 0;
input length = 20;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
input averageType = AverageType.Simple;

def sDev = stdev(data = price[-displace], length = length);

plot MidLine = MovingAverage(averageType, data = price[-displace], length = length);
plot LowerBand = MidLine + num_Dev_Dn * sDev;
plot UpperBand = MidLine + num_Dev_Up * sDev;

LowerBand.SetDefaultColor(GetColor(0));
MidLine.SetDefaultColor(GetColor(1));
UpperBand.SetDefaultColor(GetColor(5));

Marked as spam
Posted by (Questions: 1, Answers: 0)
Asked on July 9, 2021 8:15 am
90 views
0
Private answer

What you are asking for would actually make the indicator nearly useless. Notice the default length is 20. When using the default length and simple moving average it would take 20 bars AFTER that arbitrary point in time before the moving average can be computed.

When the chart is set to a 15 minute time frame and the start point is the market open the indicator would only be able to plot on the last 6 candles of the trading session.

If you move down to the 5 min time frame while using the same start point the indicator would not plot for the first 25% of the trading session.

For an indicator of this type, any time frame less than 5 min is totally useless. Nothing but noise down there and very little signal.

FYI, you can do this without modifications on the TradeStation platform. Set the chart to display only the current trading session and add the indicator to the chart. TradeStation does not use "prefetch" so each plot (using your example) must wait until 20 candles have been added to the current trading session before the indicator would begin to plot.

The reason this does not work on Thinkorswim is because this platform uses "prefetch". Don't have a clue what "prefetch" means? Check the following article form our Kitchen Sink:

https://www.hahn-tech.com/moving-averages-exponential-problems/

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on July 9, 2021 10:02 am