♥ 0 |
Is there a way to display the VWAP study without accounting for the pre-market prints? I like to have both displayed on my charts. My old software used to have an option to turn it on/off. I tried messing with the code, adding start and end time inputs but I can’t seem to figure it out. This is what I have so far: input Begin = 0930; def Active = if SecondsFromTime(Begin) > 0 and SecondsTillTime(End) >= 0 then 1 else 0; plot VWAP = active ==1; VWAP.SetDefaultColor(getcolor(9));
Any help is greatly appreciated.
Marked as spam
|
Please log in to post questions.
I can tell you that your sample code ends up plotting a true/false value. The actual vwap value is not included anywhere in your code.
So did you look at the VWAP study that comes with Thinkorswim? Is that what you are using? There is a whole lot more going on than what you have included in your sample code. The study resets the value of the vwap plot based on a user input called “time frame”. When set to DAY, the study resets the vwap plot at the start of each day. To achieve your stated goal, you would need to add a new value to “time frame”. Call it “reg hours” or something. Then modify the switch/case statement for the timeFrame input to include a case for that selection.
Then to clean things up, you would need to further modify the plot statement so the vwap plot is set to Double.NaN during extended trading hours.
Thanks for your reply Pete. I’ve tried to rewrite the code based on what you’ve mentioned but I’m having trouble with modifying the plot statement so that it only shows the VWAP during REG_HOURS. How does everything else look?
input timeFrame = {default DAY, WEEK, MONTH, REG_HOURS};
def Begin = 0930;
def End = 1600;
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 REG_HOURS:
periodIndx = if SecondsFromTime(Begin) > 0 and SecondsTillTime(End) >= 0 then 1 else 0;
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;
VWAP.setDefaultColor(getColor(0));
Actually, I’m not so sure that is plotting correctly.