- ago
I attempted to convert the TASC 2016-04 | Trading Gap Reversals (Calhoun) WL6 code to WL8 as shown at http://www2.wealth-lab.com/WL5WIKI/TASCApr2016.ashx but I'm not getting any trades. Perhaps someone can correct the mistakes to get it running.
CODE:
using WealthLab.Backtest; using WealthLab.Core; namespace WealthScript3 {    public class TradingGapReversals : UserStrategyBase    {       //TASC 2016-04 | Trading Gap Reversals (Calhoun) conversion from WL6       // www2.wealth-lab.com/WL5WIKI/TASCApr2016.ashx by Eugene              Parameter gapPct, buyStp, sellStp;       TimeSeries trigger;       public TradingGapReversals()       {          gapPct = AddParameter("Gap %", ParameterType.Double, 10.0, 1.0, 30.0, 1.0);          buyStp = AddParameter("Buy stop", ParameterType.Double, 0.50, 0.10, 1.0, 0.1);          sellStp = AddParameter("Sell stop", ParameterType.Double, 0.40, 0.10, 1.0, 0.1);       }       public override void Initialize(BarHistory bars)       {          trigger = bars.Close * (1.0 - gapPct.AsDouble/100.0) >> 1;          StartIndex = 1;       }       public override void Execute(BarHistory bars, int idx)       {          Position p = LastPosition;                    if (HasOpenPosition(bars, PositionType.Long))          {             //sell conditions below             double amount = p.MFEAsOf(idx)/p.Quantity + p.EntryPrice - sellStp.AsDouble;             CloseAtTrailingStop(p, TrailingStopType.PointC, amount, "Trailing stop Sell");             PlaceTrade(bars,TransactionType.Sell,OrderType.Stop,p.EntryPrice-sellStp.AsDouble,"Initial stop Sell");          }          else if ( p == null || !p.IsOpen && p.EntryBar < (idx-bars.IntradayBarNumber(idx)) )          {             //buy conditions below             int firstBarToday = idx-bars.IntradayBarNumber(idx);             int lastBarYesterday = firstBarToday-1;             bool priceFilter = (bars.Close[firstBarToday] >= 20) && (bars.Close[firstBarToday] <= 70);             bool gap = (bars.Open[firstBarToday] <= trigger[lastBarYesterday]);             if (priceFilter && gap && bars.IntradayBarNumber(idx)>0)             {                Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Stop, bars.Low[firstBarToday] + buyStp.AsDouble, "Initial stop Buy");                t.AutoProfitTargetPrice = bars.Close[lastBarYesterday]; //set gap Close price             }          }       }              //same bar exits: 3% profit or loss from execution price       public override void AssignAutoStopTargetPrices(Transaction t, double basisPrice, double executionPrice)       {          t.AutoProfitTargetPrice = executionPrice * 1.03;          t.AutoStopLossPrice = executionPrice * 0.97;       }    } }
By the way, the above URL is not formatting the strategy code right. Perhaps someone can fix that.
0
228
6 Replies

Reply

Bookmark

Sort
- ago
#1
Your gap percent defaults to 10% which is pretty large for an intraday trading gap overnight. I ran with 10% for a number of different symbols and didn't get any trades. I set the gap to 2% and 1% and got a bunch of trades.
0
- ago
#2
QUOTE:
Your gap percent defaults to 10% which is pretty large for an intraday trading gap overnight... I set the gap to 2% and 1% and got a bunch of trades.

I agree 10% is pretty large. I tried running Daily bars at 1% and still got nothing. I'm not experienced with gap trading, so I don't fully understand the approach here. Perhaps if the stock misses it's earning estimate, there will be a big gap down, the strategy will buy it, then it will recover slowly over time. But I'm just guessing.

But there are more things about this strategy that bother me. Take the line below:
CODE:
int firstBarToday = idx-bars.IntradayBarNumber(idx);
If you're running Daily bars, you now have
CODE:
int firstBarToday = idx-(-1); //or ... int firstBarToday = idx+1;
That's not the first bar of the day, or am I missing something? Does firstBarToday mean tomorrow's bar since that's when the buying bar is placed? If so, then they should say entryBar instead (or proposedEntryBar).

My other concern is that I've never use the Transaction.AutoProfitTargetPrice property before. Nor have I used the AssignAutoStopTargetPrices() method before. I don't know if I'm using them correctly.
0
Cone8
 ( 7.72% )
- ago
#3
Don't run it on Daily data. Clearly it's programmed for intraday charts. It would be pretty easy to modify for daily though.
1
- ago
#4
How could it be modified to run with either Daily or Intraday data?
0
Cone8
 ( 7.72% )
- ago
#5
CODE:
         if (bars.IsIntraday)          {             // the strategy as written          }          else          {             // do something else          }
0
- ago
#6
Ha, ha. I thought you were going to post a solution. I know nothing about gap trading. Check my attempt below and make any corrections.
CODE:
   else    {       int firstBarToday = bars.IsIntraday ? idx-bars.IntradayBarNumber(idx) : idx;       if (p == null || !p.IsOpen && p.EntryBar < firstBarToday)       {          //buy conditions below          int lastBarYesterday = firstBarToday-1;          bool priceFilter = (bars.Close[firstBarToday] >= 20) && (bars.Close[firstBarToday] <= 70);          bool gap = (bars.Open[firstBarToday] <= trigger[lastBarYesterday]);          if (priceFilter && gap             && bars.IsIntraday ? bars.IntradayBarNumber(idx) > 0 : true)          {             Transaction t = PlaceTrade(bars, TransactionType.Buy, OrderType.Stop, bars.Low[firstBarToday] + buyStp.AsDouble, "Initial stop Buy");             t.AutoProfitTargetPrice = bars.Close[lastBarYesterday]; //set gap Close price          }       }    }
Also, in the above code, is the following line below always "true" and what is it's purpose? Could this strategy be trying to Buy and Sell multiple times on the same bar?
CODE:
!p.IsOpen && p.EntryBar < firstBarToday
Is there any other code that needs to be modified to make this strategy trade with Daily bars?
0

Reply

Bookmark

Sort