Hi,
I have taken the VWAP code logic used by PRT and have a simple trading system to buy when close is below VWAP. I am running this on US 500 DFB on a 15M timeframe. The code works as an indicator but when I am trying to use it to build a trading strategy it is not returning any executions which is incorrect. Can you see any error in the code posted below
DEFPARAM CumulateOrders = FALSE// Cumulating positions deactivated
timeframe(daily,updateonclose)
//PRC_VWAP intraday
//SAME VERSION AS THE ORIGINAL VWAP FROM THE PLATFORM
//09.01.2020
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
if day<>day[1] then
d=0
else
d=d+1
if volume >0 then
VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
endif
sd = std[d](abs(typicalprice-vwap))
//SDHigh8 = vwap
//SDLow8 = vwap
//SDHigh9 = vwap+(sd*1)
//SDLow9 = vwap-(sd*1)
//SDHigh10 = vwap+(sd*2)
//SDLow10 = vwap-(sd*2)
endif
timeframe(default)
IF Close[0]<VWAP THEN
Trend= 1
ELSIF Close[0]> VWAP THEN
Trend = -1
ELSE
Trend = 0
ENDIF
StopLossBuy = 20
StopLossSell = 20
SellTarget = 30
BuyTarget = 30
IF Trend = 1 THEN
BUY 10 PERPOINT AT MARKET
SET STOP LOSS StopLossBuy
SET TARGET pPROFIT BuyTarget
ELSE
ENDIF
Is it due to day always being different to day[1] and so d will always = o and so vwap will always = 0 using d = 0 in the formula below …
if day<>day[1] then
d=0
else
d=d+1
if volume >0 then
VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
endif
it’s not the other way round
IF Close[0]<VWAP THEN
Trend= 1
ELSIF Close[0]> VWAP THEN
Trend = -1