Could you please, check the below code, Buys once per day at Daily VWAP
// Set the timeframe to daily for VWAP calculations
TIMEFRAME (DAILY)
//VWAP calculation
//
NoSunday = 0 //1=skip Sunday's
IF (BarIndex = 0) OR (OpenDay <> OpenDay[1]) THEN
SumVolPrice = 0
SumVol = 0
ENDIF
IF Volume > 0 THEN
IF (OpenDayOfWeek <> 0) OR (OpenDayOfWeek = 0 AND Not NoSunday) THEN
SumVolPrice = SumVolPrice + (Volume * close)
SumVol = SumVol + Volume
dailyVWAP = SumVolPrice / SumVol
ENDIF
// Reset flags at the beginning of each new trading day
IF IntradayBarIndex = 0 THEN
flagDailyVWAP = 0
ENDIF
// Buy condition at VWAP levels (trigger only once per day)
IF low <= dailyVWAP AND flagDailyVWAP = 0 THEN
BUY 20 CONTRACT AT MARKET
flagDailyVWAP = 1
ENDIF
JSParticipant
Senior
Try this one, I’ve done some small adjustment…
DefParam CumulateOrders=False
TIMEFRAME (DAILY)
NoSunday = 0 // 1 = Skip zondag
// Reset VWAP-calculation every new day
IF (BarIndex = 0) OR (OpenDay <> OpenDay[1]) THEN
SumVolPrice = 0
SumVol = 0
flagDailyVWAP = 0 // Reset flag
ENDIF
// VWAP-calculation
IF Volume > 0 THEN
IF (OpenDayOfWeek <> 0) OR (OpenDayOfWeek = 0 AND NOT NoSunday) THEN
SumVolPrice = SumVolPrice + (Volume * close)
SumVol = SumVol + Volume
ENDIF
ENDIF
// Calculate daily VWAP (outside the IF Volume > 0)
IF SumVol > 0 THEN
dailyVWAP = SumVolPrice / SumVol
ENDIF
// Buy once a day when LOW <= VWAP
IF low <= dailyVWAP AND flagDailyVWAP = 0 THEN
BUY 1 CONTRACT AT MARKET
flagDailyVWAP = 1 // No more orders that day
ENDIF
GraphOnPrice dailyVWAP as "DailyVWAP"
Graph SumVol as "SumVol"
Graph SumVolPrice as "SumVolPrice"