vwap strategy intraday timeframe help needed
Forums › ProRealTime English forum › ProOrder support › vwap strategy intraday timeframe help needed
- This topic has 3 replies, 2 voices, and was last updated 4 years ago by
robertogozzi.
-
-
02/06/2021 at 4:51 PM #160522
Hiya
I’m trying to set up this intraday strategy based on vwap, but I think I miss how to properly define trending days and inside days.
Concept is: if price breaks out of previous day high or low, it will continue on that direction (maybe retesting those levels for confirmation of direction… not sure how to code this), so I’m setting a buy on weakness (low bollinger) ,a target based on 3std deviations from vwap (using prc vwap intraday indicator, as the built in vwap can’t be used in proorder apparently), and the vwap acts as a trailing stop.
If the price action is between previous days high or low I’ll short on strenght (upper bollinger, and over 3 std devs from vwap )/buy on weakness(lower bollinger and under 3 std dev from vwap ) with vwap as a target.
What does not seem to work is the definition of long/short days and inside/swing days, as I’ve seen the strategy going long/short also when price isn’t above or below previous days highs or lows..
Any help will be much appreciated!
Cheers
A
vwap strategy12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.DEFPARAM FLATBEFORE = 080000// Cancel all pending orders and close all positions at the "FLATAFTER" timeDEFPARAM FLATAFTER = 220000// ---parametersMaxDailyProfit=10000 //Max daily profit allowed (in money)MaxDailyLoss=300 //Max daily loss allowed (in money)// first time we launch the code, the trading is allowedonce TradeAllowed=1// reset the current state of the strateygprofit each new dayIf intradaybarindex=0 thenMyProfit=STRATEGYPROFITTradeAllowed=1endif// test if the strategyprofit of the day is currently above the daily profit allowed of below the daily loss allowedIf StrategyProfit>=MyProfit+MaxDailyProfit or Strategyprofit<=MyProfit-MaxDailyLoss thenTradeAllowed=0endif//trending dayslongday = (close > DHigh(1))shortday = (close < DLow (1))//inside daysswingday = (close < DHigh (1)) and (close > Dlow (1))//bollinger and vwap definitionsbollup = Average [10](close)+1.9*std[10](close)bolldown = Average[10](close)-1.9*std[10](close)overbought = (close >= bollup)oversold = (close <= bolldown)ignored, ignored, ignored, ignored, ignored, ignored, indicator7 = CALL "PRC_VWAP intraday"ignored, ignored, ignored, ignored, ignored, indicator6, ignored = CALL "PRC_VWAP intraday"indicator1, ignored, ignored, ignored, ignored, ignored, ignored = CALL "PRC_VWAP intraday"over3std = (close => indicator6)under3std = (close =< indicator7)stoplong = (close < indicator1)stopshort = (close > indicator1)//long entryif longday and not longonmarket and TradeAllowed=1 and oversold thenBUY 1 CONTRACT AT MARKETelsif shortday and not shortonmarket and TradeAllowed=1 and overbought thenSELLSHORT 1 contract AT MARKETelsif swingday and not longonmarket and TradeAllowed=1 and under3std and oversold thenbuy 1 contract at marketelsif not shortonmarket and swingday and TradeAllowed=1 and over3std and overbought thensellshort 1 contract at marketendif//exitif longonmarket and longday and ( over3std or stoplong)thensell at marketelsif shortonmarket and shortday and (stopshort or under3std) thenexitshort at marketelsif longonmarket and swingday and (stopshort or under3std) thensell at marketelsif shortonmarket and swingday and ( over3std or stoplong) thenexitshort at marketendif// Stops and targetsSET STOP pLOSS 5002/08/2021 at 12:38 PM #160674You are only checking if the CURRENT prive (which is CLOSE) is within the yesterday’s boundaries, not if the WHOLE current day is within yesterday’s range. Try replacing line 31 with:
1swingday = (DHigh(0) < DHigh (1)) and (DLow(0) > Dlow (1))1 user thanked author for this post.
02/12/2021 at 8:09 PM #161237vwap strategy12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.DEFPARAM FLATBEFORE = 080000// Cancel all pending orders and close all positions at the "FLATAFTER" timeDEFPARAM FLATAFTER = 220000// ---parametersMaxDailyProfit=10000 //Max daily profit allowed (in money)MaxDailyLoss=80 //Max daily loss allowed (in money)// first time we launch the code, the trading is allowedonce TradeAllowed=1// reset the current state of the strateygprofit each new dayIf intradaybarindex=0 thenMyProfit=STRATEGYPROFITTradeAllowed=1endif// test if the strategyprofit of the day is currently above the daily profit allowed of below the daily loss allowedIf StrategyProfit>=MyProfit+MaxDailyProfit or Strategyprofit<=MyProfit-MaxDailyLoss thenTradeAllowed=0endif//trending dayslongday = (close > DHigh(1))shortday =(close < DLow(1))//inside daysswingday = ((DHigh(0) < DHigh(1)) and (DLow(0) > DLow(1)))//bollinger and vwap definitionsbollup = Average [10](close)+1.9*std[10](close)bolldown = Average[10](close)-1.9*std[10](close)overbought = (close >= bollup)oversold = (close <= bolldown)ignored, ignored, ignored, ignored, ignored, ignored, indicator7 = CALL "PRC_VWAP intraday"ignored, ignored, ignored, ignored, ignored, indicator6, ignored = CALL "PRC_VWAP intraday"indicator1, ignored, ignored, ignored, ignored, ignored, ignored = CALL "PRC_VWAP intraday"over3std = (close[1] => indicator6)under3std = (close[1] =< indicator7)stoplong = (close[1] < indicator1)stopshort = (close[1] > indicator1)S1stop = (over3std or stoplong)S2stop = (stopshort or under3std)S3stop = (stopshort or under3std)S4stop = (over3std or stoplong)//long entryif longday THENif not longonmarket and TradeAllowed=1 and oversold thenS=1BUY 1 CONTRACT AT MARKETelsif longonmarket and S1stop and S=1 thensell at marketendifelseif shortday thenif not shortonmarket and TradeAllowed=1 and overbought thenS=2SELLSHORT 1 contract AT MARKETelsif shortonmarket and S2stop thenexitshort at marketendifelseif swingday thenif not longonmarket and TradeAllowed=1 and under3std and oversold thenS=3buy 1 contract at marketelsif swingday and longonmarket and S3stop thensell at marketelsif swingday thenif not shortonmarket and TradeAllowed=1 and over3std and overbought thenS=4sellshort 1 contract at marketelsif swingday and shortonmarket and S4stop thenexitshort at marketendifendifendifendifendif// Stops and targetsSET STOP pLOSS 50Thanks for the reply, I’ve rearranged the code a bit, but another issue came out:
Entered a long position with conditions defined in “longday” (so price was higher than the previous day high) but did not exit the position at vwap as supposed to. I think that’s because vwap was inside the previous day high and low, so maybe the system changed form “longday” to “swingday”. But still one of the condition to close longs on inside days is for the price to be above vwap (as a target), so I’m not sure what the code reads in this case, eventually the code closed the position with the stoploss, so it completely ignored the stops also for the inside day strategy as price did pass below vwaps low 3 std dev.
I’ve attached a picture with my comments, and the new code above.
Cheers!
A
02/13/2021 at 1:30 AM #161247I suggest that you append these lines to your code:
12345graph SwingDaygraph ShortDaygraph LongDaygraph S1Stopgraph S2Stop(and you may add more) they will help you spot any wrong value at any given bar in the variable window that ProBackTest opens (only when GRAPH is used).
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on