MWilliamson83
New member
I have created a custom script for chart signals which works exactly as intended. It's basically a crossover event involving VWAP and some SMAs. However, when coding the watchlist columns, it will not work. I've plotted each variable one by one, including VWAP, and each matches the values on the chart exactly. But the crossover trigger that I'm using for the chart just isn't working, or it's firing at the wrong times, etc. So the code is below, am I missing something?
Note, I copied the VWAP code from the VWAP study, didn't write that part.
Note, I copied the VWAP code from the VWAP study, didn't write that part.
Code:
##########################################
# #
# Assigning & plotting VWAP #
# #
##########################################
input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};
def cap = GetAggregationPeriod();
def errorInAggregation =
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
Assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");
def yyyyMmDd = GetYYYYMMDD();
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd;
case WEEK:
periodIndx = Floor((DaysFromDate(First(yyyyMmDd)) + GetDayOfWeek(First(yyyyMmDd))) / 7);
case MONTH:
periodIndx = RoundDown(yyyyMmDd / 100, 0);
}
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 price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));
plot VWAP = price;
#plot UpperBand = price + numDevUp * deviation;
#plot LowerBand = price + numDevDn * deviation;
#VWAP.SetDefaultColor(Color.YELLOW);
#UpperBand.setDefaultColor(getColor(2));
#LowerBand.setDefaultColor(getColor(4));
##########################################
# #
# Plotting the EMAs #
# #
##########################################
input short_ema_length = 10;
input long_ema_length = 30;
def short_ema = MovAvgExponential(close, short_ema_length);
#short_ema.SetDefaultColor(Color.CYAN);
def long_ema = MovAvgExponential(close, long_ema_length);
#long_ema.SetDefaultColor(Color.RED);
input lookback = 10;
##########################################
# #
# Defining main signal #
# #
##########################################
def bearish_trigger =
short_ema < long_ema
and
long_ema < VWAP
###use next line (delete the # signs to use) to include price over the MAs and VWAP as a condition
###and close > short_ema
;
##########################################
# #
# Plotting the trigger signal #
# #
##########################################
def bearish_signal = bearish_trigger[1] is false and bearish_trigger and bearish_trigger is false within lookback bars;
#addLabel(Yes, if bearish_signal then "Sell" else " " ,color.red);
#bearish_signal.AssignValueColor(Color.RED);
#bearish_signal.SetPaintingStrategy(paintingStrategy = PaintingStrategy.BOOLEAN_ARROW_DOWN);