hectorgasm
Member

This is intended to use on a 5 minute graph
-Please feel free to comment or suggest further enhancements
http://tos.mx/HaokTj2
Code:
##CREATED BY GASMOS ;)
######################## PLOTTING THE SLOWRSI #####################################
input emaLength = 5;
input rsiLength = 10;
input over_bought = 80;
input over_sold = 20;
#breakout signals of SLOWRSI
input averageType = AverageType.WILDERS;
input showBreakoutSignals = no;
def ema = ExpAverage(close, emaLength);
def netChgAvg = WildersAverage(close - ema, rsiLength);
def totChgAvg = WildersAverage(AbsValue(close - ema), rsiLength);
def chgRatio = if totChgAvg != 0 then netChgAvg / totChgAvg else 0;
def SlowRSI = 50 * (chgRatio + 1);
def OverBought = over_bought;
def MiddleLine = 50;
def OverSold = over_sold;
#plot breakout signals of SLOWRSI
def UpSignal = if SlowRSI crosses above OverSold then OverSold else Double.NaN;
def DownSignal = if SlowRSI crosses below OverBought then OverBought else Double.NaN;
#Moving Averages of SLOWRSI
input MALength = 9;
input AverageType1 = AverageType.WEIGHTED;
input MALength2 = 26;
input AverageType2 = AverageType.SIMPLE;
input MALength3 = 57;
input AverageType3 = AverageType.SIMPLE;
input MALength4 = 200;
input AverageType4 = AverageType.HULL;
# plot the Moving Averages of SLOWRSI
def MA = MovingAverage(AverageType1, SlowRSI, MALength);
def pMA = MA;
def MA2 = MovingAverage(AverageType2, SlowRSI, MALength2);
def pMA2 = MA2;
def MA3 = MovingAverage (AverageType3, SlowRSI, MALength3);
def pMA3 = MA3;
def MA4 = MovingAverage(AverageType4, SlowRSI, MALength4);
def pMA4 = MA4;
################################ Plotting the MomentumSMA ###############################
input price = close;
input momentumLength = 26;
input smaLength = 26;
input AverageType11 = AverageType.SIMPLE;
input smaLength2 = 100;
input AverageType22 = AverageType.SIMPLE;
#Momentum
Assert(momentumLength > 0, "'momentum length' must be positive: " + momentumLength);
def Momentum = price - price[momentumLength];
#MomentumSMA Moving averages
def MA11 = MovingAverage(AverageType11, Momentum, smaLength);
def pMA11 = MA11;
def MA22 = MovingAverage(AverageType22, Momentum, smaLength2);
def pMA22 = MA22;
def ZeroLine = 0;
#plotting the arrows of Momentum SMA
def UpSignal1 = if Momentum crosses above pMA11 then pMA11 else Double.NaN;
def DownSignal2 = if Momentum crosses below pMA11 then pMA11 else Double.NaN;
####################### PLOTTING Z SCORE #####################################
def Data = close;
#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
input length = 20;
input ZavgLength = 26;
#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
def Zscore = ((price - avgClose) / oneSD);
def avgZscore = Average(Zscorevalue, ZavgLength);
#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
def zero = 0;
def two = 2;
def one = 1;
def negone = -1;
def negtwo = -2;
############# Plotting DEMANDIndex #################
input lengthDI = 20;
def wClose = (high + low + 2 * close) * 0.25;
def wCRatio = (wClose - wClose[1]) / Min(wClose, wClose[1]);
def closeRatio = 3 * wClose / Average(Highest(high, 2) - Lowest(low, 2), lengthDI) * AbsValue(wCRatio);
def volumeRatio = volume / Average(volume, lengthDI);
def volumePerClose = volumeRatio / Exp(Min(88, closeRatio));
def buyP;
def sellP;
if (wCRatio > 0) {
buyP = volumeRatio;
sellP = volumePerClose;
} else {
buyP = volumePerClose;
sellP = volumeRatio;
}
def buyPres = if IsNaN(buyPres[1]) then 0 else ((buyPres[1] * (lengthDI - 1)) + buyP) / lengthDI;
def sellPres = if IsNaN(sellPres[1]) then 0 else ((sellPres[1] * (lengthDI - 1)) + sellP) / lengthDI;
def tempDI;
if ((((sellPres[1] * (lengthDI - 1)) + sellP) / length - ((buyPres[1] * (lengthDI - 1)) + buyP) / lengthDI) > 0) {
tempDI = - if (sellPres != 0) then buyPres / sellPres else 1;
} else {
tempDI = if (buyPres != 0) then sellPres / buyPres else 1;
}
def DMIndx = if IsNaN(close) then Double.NaN else if tempDI < 0 then -1 - tempDI else 1 - tempDI;
def ZeroLineDI = 0;
#Demand Index Moving Averages
input DMIndxMALength = 8;
input DMIndxAverageType = AverageType.SIMPLE;
input DMIndxMALength2 = 26;
input DMIndxAverageType2 = AverageType.WEIGHTED;
input DMIndxMALength3 = 40;
input DMIndxAverageType3 = AverageType.SIMPLE;
input DMIndxMALength4 = 50;
input DMIndxAverageType4 = AverageType.SIMPLE;
def DMIndxMA = MovingAverage(DMIndxAverageType, DMIndx, DMIndxMALength);
def pDMIndxMA = DMIndxMA;
def DMIndxMA2 = MovingAverage(DMIndxAverageType2, DMIndx, DMIndxMALength2);
def pDMIndxMA2 = DMIndxMA2;
def DMIndxMA3 = MovingAverage(DMIndxAverageType3, DMIndx, DMIndxMALength3);
def pDMIndxMA3 = DMIndxMA3;
def DMIndxMA4 = MovingAverage(DMIndxAverageType4, DMIndx, DMIndxMALength4);
def pDMIndxMA4 = DMIndxMA4;
##########USE THIS STRATEGY FOR CONSISTENT RESULTS
AddOrder(OrderType.BUY_auto, SlowRSI crosses above pMA2 and Zscore > -1 and SlowRSI < MiddleLine and SLOWRSI > Oversold and dMIndx > pDMIndxMA2 and (Momentum > pMA11 or Momentum > Zeroline), tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");
AddOrder(OrderType.SELL_auto, SlowRSI crosses below pMA2 and Zscore < -1 and SLOWRSI > Oversold and (dMIndx < pDMIndxMA2), tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");
AddOrder(OrderType.SELL_auto, SlowRSI crosses below pMA2 and Zscore < 1 and SlowRSI > MiddleLine and SLOWRSI < Overbought and dMIndx < pDMIndxMA2 and (Momentum < pMA11 or Momentum < Zeroline), tickcolor = GetColor(1), arrowcolor = GetColor(1), name = "SE");
AddOrder(OrderType.BUY_auto, SlowRSI crosses above pMA2 and Zscore > -1 and SLOWRSI > Oversold and (dMIndx > pDMIndxMA2), tickcolor = GetColor(0), arrowcolor = GetColor(0), name = "LE");
#STOP LOSS ATR
input stop_mult = 2.5;
def stopb = EntryPrice() - ATR() * stop_mult;
AddOrder(OrderType.SELL_to_close, CLOSE <= stopb, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", price = stopb);
def stops = EntryPrice() + ATR() * stop_mult;
AddOrder(OrderType.BUY_to_close, CLOSE >= stops, tickcolor = Color.GRAY, arrowcolor = Color.GRAY, name = "Stop", price = stops);
Last edited: