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!
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.
#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!
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: