Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Alert(your condition here, "your text here", alert.bar, sound.chimes);
. You can adjust the alert type and sound as well - see https://tlc.thinkorswim.com/center/reference/thinkScript/Functions/Others/Alert.crosses above
or crosses below
. If you need help, post your code here. #
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#
input numDevDn = -1.0;
input numDevUp = 1.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));
def VWAP = price;
plot UpperBand = price + numDevUp * deviation;
#plot LowerBand = price + numDevDn * deviation;
AssignBackgroundColor(if close > UpperBand then Color.DARK_GREEN else Color.Gray);
def VWAP_Upper = price + numDevUp * deviation;
def VWAP_Lower = price + numDevDn * deviation;
def VWAP_StrongBull = close > VWAP_Upper;
def VWAP_Bull = close < VWAP_Upper and close > price;
def VWAP_Bear = close > VWAP_Lower and close < price;
def VWAP_StrongBear = close < VWAP_Lower;
plot VWAP_Num = if VWAP_StrongBull is true then 2 else if VWAP_Bull is true then 1 else if VWAP_Bear is true then -1 else if VWAP_StrongBear is true then -2 else 0;
AssignBackgroundColor(if VWAP_Num == 2 then Color.DARK_GREEN else if VWAP_Num == 1 then color.GREEN else if VWAP_Num == -1 then color.RED else if VWAP_Num == -2 then Color.Dark_Red else Color.White);
@Bung Bang A scan code that looks for EMA(9) crossing VWAP can be simply coded as follows. If you want this to lookback 2 bars, just change the value of the variable lookback to 2. Be default it is set to 0, which means it looks at the current bar.
Code:def lookback = 0; def EMA = ExpAverage(close, 9); def vwapValue = VWAP()[lookback]; plot scan = EMA crosses vwapValue;
input numDevDn = -1.0;
input numDevUp = 1.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));
def VWAP = price;
def VWAP_Upper = price + numDevUp * deviation;
def VWAP_Lower = price + numDevDn * deviation;
def SignalEMA = movAvgExponential (3);
def VWAP_StrongBull = SignalEMA crosses above VWAP_Upper within 5 bars;
plot VWAP_Num = if VWAP_StrongBull is true then 2 else 0;
AssignBackgroundColor(if VWAP_Num == 2 then Color.BLUE else Color.Black);
# EMA crossing above Upper VWAP Band Watchlist Column
# By BenTen of useThinkScript.com
declare upper;
# Moving Average
input priceMA = close;
input lengthMA = 9;
input displace = 0;
input showBreakoutSignals = yes;
input price = close;
def EMA = ExpAverage(priceMA[-displace], lengthMA);
# VWAP
input numDevDn = -2.0;
input 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 priceVWAP = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(priceVWAP), 0));
def VWAP = priceVWAP;
def UpperBand = priceVWAP + numDevUp * deviation;
#plot LowerBand = priceVWAP + numDevDn * deviation;
def bullish_signal = EMA crosses above UpperBand;
#def bearish_signal = EMA crosses below priceVWAP;
# Plot Signals
plot bullish = bullish_signal;
AssignBackgroundColor(if bullish then color.dark_green else color.gray);
Newbie here Looking for an intraday scan to find EMA9 ("trade line") crossing above VWAP.....
Can you point me in the right direction?
MovAvgExponential("length" = 9)."AvgExp" crosses above reference VWAP()."VWAP"
input maType = AverageType.EXPONENTIAL;
input maPrice = close;
input maLength = 9;
input numDevDn = -1.0;
input numDevUp = 1.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;
plot UpperBand = price + numDevUp * deviation;
plot LowerBand = price + numDevDn * deviation;
VWAP.setDefaultColor(getColor(0));
UpperBand.setDefaultColor(getColor(2));
LowerBand.setDefaultColor(getColor(4));
plot ma = MovingAverage(maType, maPrice, maLength);
ma.SetStyle(Curve.MEDIUM_DASH);
plot crossAbove = ma[1] < VWAP[1] and ma > VWAP;
crossAbove.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
crossAbove.SetLineWeight(3);
crossAbove.SetDefaultColor(Color.CYAN);
plot crossBelow = ma[1] > VWAP[1] and ma < VWAP;
crossBelow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
crossBelow.SetLineWeight(3);
crossBelow.SetDefaultColor(Color.MAGENTA);
plot condition1 = ma crosses below LowerBand;
condition1.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
plot condition2 = ma crosses above UpperBand;
condition2.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
Thread starter | Similar threads | Forum | Replies | Date |
---|---|---|---|---|
RSI (or MACD) with VWAP & MA & div for ThinkOrSwim | Indicators | 11 | ||
J | High/Low Anchored VWAP For ThinkOrSwim | Indicators | 16 | |
Opening Range Indicator with Measured Moves and VWAP For ThinkOrSwim | Indicators | 43 | ||
RSI-VWAP Indicator for ThinkorSwim | Indicators | 68 | ||
Squeeze Clouds based on SMA and VWAP | Indicators | 7 |
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.