could anybody indicate why i get the following message (see attached) in my script:
1.
"Failed to Call ...."
I suspect it might have to do with a missing DataSeries I should report in the Initialize() method, but I am unable to figure it out;
2.
"An entry() method..Please search on the term Internal Order Handling.."
I suspect I am doing something wrong when placing my stop-loss, maybe because using ExitLongStop rather than Set() but this is what is advised in the tutorial, please could you help me solve this?
#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Indicator; using NinjaTrader.Strategy; #endregion namespace NinjaTrader.Strategy { [Description("")] public class PPPP : Strategy { #region Variables private IOrder entryOrderLong = null; private IOrder stopOrderLong = null; private IOrder entryOrderShort = null; private IOrder stopOrderShort = null; private double stopLoss = 0; private double AccBalNew = 0; private double AccountSize = 100000; private double Riskf = 1; private double Psize = 0; private double priorTradesCumProfit = 0; private double slippage = 3; #endregion protected override void Initialize() { CalculateOnBarClose = true; ExitOnClose = false; } protected override void OnBarUpdate() { #region Long Stop-Loss Adj //ADJUST STOP LOSS if (Position.MarketPosition == MarketPosition.Long && stopOrderLong != null) { if(Close[0] < Close[1] && Low[0] < Low[1]) { stopOrderLong = ExitLongStop(0, true, stopOrderLong.Quantity, Low[0]-slippage*TickSize, "New Stop-Loss", "Long"); } } #endregion #region Short Stop-Loss Adj //ADJUST STOP LOSS if (Position.MarketPosition == MarketPosition.Short && stopOrderShort != null) { if(Close[0] > Close[1] && High[0] > High[1]) { stopOrderShort = ExitShortStop(0, true, stopOrderShort.Quantity, High[0]+slippage*TickSize, "New Stop-Loss", "Short"); } } #endregion #region Long Entry if (Position.MarketPosition == MarketPosition.Flat && entryOrderLong ==null) { if(Close[0] >MAX(High,5)[1]) { stopLoss = High[0] - Low[0] + slippage * 2 * TickSize; PositionSize(); entryOrderLong = EnterLongStop(0, false, (int)Psize, High[0]+slippage*TickSize,"Long"); } } #endregion #region Short Entry if(Position.MarketPosition == MarketPosition.Flat && entryOrderShort ==null) { if(Close[0] < MIN(Low,5)[1]) { stopLoss = High[0] - Low[0] + slippage * 2 * TickSize; PositionSize(); entryOrderShort = EnterShortStop(0, false, (int)Psize, Low[0]-slippage*TickSize,"Short"); } } #endregion } protected override void OnOrderUpdate(IOrder order) { #region Reset Long Entry if (entryOrderLong != null && entryOrderLong == order) { if (order.OrderState == OrderState.Cancelled && order.Filled == 0) { entryOrderLong = null; } } #endregion #region Reset Short Entry if (entryOrderShort != null && entryOrderShort == order) { if (order.OrderState == OrderState.Cancelled && order.Filled == 0) { entryOrderShort = null; } } #endregion } protected override void OnExecution(IExecution execution) { #region Long Stop-Loss & Partial Fill Reset if (entryOrderLong != null && entryOrderLong == execution.Order) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { stopOrderLong = ExitLongStop(0, true, execution.Order.Filled, Low[0]-slippage*TickSize, "Stop-Loss", "Long"); } if (execution.Order.OrderState != OrderState.PartFilled) { entryOrderLong = null; } } #endregion #region Reset Long Stop-Loss & Target Profit if ((stopOrderLong != null && stopOrderLong == execution.Order)) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled) { stopOrderLong = null; } } #endregion #region Short Stop-Loss & Partial Fill Reset if (entryOrderShort != null && entryOrderShort == execution.Order) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { stopOrderShort = ExitShortStop(0, true, execution.Order.Filled, High[0]+slippage*TickSize, "Stop-Loss", "Short"); } if (execution.Order.OrderState != OrderState.PartFilled) { entryOrderShort = null; } } #endregion #region Reset Short Stop-Loss & Target Profit if ((stopOrderShort != null && stopOrderShort == execution.Order) ) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled) { stopOrderShort = null; } } #endregion } #region PositionSizeFunction //POSITION SIZING ONLY FOR DIRECT RATES void PositionSize() { priorTradesCumProfit = (double)Performance.AllTrades.TradesPerformance.Currency.CumProfit; AccBalNew = AccountSize + priorTradesCumProfit; Psize = Math.Round(AccBalNew * Riskf / 100 / stopLoss); //For fixed amount stopLoss to be defined as variable e.i. 50 pips = 50, then use formula: Psize = Math.Round(AccBalNew * Riskf / 100 / (stopLoss) / TickSize); Print(""); Print("New Account Balance: "+AccBalNew); Print("Time: "+Time[0]); Print("CumProfit: "+priorTradesCumProfit); Print("Position Size: "+Psize); } #endregion #region Properties [Description("Account Balance (US$)")] [Category("Parameters")] [Gui.Design.DisplayNameAttribute("\t\t\t\tAccount Balance (USD)")] public double AccBal { get { return AccountSize; } set { AccountSize = Math.Max(0, value); } } [Description("Risk Factor (%)")] [Category("Parameters")] [Gui.Design.DisplayNameAttribute("\t\t\tRisk Factor (%)")] public double RiskF { get { return Riskf; } set { Riskf = Math.Max(0, value); } } [Description("Slippage(Pips)")] [Category("Parameters")] [Gui.Design.DisplayNameAttribute("\t\t\t\tSlippage(Pips)")] public double Slippage { get { return slippage; } set { slippage = Math.Max(0, value); } } #endregion } }
Comment