Hi everyone,
I'm working on setting up some automated parameters to execute based on a few things: Trades only within the first two hours, Price over a certain moving average, over daily and monthly VWAP, with shorts on the inverse side of things. Backtesting has been going well, but I'm unable to figure out the code for implementing VWAP into the broader strategy. I've been using chatgpt to write a lot of this for me as I'm not familiar with code myself, but can't seem to work out the VWAP coding. Any suggestions? Code below with ***** next to my issue.
input marketOpenTime = 0930;
input marketCloseTime = 1130; # Change market close time as per your requirement
input EMA_Length_3min = 13;
input EMA_Length_Exit = 20;
def EMA_3min_13 = ExpAverage(close, EMA_Length_3min);
def EMA_3min_20 = ExpAverage(close, EMA_Length_Exit);
def VWAP_Monthly = reference VWAP("length" = "M"); ******************** This is where I was having issues, VWAP("length" is being shaded as red in TS.
def sessionOpen = SecondsFromTime(marketOpenTime) >= 0;
def sessionClose = SecondsTillTime(marketCloseTime) >= 0;
def buyCondition = close > EMA_3min_13 and sessionOpen and sessionClose and close > VWAP_Monthly;
def sellCondition = close < EMA_3min_20;
AddOrder(OrderType.BUY_TO_OPEN, buyCondition, open[-1], 1, Color.GREEN, Color.GREEN, "Buy");
AddOrder(OrderType.SELL_TO_CLOSE, sellCondition, open[-1], 1, Color.RED, Color.RED, "Sell");
def shortCondition = close < EMA_3min_13 and sessionOpen and sessionClose and close < VWAP_Monthly;
def coverCondition = close > EMA_3min_20;
AddOrder(OrderType.SELL_TO_OPEN, shortCondition, open[-1], 1, Color.RED, Color.RED, "Short");
AddOrder(OrderType.BUY_TO_CLOSE, coverCondition, open[-1], 1, Color.GREEN, Color.GREEN, "Cover");
I'm working on setting up some automated parameters to execute based on a few things: Trades only within the first two hours, Price over a certain moving average, over daily and monthly VWAP, with shorts on the inverse side of things. Backtesting has been going well, but I'm unable to figure out the code for implementing VWAP into the broader strategy. I've been using chatgpt to write a lot of this for me as I'm not familiar with code myself, but can't seem to work out the VWAP coding. Any suggestions? Code below with ***** next to my issue.
input marketOpenTime = 0930;
input marketCloseTime = 1130; # Change market close time as per your requirement
input EMA_Length_3min = 13;
input EMA_Length_Exit = 20;
def EMA_3min_13 = ExpAverage(close, EMA_Length_3min);
def EMA_3min_20 = ExpAverage(close, EMA_Length_Exit);
def VWAP_Monthly = reference VWAP("length" = "M"); ******************** This is where I was having issues, VWAP("length" is being shaded as red in TS.
def sessionOpen = SecondsFromTime(marketOpenTime) >= 0;
def sessionClose = SecondsTillTime(marketCloseTime) >= 0;
def buyCondition = close > EMA_3min_13 and sessionOpen and sessionClose and close > VWAP_Monthly;
def sellCondition = close < EMA_3min_20;
AddOrder(OrderType.BUY_TO_OPEN, buyCondition, open[-1], 1, Color.GREEN, Color.GREEN, "Buy");
AddOrder(OrderType.SELL_TO_CLOSE, sellCondition, open[-1], 1, Color.RED, Color.RED, "Sell");
def shortCondition = close < EMA_3min_13 and sessionOpen and sessionClose and close < VWAP_Monthly;
def coverCondition = close > EMA_3min_20;
AddOrder(OrderType.SELL_TO_OPEN, shortCondition, open[-1], 1, Color.RED, Color.RED, "Short");
AddOrder(OrderType.BUY_TO_CLOSE, coverCondition, open[-1], 1, Color.GREEN, Color.GREEN, "Cover");