thealphabreed
Member
would this work on a 1min and 5min chart or we need to edit the script for those timeframes?
would this work on a 1min and 5min chart or we need to edit the script for those timeframes?
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Thanks @BenTen@thealphabreed It should work on any timeframe, I don't see why you would need to edit the script for this sort of setup.
# Price crossing above or below 9 EMA and VWAP
# 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 bullish_signal = EMA crosses above priceVWAP;
def bearish_signal = EMA crosses below priceVWAP;
# Plot Signals
plot bullish = bullish_signal;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(3);
plot bearish = bearish_signal;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.CYAN);
bearish.SetLineWeight(3);
AddOrder(OrderType.BUY_TO_OPEN, condition = bullish_signal, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Long");
AddOrder(OrderType.SELL_TO_CLOSE, condition = bearish_signal, price = close,1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "Cover");
BenTen - The ToS editor displays "Exactly one plot expected" at the bottom when I add your code to it. Does it require an if-else condition? Pls advise. Thanks.
close is greater than or equal to reference VWAP()."VWAP" * .98 and close is less than reference VWAP ()."VWAP" * 1.02
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.