Greetings, the following code exits a position on the same day as the entry at the close when run as a stand-alone strategy, however, when ran in meta strategy exits are on the following day’s open. Any thoughts on how to remedy this issue. As a side note tried a version of the code using ExecuteSessionOpen() (this also seemed much slower for some reason when using a large data set) and resulted in the same output differences.
CODE:
public override void Execute(BarHistory bars, int idx) { int index = idx; Position foundPosition0 = FindOpenPosition(0); if (HasOpenPosition(bars, PositionType.Short)!=true) { if ( idx > 90 & bars.Open[idx+1] < _MA[idx] & source[idx] >10 ) { val = multSource[idx]; _transaction = PlaceTrade(bars, TransactionType.Short, OrderType.Limit, val, 0, "sell "); PlaceTrade(bars, TransactionType.Cover, OrderType.MarketClose); } } }
Rename
QUOTE:
As a side note tried a version of the code using ExecuteSessionOpen() (this also seemed much slower for some reason when using a large data set) and resulted in the same output differences.
Did you follow Cone's suggestion to eliminate that peeking code i.e. bars.Open[idx+1]?
Yes I did, and using ExecuteSessionOpen() creates the same output as the above code. Also there seemed to be a major difference in run time using ExecuteSessionOpen() instead of bars.open[idx+1] which from my understanding is not actually peeking? My main issue is the different output in Meta Strategy.
Just for clarity, I get the same unexpected output using this as well,
CODE:
//execute the strategy rules here, this is executed once for each bar in the backtest history public override void ExecuteSessionOpen(BarHistory bars, int idx, double sessionOpenPrice) { int index = idx; Position foundPosition0 = FindOpenPosition(0); if (HasOpenPosition(bars, PositionType.Short)!=true) { if ( idx > 90 & sessionOpenPrice < _MA[idx] & source[idx] >10 ) { val = multSource[idx]; _transaction = PlaceTrade(bars, TransactionType.Short, OrderType.Limit, val, 0, "sell sdev"); PlaceTrade(bars, TransactionType.Cover, OrderType.MarketClose); } } }
I see it. In a MetaStrategy the MOC exit is occurring a bar too late, but at the previous day's closing price. We'll investigate!
Thanks!
I also observed exits being taken at or near the prior days close in meta strategy however exits seem to diverge quite a bit when the next day is a gap and the prior close is not traded.
Your Response
Post
Edit Post
Login is required