Z score strategy help



New member
I have a indicator that I like but need some help with the strategy for further testing. Long entry is when the avgZscore is below -1 and the signal is when Zscore crosses above -1. Short entry is avgZscore is above 1 and the signal is Zscore crosses below 1. Exit would be ATR multiple for trailing stop and profit target.

declare lower;
input length = 20;
input Agg = {default current, min5, min15, min30, daily}; def t; switch (Agg){ case current:     t = close; case min5:     t = close(period = AggregationPeriod.FIVE_MIN); case min15:     t = close(period = AggregationPeriod.FIFTEEN_MIN); case min30:     t = close(period = AggregationPeriod.THIRTY_MIN); case daily:     t = close(period = AggregationPeriod.DAY); } def c = close;
plot Zscore = (t - Average(t, length)) / StDev(t, length); Zscore.SetDefaultColor(Color.cyan);
plot zero = if IsNaN(c) then Double.NaN else 0; zero.SetDefaultColor(Color.BLACK);
zero.SetLineWeight(1); zero.HideTitle();
plot PosOne = if IsNaN(c) then Double.NaN else 1; PosOne.SetDefaultColor(Color.white); PosOne.HideTitle();
plot NegOne = if IsNaN(c) then Double.NaN else -1; NegOne.SetDefaultColor(Color.yellow); NegOne.HideTitle();
plot PosTwo = if IsNaN(c) then Double.NaN else 2; PosTwo.SetDefaultColor(Color.GREEN); PosTwo.HideTitle();
plot NegTwo = if IsNaN(c) then Double.NaN else -2; NegTwo.SetDefaultColor(Color.RED);
plot PosThree = if IsNaN(c) then Double.NaN else 3; PosThree.SetDefaultColor(Color.DARK_GREEN); PosThree.HideTitle();
plot NegThree = if IsNaN(c) then Double.NaN else -3; NegThree.SetDefaultColor(Color.DARK_RED); NegThree.HideTitle();
AddCloud(zero, PosOne, Color.LIGHT_GREEN, Color.LIGHT_GREEN);
AddCloud(PosOne, PosTwo, Color.GREEN, Color.GREEN); AddCloud(PosTwo, PosThree, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(NegOne, zero, Color.LIGHT_RED, Color.LIGHT_RED);
AddCloud(NegTwo, NegOne, Color.RED, Color.RED);
AddCloud(NegThree, NegTwo, Color.DARK_RED, Color.DARK_RED);
Zscore input price = close;
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);
plot avgZscore = Average(Zscorevalue, ZavgLength);
avgZscore.SetPaintingStrategy(PaintingStrategy.LINE); avgZscore.SetLineWeight(2); avgZscore.AssignValueColor(Color.GREEN);



thank you HorseRider, its works.. a quick question, do you know if someone have the toptradertools, linear compression pro?


Well-known member
No idea what linear compression pro is. Take a look at ECI gaussian it is on here somewhere, just search. Play with inputs to get what you want. @FOTM_8888

Similar threads