- ago
Hello,

While a "Market" order correctly ignores any non-zero limit price, but it seems that a "MarketClose" order with a non-zero limit price can generate ghost trades. Please see the code and the snippet below:

CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using WealthLab.ChartWPF; using System.Drawing; using System.Collections.Generic; namespace WealthScript27 {    public class MyStrategy : UserStrategyBase    {       //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {          rsi = new RSI(bars.Close, 14);          PlotIndicator(rsi);       }       //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))             {             if (rsi[idx] < 30)                PlaceTrade(bars, TransactionType.Buy, OrderType.Market);          }          else          {             Position p = LastPosition;             //exit after 3 days             if (idx + 1 - p.EntryBar >= 3)                PlaceTrade(bars, TransactionType.Sell, OrderType.MarketClose, p.EntryPrice + 0.1);          }       }       //declare private variables below       private RSI rsi;    } }




0
839
1 Replies

Reply

Bookmark

Sort
- ago
#1
Hi,

MarketClose orders are not intended to be used with a price. You should remove it from the code.
0

Reply

Bookmark

Sort