I am trying to set up some code to trade XIV, which is the VelocitySHares Daily Inverse VIX Short. In real basic terms, here is what I am trying to achieve:
1. Buy XIV tomorrow at tomorrow's Close, when today's Low is > yesterday's Low
2. Sell XIV tomorrow at tomorrow's Close, when today's Low is < yesterday's Low
Basically, if you look at a chart, I want to buy the day after XIV has made a higher low. Inversely, I want to get out of that position the day after the XIV made a lower low than the day before.
Here is what I have coded so far but can't make it work. Seems simple but for the life of me I can't get it to act correctly. Anyone on this board able to help - is it a simple thing I missed or am I approaching it all wrong?
Code://///* Strategy : basic higher lows /////* 1.Buy tomorrow at tomorrow's Close, when today's Low is > yesterday's Low /////* 2.Sell tomorrow at tomorrow's Close, when today's Low is < yesterday's Low SetFormulaName("HigherLowsStrategy"); /*name it for backtest report identification*/ SetOption( "initialequity", 5000 ); /* starting capital */ SetOption( "MaxOpenPositions", 1 ); SetOption( "CommissionMode", 3 ); /* set commissions AND costs as $ per trade */ SetOption( "CommissionAmount", 0.005 ); /* commissions AND cost */ //SetTradeDelays(1,1,1,1); /* Buy and sell on next bar - will be close due to BuyPrice=SellPrice = Close */ YesterdaysLow = Ref( L, -1 ); TodaysLow = L; Buy = Ref(ROC(L, 1 ) > 0, -1 ); Sell = TodaysLow < YesterdaysLow; BuyPrice = SellPrice = Close; Buy = ExRem(Buy,Sell); Sell = ExRem(Sell,Buy);