Stochastic on two timeframes


Category:
0
0

Hello.  I am trying to implement a two timeframe stochastic on a one minute chart on ToS by adapting some code I found online.  The 1 min stochastic is fine, but the 10 min is plotted like a step function.  I assume because its calculating and plotting on every bar instead of on every tenth bar.  Not sure how to fix this.  Any ideas?

Here is the relevant code:

<pre>

def ml = (over_bought + over_sold)/2;

# TF1
def T1L = low(period = Period1);
def T1H = high(period = Period1);
def T1C = close(period = Period1);

def TF1_lowest_k = Lowest(T1L, KPeriod1);
def TF1_c1 = T1C – TF1_lowest_k;
def TF1_c2 = Highest(T1H, KPeriod1) – TF1_lowest_k;
def TF1_FastK = if TF1_c2 != 0 then TF1_c1 / TF1_c2 * 100 else 0;

plot TF1_FullK =
if HideK1 then double.nan
else MovingAverage(averageType1, TF1_FastK, slowing_period1);
plot TF1_FullD = if HideD1 then double.nan
else MovingAverage(averageType1, TF1_FullK, DPeriod1);

# TF2
def T2L = low(period = Period2);
def T2H = high(period = Period2);
def T2C = close(period = Period2);

def TF2_lowest_k = Lowest(T2L, KPeriod2);
def TF2_c1 = T2C – TF2_lowest_k;
def TF2_c2 = Highest(T2H, KPeriod2) – TF2_lowest_k;
def TF2_FastK = if TF2_c2 != 0 then TF2_c1 / TF2_c2 * 100 else 0;

plot TF2_FullK =
if HideK2 then double.nan
else ExpAverage(TF2_FastK, slowing_period2);
plot TF2_FullD = if HideD2 then double.nan
else ExpAverage(TF2_FullK, DPeriod2);

</pre>

 

Attachments:
Marked as spam
Posted by (Questions: 2, Answers: 1)
Asked on May 13, 2020 8:08 pm
138 views
0
Private answer

Stair-step pattern. So this is you very first foray into the world of referencing secondary aggregation periods (also referred to as multiple time frames). There is no "fix" for this. It is simply the nature of this new reality you have discovered. Mark this date on the calendar. You'll want to remember when you first came to understand this.

Take the most basic example of plotting a series of data from the 1 hour time frame on the 15 minute chart. There are exactly 4 of each 15 min bars that are combined to create a single 1 hour bar. So when you plot the 1 hour close on a 15 min chart you end up with a stair-step pattern that changes to a new value every 4th 15 min bar. You may want to go back and read that paragraph 2-3 more times. This is important, and not very intuitive.

Now that you have discovered this. You absolutely must understand the consequences and pitfalls. On your own, it may take you several years to come to understand these details. (I am speaking from experience). Or you can take a couple of hours out of your day and view the following videos:

https://www.hahn-tech.com/thinkorswim-mtf-macd-indicator/

https://www.hahn-tech.com/thinkorswim-strategy-guide-mtf/

 

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on May 13, 2020 9:14 pm
0
Yes! I had started to understand what was going on, but not as clearly as you put it. I tried using a counter to only plot the 10 min value every 10th 1 minute candle hoping that because it was a "line" it would get drawn as such but no luck making that work. I'll take a look at the videos, thanks.
( at May 14, 2020 6:57 am)