OptionsTrader
New member
Hey guys here is my code for some custom candlesticks I am using. I am trying to add the last condition would be ADX is rising not just above the trend level (I left a space where around line 18). I tried doing something similar to the LRV and put in: Def Trending= ADX (close, 50) - ADX (close, 9); after the DEF TRUP/TRDown. I don't get an error message but I can't press apply or ok and I'm really confused as to why. Any help would be very appreciated. Thanks
Code:
declare once_per_bar;
def NetChgAvg = MovingAverage(AverageType.WILDERS, close - close[1], 14);
def theta = GetYYYYMMDD();
def LRV = Inertia(close - ((Highest(high, 20) + Lowest(low, 20)) / 2 + ExpAverage(close, 20)) / 2, 20);
input ADXLength = 14;
input ADXTrend = 20;
input ADXaverageType = AverageType.WILDERS;
def ADX = DMI(ADXlength, ADXaverageType).ADX;
def DIPlus = reference DIPlus(length = ADXLength);
def DIMinus = reference DIMinus(length = ADXLength);
def Tr = if ADX > ADXTrend then 1 else 0;
Def TRUp = if DIPlus > DIMinus and TR then 1 else 0;
Def TRDown = If DIMinus > DIPlus and TR then 1 else 0;
def Value = MovingAverage(AverageType.EXPONENTIAL, close, 10) - MovingAverage(AverageType.EXPONENTIAL, close, 50);
def Avg = MovingAverage(AverageType.EXPONENTIAL, Value, 9);
def periodIndx = theta;
def isPeriodRolled = CompoundValue(1, periodIndx != periodIndx[1], yes);
def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;
if (isPeriodRolled) {
volumeSum = volume;
volumeVwapSum = volume * vwap;
volumeVwap2Sum = volume * Sqr(vwap);
} else {
volumeSum = CompoundValue(1, volumeSum[1] + volume, volume);
volumeVwapSum = CompoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
volumeVwap2Sum = CompoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def VWAP = volumeVwapSum / volumeSum;
def bulltrend = if ((Value > 0 and Avg > 0)) and (LRV > 0 and NetChgAvg > 0) and close[1] > VWAP[1] and close > VWAP and TRUp then 1 else 0;
def beartrend = if ((Value < 0 and Avg < 0)) and (LRV < 0 and NetChgAvg < 0) and close[1] < VWAP[1] and close < VWAP and TRDown then 1 else 0;
AssignPriceColor(if bulltrend then Color.GREEN else if beartrend then Color.RED else Color.BLUE);
#End