- ago
The following code is testable. According to discuss, the position is not created during intraday. How to code intraday limit order ?

CODE:
public override void Execute(BarHistory bars, int idx) {          int index = idx;          Position foundPosition0 = FindOpenPosition(0);          if (foundPosition0 == null)          {             PlaceTrade(bars, TransactionType.Buy, OrderType.Limit, bars.Close[idx]*0.99, 0);                       }          else          {             ClosePosition(foundPosition0, OrderType.Limit, foundPosition0.EntryPrice * 0.97);                      } }
0
1,210
Solved
3 Replies

Reply

Bookmark

Sort
Glitch8
 ( 10.62% )
- ago
#1
A limit order, by nature, often executes intraday. WL7 will simulate this, and you will see the little circle in the fill marker appear in the middle of the bar, at precisely the intraday fill price. If prices open up below the limit price, the order will get filled at market open, just like in real trading.
0
- ago
#2
Thanks Glitch.

Above code is WL7 sample code and works for daily bar.
Question:
1) if 5 min bar is used, is above code still corrected?

2) If not, can we use _transaction.IsActive, instead of checking position count, to create a single entry strategy? Looks like _transaction do not have an EntryBar property? Can someone create a sample code?

Thanks a lot.

0
Cone8
 ( 4.98% )
- ago
#3
Question:
1) Sure. Strategy code always operate on the time scale of the data you load in the Strategy Settings.

2)Use the template code that comes with WL7. if (!HasOpenPosition ... ) does the trick for a single entry strategy.

CODE:
//execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } }
0
Best Answer

Reply

Bookmark

Sort