I appended this code to the original @horserider code and it looks like it works, but there isn't logic in place to shift the crosses when i change the ema. Is it possible to adjust that? Also, this only displays an UP arrow, any way to add a Down arrow too? Love the implementation and the idea of only showing "x" arrows so not to clutter the chart. Turning off the lines would also free up space to add other items in the price areaThe following will limit the plot of arrows when yes to the number of x arrows:
input limit_arrow_plot = yes;
input show_x_arrows = 1;
The following set to 1 will plot the arrow on the cross. If set higher it will move the arrow to the right from the cross by that increase:
input show_within_bars = 1;
Thanks!.
Code:
# 5 EMA and VWAP cross. Modified 2 ToS studies and added labels for crosses. By Horserider 7/21/2019
# TD Ameritrade IP Company, Inc. (c) 2011-2019
#
#Example_cond_limit_plot
input limit_arrow_plot = yes;
input show_x_arrows = 1;
input show_within_bars = 1;
def bullish = reference VWAP()."VWAP" crosses above MovAvgExponential("length" = 5)."AvgExp" within show_within_bars bars;
def dataCount = CompoundValue(1, if IsNaN(dataCount[1]) then 0 else if bullish then dataCount[1] + 1 else dataCount[1], 0);
plot upArrow = if limit_arrow_plot and HighestAll(dataCount) - dataCount <= show_x_arrows - 1
then bullish
else if !limit_arrow_plot
then bullish
else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upArrow.SetDefaultColor(CreateColor(145, 210, 144));
upArrow.SetLineWeight(4);
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;
plot VWAP = price;
# TD Ameritrade IP Company, Inc. (c) 2017-2019
#
input price2 = close;
input length = 5;
input displace = 0;
plot AvgExp = ExpAverage(price2[-displace], length);
AddLabel(yes, "Buy ", if avgexp > vwap then Color.GREEN else color.GRAY);
AddLabel(yes, "Sell", if avgexp < vwap then Color.RED else color.GRAY);
Last edited: