Post by Jordan on Apr 20, 2020 15:01:06 GMT -5
I have a script written to help Predict consolidation by using the stochastic oscillator using multiple time frames.
The Study works with only one problem. It repaints bar color after the fact. For instance If its referencing the 1 hour stochastic the indicator. The indicator might not be oversold or over bought for 55 of 60 minutes but as soon as the last five minutes go into over bought territory it changes the color of the bars the previous 55 minutes.
This isn't a problem in real time because the time has already passed and I would have never reacted to the indicator. However It is inconvenient when I am trying to go back and analyze my trades what I was thinking or doing during that moment.
Here is the code you have to view it on 2 minute timeframe or less using the current settings. but you can change the aggregation periods if you wanted to view it on higher timeframes.
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 5;
input Agg1 = AggregationPeriod.TWO_MIN;
input Agg2 = AggregationPeriod.FIVE_MIN;
input Agg3 = AggregationPeriod.FIFTEEN_MIN;
input Agg4 = AggregationPeriod.THIRTY_MIN;
input Agg5 = AggregationPeriod.HOUR;
input averageType = AverageType.SIMPLE;
####Stoch1
plot K1 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg1),low(period=Agg1),close(period=Agg1),3,averageType).FullK;
plot D1 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg1),low(period=Agg1),close(period=Agg1),3,averageType).FullD;
####Stoch2
plot K2 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg2),low(period=Agg2),close(period=Agg2),3,averageType).FullK;
plot D2 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg2),low(period=Agg2),close(period=Agg2),3,averageType).FullD;
####Stoch3
plot K3 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg3),low(period=Agg3),close(period=Agg3),3,averageType).FullK;
plot D3 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg3),low(period=Agg3),close(period=Agg3),3,averageType).FullD;
####Stoch4
plot K4 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg4),low(period=Agg4),close(period=Agg4),3,averageType).FullK;
plot D4 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg4),low(period=Agg4),close(period=Agg4),3,averageType).FullD;
####Stoch5
plot K5 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg5),low(period=Agg5),close(period=Agg5),3,averageType).FullK;
plot D5 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg5),low(period=Agg5),close(period=Agg5),3,averageType).FullD;
plot OverBought = over_bought;
plot OverSold = over_sold;
AssignPriceColor ( if K5 > OverBought and K4 > OverBought and K3 > OverBought and K2 > OverBought and K1 > Overbought then Color.blue
Else if K5 < OverSold and K4 < OverSold and K3 < OverSold and K2 < OverSold and K1 < Oversold then Color.yellow
else if K3 > OverBought and K2 > OverBought and K1 > Overbought then createColor (0, 153, 153)
Else if K3 < OverSold and K2 < OverSold and K1 < Oversold then createColor (153, 0, 153)
Else color.Current);
The Study works with only one problem. It repaints bar color after the fact. For instance If its referencing the 1 hour stochastic the indicator. The indicator might not be oversold or over bought for 55 of 60 minutes but as soon as the last five minutes go into over bought territory it changes the color of the bars the previous 55 minutes.
This isn't a problem in real time because the time has already passed and I would have never reacted to the indicator. However It is inconvenient when I am trying to go back and analyze my trades what I was thinking or doing during that moment.
Here is the code you have to view it on 2 minute timeframe or less using the current settings. but you can change the aggregation periods if you wanted to view it on higher timeframes.
input over_bought = 80;
input over_sold = 20;
input KPeriod = 10;
input DPeriod = 5;
input Agg1 = AggregationPeriod.TWO_MIN;
input Agg2 = AggregationPeriod.FIVE_MIN;
input Agg3 = AggregationPeriod.FIFTEEN_MIN;
input Agg4 = AggregationPeriod.THIRTY_MIN;
input Agg5 = AggregationPeriod.HOUR;
input averageType = AverageType.SIMPLE;
####Stoch1
plot K1 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg1),low(period=Agg1),close(period=Agg1),3,averageType).FullK;
plot D1 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg1),low(period=Agg1),close(period=Agg1),3,averageType).FullD;
####Stoch2
plot K2 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg2),low(period=Agg2),close(period=Agg2),3,averageType).FullK;
plot D2 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg2),low(period=Agg2),close(period=Agg2),3,averageType).FullD;
####Stoch3
plot K3 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg3),low(period=Agg3),close(period=Agg3),3,averageType).FullK;
plot D3 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg3),low(period=Agg3),close(period=Agg3),3,averageType).FullD;
####Stoch4
plot K4 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg4),low(period=Agg4),close(period=Agg4),3,averageType).FullK;
plot D4 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg4),low(period=Agg4),close(period=Agg4),3,averageType).FullD;
####Stoch5
plot K5 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg5),low(period=Agg5),close(period=Agg5),3,averageType).FullK;
plot D5 = reference StochasticFull(over_bought,over_sold,KPeriod,DPeriod,high(period=Agg5),low(period=Agg5),close(period=Agg5),3,averageType).FullD;
plot OverBought = over_bought;
plot OverSold = over_sold;
AssignPriceColor ( if K5 > OverBought and K4 > OverBought and K3 > OverBought and K2 > OverBought and K1 > Overbought then Color.blue
Else if K5 < OverSold and K4 < OverSold and K3 < OverSold and K2 < OverSold and K1 < Oversold then Color.yellow
else if K3 > OverBought and K2 > OverBought and K1 > Overbought then createColor (0, 153, 153)
Else if K3 < OverSold and K2 < OverSold and K1 < Oversold then createColor (153, 0, 153)
Else color.Current);