EMA-VWAP-BBand in ThinkOrSwim

Gerrypicker

New member
VIP
EMA-VWAP-BBand 5min Strategy - Needs one more tweak

#This TOS strategy is executed on a 5min timeframe and has produced promising backtest results for trading on the 5 min timeframe. It does the following:
#Buys when EMA9 is greater than EMA20 AND price is above VWAP
#Sells when EMA9 is less than EMA20 OR if price slices downward through the upper bollinger band price between within then hours of 1000 and 1545
#The bollinger band sell condition above is designed to guard against taking profit too early during the first 30 minutes of market open in the event that price accelerates above and below the upper BB band too rapidly, hence the 1000 - 1545 window

#The current script does not register a sell order sourced from the bollingerBand condition; any help would be greatly appreciated!

EXP VWAP BBand 5 min.jpg


Ruby:
input quickexp1 = 9;
input longexp1 = 20;
input bbperiod = 55;
Input SDlength = 55;
input BBupperSD = 2.3;
input vwap = vwap;
input tradesize = 1000;
input priceActionIndicator = close;
input tradingstarttime = 1000;
input tradingendtime = 1545;
def exp1 = ExpAverage(close, length = quickexp1);
def exp2 = ExpAverage(close, length = longexp1);
#bband average price calculated from SMA
def bbperiodaverage = movingaverage (averagetype.SIMPLE,close, bbperiod);
#standard deviation of Bband average price
def SDBBand = stdev(bbperiodaverage,length=sdlength);
#price of upper bband
def upperbbprice = bbperiodaverage + (bbupperSD*sdbband);
def bbandcrossdown = (close < upperbbprice and upperbbprice[1] < close[1]);
def price = price;
def vwapbelow = vwap <= close;
def vwapabove = vwap > close and vwap[1] <= close[1];
def tradingstart = tradingstarttime;
def tradingend = tradingendtime;
def currenttime = GetTime();
def signaltimeB2 = currenttime >=tradingstarttime or currenttime <=tradingendtime;
def buy2 = exp1[0] >= exp2[0] and vwapbelow;
AddOrder(OrderType.BUY_TO_OPEN, buy2, open[-1], tradesize, name = "buy2", Color.DARK_GREEN);
def sell3 = exp1[0] < exp2[0] or (bbandcrossdown and signaltimeB2);
#def sell3 = exp1 < exp2 or (close[1] >= upperbbprice[1] and close < upperbbprice);
AddOrder(OrderType.SELL_TO_CLOSE, sell3, open[-1], tradesize, name = "sell3", Color.DARK_RED);

Update:
You can enter sequential orders, up to 8. I use a combination of EMA crossovers and VWAP coded as Thinkscript within the Condition Wizard with the plot signal = 1 to initiate the trade. An initial buy order is triggered when EMA 9 [1]is greater than EMA 20[1], for example, and a sell order automatically fires when EMA 9 is less than EMA 20. I use this on a 5-minute timeframe and include an EOD sell order. The buy/sell orders repeat automatically until the four round trips are made or the trading day ends. Better for trending price action versus sideways movement. It works but you still need to watch it.
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

EMA-VWAP-BBand 5min Strategy - Needs one more tweak

#This TOS strategy is executed on a 5min timeframe and has produced promising backtest results for trading on the 5 min timeframe. It does the following:
#Buys when EMA9 is greater than EMA20 AND price is above VWAP
#Sells when EMA9 is less than EMA20 OR if price slices downward through the upper bollinger band price between within then hours of 1000 and 1545
#The bollinger band sell condition above is designed to guard against taking profit too early during the first 30 minutes of market open in the event that price accelerates above and below the upper BB band too rapidly, hence the 1000 - 1545 window

#The current script does not register a sell order sourced from the bollingerBand condition; any help would be greatly appreciated!

View attachment 21050

input quickexp1 = 9;
input longexp1 = 20;
input bbperiod = 55;
Input SDlength = 55;
input BBupperSD = 2.3;
input vwap = vwap;
input tradesize = 1000;
input priceActionIndicator = close;
input tradingstarttime = 1000;
input tradingendtime = 1545;
def exp1 = ExpAverage(close, length = quickexp1);
def exp2 = ExpAverage(close, length = longexp1);
#bband average price calculated from SMA
def bbperiodaverage = movingaverage (averagetype.SIMPLE,close, bbperiod);
#standard deviation of Bband average price
def SDBBand = stdev(bbperiodaverage,length=sdlength);
#price of upper bband
def upperbbprice = bbperiodaverage + (bbupperSD*sdbband);
def bbandcrossdown = (close < upperbbprice and upperbbprice[1] < close[1]);
def price = price;
def vwapbelow = vwap <= close;
def vwapabove = vwap > close and vwap[1] <= close[1];
def tradingstart = tradingstarttime;
def tradingend = tradingendtime;
def currenttime = GetTime();
def signaltimeB2 = currenttime >=tradingstarttime or currenttime <=tradingendtime;
def buy2 = exp1[0] >= exp2[0] and vwapbelow;
AddOrder(OrderType.BUY_TO_OPEN, buy2, open[-1], tradesize, name = "buy2", Color.DARK_GREEN);
def sell3 = exp1[0] < exp2[0] or (bbandcrossdown and signaltimeB2);
#def sell3 = exp1 < exp2 or (close[1] >= upperbbprice[1] and close < upperbbprice);
AddOrder(OrderType.SELL_TO_CLOSE, sell3, open[-1], tradesize, name = "sell3", Color.DARK_RED);

You can enter sequential orders, up to 8. I use a combination of EMA crossovers and VWAP coded as Thinkscript within the Condition Wizard with the plot signal = 1 to initiate the trade. An initial buy order is triggered when EMA 9 [1]is greater than EMA 20[1], for example, and a sell order automatically fires when EMA 9 is less than EMA 20. I use this on a 5-minute timeframe and include an EOD sell order. The buy/sell orders repeat automatically until the four round trips are made or the trading day ends. Better for trending price action versus sideways movement. It works but you still need to watch it.
The strategy does not plot the BB but your attached image does.
I am not seeing the issue, can you attach an image with only the strategy and all the visual information necessary to verify the entry logic?
 

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
284 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top