MTF Stochastic "Stoplight" Upper Study

D

Dixon72

New member
Hey everyone, new to the site. I've enjoyed sifting through the collection of indicators on this site and it's inspired me to try some scripting of my own. Disclaimer: I suck and am still learning. I've tried piecing together some code (some borrowed, some not) to make an MTF Stochastic stoplight-like upper indicator. It'll end up as a collection of red/green squares at the top of the chart that will tell you what the current status of the StochasticFull is (%K > %D = green and vice verse) for multiple charts -- 1D, 4hr, 1hr, 30 min, whatever you want. I've been successful getting one timeframe's stoplight to appear on it's own chart, but can't figure out how to have all timeframes report on a single chart (30min, 15min, 5min, 1 min all on the 1min chart). The code for I've been working on to get multiple timeframes reporting on a single chart is below, but it has an error with the "script SymbolStochastic {" line. I'm sure it's something silly due to me not knowing what I'm doing, but would appreciate it if someone could show me the error of my ways. Thanks!

declare upper;
input period = AggregationPeriod.DAY;
input over_bought = 80;
input over_sold = 20;
input KPeriod = 5;
input DPeriod = 3;
input slowing_period = 3;
input priceH = high;
input priceL = low;
input priceC = close;
input aP = AggregationPeriod.DAY;
input averageType = AverageType.SIMPLE;
DefineGlobalColor("CrossDown", Color.GREEN);
DefineGlobalColor("CrossUp", Color.RED);
script SymbolStochastic {
def CrossUp = FullK >= FullD;
def CrossDown = FullK < FullD;
def lowest_k = Lowest(priceL, KPeriod);
def c1 = priceC – lowest_k;
def c2 = Highest(priceH, KPeriod) – lowest_k;
def FastK = if c2 != 0 then c1 / c2 * 100 else 0;
def FullK = MovingAverage(averageType, FastK, slowing_period);
def FullD = MovingAverage(averageType, FullK, DPeriod);
def currentPeriod = GetAggregationPeriod();
if period >= currentPeriod {
s1 = SymbolStochastic(aP = period);
} else {
s1 = Double.NaN;
}
AddLabel(!IsNaN(s1), if period == AggregationPeriod.MONTH then "M" else
if period == AggregationPeriod.WEEK then "W" else
if period == AggregationPeriod.FOUR_DAYS then "4D" else
if period == AggregationPeriod.THREE_DAYS then "3D" else
if period == AggregationPeriod.TWO_DAYS then "2D" else
if period == AggregationPeriod.DAY then "D" else
if period == AggregationPeriod.FOUR_HOURS then "4H" else
if period == AggregationPeriod.TWO_HOURS then "2H" else
if period == AggregationPeriod.HOUR then "60m" else
if period == AggregationPeriod.THIRTY_MIN then "30m" else
if period == AggregationPeriod.TWENTY_MIN then "20m" else
if period == AggregationPeriod.FIFTEEN_MIN then "15m" else
if period == AggregationPeriod.TEN_MIN then "10m" else
if period == AggregationPeriod.FIVE_MIN then "5m" else
if period == AggregationPeriod.FOUR_MIN then "4m" else
if period == AggregationPeriod.THREE_MIN then "3m" else
if period == AggregationPeriod.TWO_MIN then "2m" else
if period == AggregationPeriod.MIN then "1m"
else "", if s1 > 0 then GlobalColor("CrossUp") else GlobalColor("CrossDown"));
 
markos

markos

Well-known member
VIP
Warehouse
@Dixon72 Nice start from the looks of things. Please go through the Universe of Thinkscript, located in the Tutorial section. You'll find examples there.
Please fill out you signature line so we know where your comin' from. :)

"Something simple like you not knowing what you're doing." :LOL::ROFLMAO: It looks to me like you've got a very good grip on things for a beginner.

Take a look at this indicator below, open it up and go thru the code. It will give you an idea of what might be needed. (Or not!)
StopLightIndicators_Lar719
 

Top