Ricorichie
New member
Looking at my current VWAP from TOS (slightly modified of course).
How can I change the "input timeframe" to just be "Day" only instead of {default DAY, WEEK, MONTH}? Each time I try to modify that it throws errors about "def cap" and "def error". I'd like to be able to "def" the timeframe instead of "inputting" it. So basically I want to carve out and remove "week" and "Month" from the script. If that makes sense.
How can I change the "input timeframe" to just be "Day" only instead of {default DAY, WEEK, MONTH}? Each time I try to modify that it throws errors about "def cap" and "def error". I'd like to be able to "def" the timeframe instead of "inputting" it. So basically I want to carve out and remove "week" and "Month" from the script. If that makes sense.
Code:
def numDevDn = -2.0;
def 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;
VWAP.SetDefaultColor(CreateColor (220,68,220));