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