I'm trying to combine a couple indicators to create a strategy that gives me a buy sell signal. Can anyone help?
Ruby:
Buy when HMA 20 crosses over 50, zscore (1hr) turns green, accumulation distribution index turns green
#########
HMA Cloud
#########
plot hma20 = hullMovingAvg(close, 20);
plot hma50 = hullMovingAvg(close, 50);
AddCloud(hma20, hma50, Color.GREEN, Color.RED);
#########
Zscore (multiple time frame)
#########
#Computes and plots the Zscore
#Provided courtesy of ThetaTrend.com
#Feel free to share the indicator, but please provide a link back to ThetaTrend.com
declare lower;
input price = close;
input length = 20;
input ZavgLength = 20;
#Initialize values
def oneSD = stdev(price,length);
def avgClose = simpleMovingAvg(price,length);
def ofoneSD = oneSD*price[1];
def Zscorevalue = ((price-avgClose)/oneSD);
def avgZv = average(Zscorevalue,20);
#Compute and plot Z-Score
plot Zscore = ((price-avgClose)/oneSD);
Zscore.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Zscore.setLineWeight(2);
Zscore.assignValueColor(if Zscore > 0 then color.green else color.red);
plot avgZscore = average(Zscorevalue,ZavgLength);
avgZscore.setPaintingStrategy(paintingStrategy.LINE);
#This is an optional plot that will display the momentum of the Z-Score average
plot momZAvg = (avgZv-avgZv[5]);
#Plot zero line and extreme bands
plot zero = 0;
plot two = 2;
plot negtwo = -2;
zero.setDefaultColor(color.black);
########
Accumulation/Distribution (4hr)
########
# TOS MTF AccumulationSwingIndex
#global variables
input agg = AggregationPeriod.TEN_MIN ;
def cclose = close(period = agg);
def oopen = open(period = agg);
def hhigh = high(period = agg);
def llow = low(period = agg);
# ########################################################
input smaLength = 10;
def limit = 30;
def AbsHighClose = AbsValue(hhigh - cclose[1]);
def AbsLowClose = AbsValue(llow - cclose[1]);
def AbsCloseOpen = AbsValue(cclose[1] - oopen[1]);
def K = If(AbsHighClose >= AbsLowClose, AbsHighClose, AbsLowClose);
def R = If(AbsHighClose >= AbsLowClose,
If(AbsHighClose >= (hhigh - llow), AbsHighClose - 0.5 * AbsLowClose + 0.25 * AbsCloseOpen, (hhigh - llow) + 0.25 * AbsCloseOpen),
If(AbsLowClose >= (hhigh - llow), AbsLowClose - 0.5 * AbsHighClose + 0.25 * AbsCloseOpen, (hhigh - llow) + 0.25 * AbsCloseOpen));
def nRes = If(R != 0,
(50 * (((cclose - cclose[1]) + 0.50 * (cclose - oopen) + 0.25 * (cclose[1] - oopen[1])) / R ) * K / limit) + if !IsNaN(nRes[1]) then nRes[1] else 0,
0 + if !IsNaN(nRes[1]) then nRes[1] else 0);
def ASI = nRes;
def sma = SimpleMovingAvg(ASI,smaLength);
# ########################################################
# charting and formatting
declare lower;
plot pASI = ASI;
pASI.SetLineWeight(3);
pASI.AssignValueColor(if asi>sma then Color.Green else Color.RED);
plot pSMA = sma;
pSMA.SetPaintingStrategy(PaintingStrategy.DASHES);
pSMA.SetLineWeight(1);
pSMA.AssignValueColor(Color.VIOLET);
DefineGlobalColor("bear", CreateColor(225, 0, 0)) ;
DefineGlobalColor("bull", CreateColor(0, 165, 0)) ;
AddCloud(pASI, pSMA, GlobalColor("bull"), GlobalColor("bear"));
Last edited by a moderator: