Hi guys, I wrote a script about arrow alert when price closes above/ below VWAP and MATriangular at the same time but I don't know why when I plug in TOS, the arrow doesn't show up. Can your guys help me with this? Thank you so much. Have a great day guys.
Code:
input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};
input price = close;
input length = 9;
input displace = 0;
def na = double.nan;
def effectiveLength = Ceil((length + 1) / 2);
plot slowema = Average(Average(price[-displace], effectiveLength), effectiveLength);
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));
}
plot fastema = volumeVwapSum / volumeSum;
def crossover = if fastema > slowema AND fastema[1] <= slowema[1] then 1 else 0;
def crossunder = if fastema < slowema AND fastema[1] >= slowema[1] then 1 else 0;
plot ArrowUp = Crosses(close, crossover, CrossingDirection.ABOVE);
plot ArrowDown = Crosses(close, crossunder, CrossingDirection.BELOW);
ArrowUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
ArrowDown.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Last edited by a moderator: