vwap strategy intraday timeframe help needed

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #160522 quote
    abraxas
    Participant
    Junior

    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

    // Definition of code parameters
    DEFPARAM 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" time
    DEFPARAM FLATAFTER = 220000
    // ---parameters
    MaxDailyProfit=10000 //Max daily profit allowed (in money)
    MaxDailyLoss=300 //Max daily loss allowed  (in money)
     
    // first time we launch the code, the trading is allowed
    once TradeAllowed=1
     
    // reset the current state of the strateygprofit each new day
    If intradaybarindex=0 then
    MyProfit=STRATEGYPROFIT
    TradeAllowed=1
    endif
     
    // test if the strategyprofit of the day is currently above the daily profit allowed of below the daily loss allowed
    If StrategyProfit>=MyProfit+MaxDailyProfit or Strategyprofit<=MyProfit-MaxDailyLoss then
    TradeAllowed=0
    endif
     
    
    
    //trending days
    longday = (close > DHigh(1))
    shortday = (close < DLow (1))
    //inside days
    swingday = (close < DHigh (1)) and (close > Dlow (1))
    
    
    //bollinger and vwap definitions
    
    bollup = 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 entry
    if longday and not longonmarket and TradeAllowed=1 and oversold then
    BUY 1 CONTRACT AT MARKET
    elsif shortday and not shortonmarket and TradeAllowed=1 and overbought then
    SELLSHORT 1 contract AT MARKET
    elsif swingday and not longonmarket and TradeAllowed=1 and under3std and oversold then
    buy 1 contract at market
    elsif not shortonmarket and swingday and TradeAllowed=1 and over3std and overbought then
    sellshort 1 contract at market
    endif
    
    //exit
    if longonmarket and longday  and ( over3std or stoplong)then
    sell at market
    elsif shortonmarket and shortday and (stopshort or under3std) then
    exitshort at market
    elsif longonmarket and swingday and (stopshort or under3std) then
    sell at market
    elsif shortonmarket and swingday and ( over3std or stoplong) then
    exitshort at market
    endif
    
    // Stops and targets
    SET STOP pLOSS 50
    
    #160674 quote
    robertogozzi
    Moderator
    Master

    You 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:

    swingday = (DHigh(0) < DHigh (1)) and (DLow(0) > Dlow (1))
    abraxas thanked this post
    #161237 quote
    abraxas
    Participant
    Junior
    // Definition of code parameters
    DEFPARAM 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" time
    DEFPARAM FLATAFTER = 220000
    // ---parameters
    MaxDailyProfit=10000 //Max daily profit allowed (in money)
    MaxDailyLoss=80 //Max daily loss allowed  (in money)
     
    // first time we launch the code, the trading is allowed
    once TradeAllowed=1
     
    // reset the current state of the strateygprofit each new day
    If intradaybarindex=0 then
    MyProfit=STRATEGYPROFIT
    TradeAllowed=1
    endif
     
    // test if the strategyprofit of the day is currently above the daily profit allowed of below the daily loss allowed
    If StrategyProfit>=MyProfit+MaxDailyProfit or Strategyprofit<=MyProfit-MaxDailyLoss then
    TradeAllowed=0
    endif
     
    
    //trending days
    longday = (close > DHigh(1))
    shortday =(close < DLow(1))
    //inside days
    swingday = ((DHigh(0) < DHigh(1)) and (DLow(0) > DLow(1)))
    
    //bollinger and vwap definitions
    
    bollup = 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 entry
    
    if longday THEN
    if not longonmarket and TradeAllowed=1 and oversold then
    S=1
    BUY 1 CONTRACT AT MARKET
    elsif longonmarket and S1stop  and S=1 then
    sell at market
    endif
    else
    if shortday  then
    if not shortonmarket and TradeAllowed=1 and overbought then
    S=2
    SELLSHORT 1 contract AT MARKET
    elsif shortonmarket and S2stop then
    exitshort at market
    endif
    else
    if swingday then
    if not longonmarket and TradeAllowed=1 and under3std and oversold then
    S=3
    buy 1 contract at market
    elsif swingday and longonmarket and S3stop then
    sell at market
    elsif swingday then
    if not shortonmarket and TradeAllowed=1 and over3std and overbought then
    S=4
    sellshort 1 contract at market
    elsif swingday and shortonmarket and S4stop then
    exitshort at market
    endif
    endif
    endif
    endif
    endif
    
    
    // Stops and targets
    
    SET STOP pLOSS 50
    

    Thanks 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

    NASDAQ-3-minutes.png NASDAQ-3-minutes.png
    #161247 quote
    robertogozzi
    Moderator
    Master

    I suggest that you append these lines to your code:

    graph SwingDay
    graph ShortDay
    graph LongDay
    graph S1Stop
    graph 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).

    abraxas thanked this post
    x-4.jpg x-4.jpg
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

vwap strategy intraday timeframe help needed


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
abraxas @abraxas Participant
Summary

This topic contains 3 replies,
has 2 voices, and was last updated by robertogozzi
5 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/06/2021
Status: Active
Attachments: 2 files
Logo Logo
Loading...