How to display different results for different instruments?

RickK

Active member
Hi All, I've patched together a different kind of VWAP. Not one that measures standard deviations, but one that measures predictive movements. But the predictive movements are different for each instrument. For example, if my predictive movements for /ES are 10, they might be 40 for /NQ and 6 for /GC. I would like to have a single indicator that would display on a single chart an instrument's predictive movements....depending on the instrument selected.

I have included the indicator below that displays only the predictive movements for /ES. I would like to build in /NQ, /RTY, /CL and /GC but don't really know how to go about it.

Thanks to anyone who responds!

.....credit goes to @johntermotto for posting the original at https://usethinkscript.com/threads/fixed-offset-vwap.1940/

3T4Uodd.png


Code:
# VWAP_Offset_DollarAmt for DTP (/ES version)

# this script plots the VWAP and 8 deviation bands measured by
# predictive dollar amount movements.

# idea originally drawn from usethinkscript.com / fixed - offset - vwap

input Down1 = -6;
input Up1 = 6;
input Down2 = -12;
input Up2 = 12;
input Down3 = -18;
input Up3 = 18;
input Down4 = -24;
input Up4 = 24;
input Down5 = -30;
input Up5 = 30;
input Down6 = -36;
input Up6 = 36;
input Down7 = -42;
input Up7 = 42;
input Down8 = -48;
input Up8 = 48;
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 Band1 = price + Up1;
plot Band_1 = price + Down1;
plot Band2 = price + Up2;
plot Band_2 = price + Down2;
plot Band3 = price + Up3;
plot Band_3 = price + Down3;
plot Band4 = price + Up4;
plot Band_4 = price + Down4;
plot Band5 = price + Up5;
plot Band_5 = price + Down5;
plot Band6 = price + Up6;
plot Band_6 = price + Down6;
plot Band7 = price + Up7;
plot Band_7 = price + Down7;
plot Band8 = price + Up8;
plot Band_8 = price + Down8;

Band1.SetStyle(Curve.LONG_DASH);
Band_1.SetStyle(Curve.LONG_DASH);
Band2.SetStyle(Curve.LONG_DASH);
Band_2.SetStyle(Curve.LONG_DASH);
Band3.SetStyle(Curve.LONG_DASH);
Band_3.SetStyle(Curve.LONG_DASH);
Band4.SetStyle(Curve.LONG_DASH);
Band_4.SetStyle(Curve.LONG_DASH);
Band5.SetStyle(Curve.LONG_DASH);
Band_5.SetStyle(Curve.LONG_DASH);
Band6.SetStyle(Curve.LONG_DASH);
Band_6.SetStyle(Curve.LONG_DASH);
Band7.SetStyle(Curve.LONG_DASH);
Band_7.SetStyle(Curve.LONG_DASH);
Band8.SetStyle(Curve.LONG_DASH);
Band_8.SetStyle(Curve.LONG_DASH);

VWAP.setDefaultColor(getColor(9));
VWAP.setLineWeight(3);
Band1.setDefaultColor(getColor(9));
Band_1.setDefaultColor(getColor(9));
Band2.setDefaultColor(getColor(9));
Band_2.setDefaultColor(getColor(9));
Band3.setDefaultColor(getColor(9));
Band_3.setDefaultColor(getColor(9));
Band4.setDefaultColor(getColor(9));
Band_4.setDefaultColor(getColor(9));
Band5.setDefaultColor(getColor(9));
Band_5.setDefaultColor(getColor(9));
Band6.setDefaultColor(getColor(9));
Band_6.setDefaultColor(getColor(9));
Band7.setDefaultColor(getColor(9));
Band_7.setDefaultColor(getColor(9));
Band8.setDefaultColor(getColor(9));
Band_8.setDefaultColor(getColor(9));

# end
 
Last edited:

Similar threads

Top