When the strategy executes and the EnterLongLimit order is placed, I should see the order on the chart. Chart Trader is active.
I confirm that that the order was filled via the script output window but nothing ever shows on the chart. It is a NES chart set to 5 ticks.
all default. It has Plot executions set to Text and marker. I am running the strategy under the Sim101 account.
Any thoughts on what I am missing? I am correct in that I should see my orders on the chart since Chart Trader is active.
I have setup a bool to act as a switch to trigger the market limit order right away.
Here is what I see in in the output window:
Trigger Maket Buy
Price 2
Trying to order...
5/3/2021 5:07:29 PM Strategy 'TestEntry2/231316416': Entered internal SubmitOrderManaged() method at 5/3/2021 5:07:29 PM: BarsInProgress=0 Action=Buy OrderType=Limit Quantity=1 LimitPrice=4181.75 StopPrice=0 SignalName='entryOrder' FromEntrySignal=''
orderId='NT-00000-1394' account='Sim101' name='entryOrder' orderState=Submitted instrument='MES 06-21' orderAction=Buy orderType='Limit' limitPrice=4181.75 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2021-05-03 17:07:29' gtd='2099-12-01' statementDate='2021-06-23'
orderId='NT-00000-1394' account='Sim101' name='entryOrder' orderState=Accepted instrument='MES 06-21' orderAction=Buy orderType='Limit' limitPrice=4181.75 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2021-05-03 17:07:29' gtd='2099-12-01' statementDate='2021-06-23'
orderId='NT-00000-1394' account='Sim101' name='entryOrder' orderState=Working instrument='MES 06-21' orderAction=Buy orderType='Limit' limitPrice=4181.75 stopPrice=0 quantity=1 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2021-05-03 17:07:29' gtd='2099-12-01' statementDate='2021-06-23'
Order Not Filled
orderId='NT-00000-1394' account='Sim101' name='entryOrder' orderState=Filled instrument='MES 06-21' orderAction=Buy orderType='Limit' limitPrice=4181.75 stopPrice=0 quantity=1 tif=Gtc oco='' filled=1 averageFillPrice=4181.5 onBehalfOf='' id=-1 time='2021-05-03 17:07:29' gtd='2099-12-01' statementDate='2021-06-23'
Order Filled
1
execution='NT-00000-1394' instrument='MES 06-21' account='Sim101' exchange=Default price=4181.5 quantity=1 marketPosition=Long orderId='NT-00000-1394' time='2021-05-03 17:07:51' sod=False statementDate='0001-01-01'
Enabling NinjaScript strategy 'TestEntry2/231316416' : On starting a real-time strategy - StartBehavior=WaitUntilFlat EntryHandling=All entries EntriesPerDirection=1 StopTargetHandling=Per entry execution ErrorHandling=Stop strategy, cancel orders, close positions ExitOnSessionClose=True / triggering 30 seconds before close SetOrderQuantityBy=Strategy ConnectionLossHandling=Recalculate DisconnectDelaySeconds=10 CancelEntriesOnStrategyDisable=False CancelExitsOnStrategyDisable=False Calculate=On bar close IsUnmanaged=False MaxRestarts=4 in 5 minutes
Here is my code:
#region Using declarations
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Xml.Serialization;
using NinjaTrader.Cbi;
using NinjaTrader.Gui;
using NinjaTrader.Gui.Chart;
using NinjaTrader.Gui.SuperDom;
using NinjaTrader.Gui.Tools;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript;
using NinjaTrader.Core.FloatingPoint;
using NinjaTrader.NinjaScript.Indicators;
using NinjaTrader.NinjaScript.DrawingTools;
#endregion
//This namespace holds Strategies in this folder and is required. Do not change it.
namespace NinjaTrader.NinjaScript.Strategies
{
public class TestEntry2 : Strategy
{
private Order entryOrder = null;
private bool xOrderFilled;
private bool xMoved;
private int xCurrentBar;
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Enter the description for your new custom Strategy here.";
Name = "TestEntry2";
Calculate = Calculate.OnBarClose;
EntriesPerDirection = 1;
EntryHandling = EntryHandling.AllEntries;
IsExitOnSessionCloseStrategy = true;
ExitOnSessionCloseSeconds = 30;
IsFillLimitOnTouch = false;
MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
OrderFillResolution = OrderFillResolution.Standard;
Slippage = 1;
StartBehavior = StartBehavior.WaitUntilFlat;
TimeInForce = TimeInForce.Gtc;
TraceOrders = true;
RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
StopTargetHandling = StopTargetHandling.PerEntryExecution;
BarsRequiredToTrade = 20;
// Disable this property for performance gains in Strategy Analyzer optimizations
// See the Help Guide for additional information
IsInstantiatedOnEachOptimizationIteration = true;
TriggerLimitBuy = false;
}
else if (State == State.Configure)
{
// SetTrailStop(Convert.ToString((GetCurrentAsk(0) + (2 * TickSize)) ), CalculationMode.Ticks, 2, false);
}
}
protected override void OnBarUpdate()
{
if (CurrentBars[0] < BarsRequiredToTrade)
return;
if (BarsInProgress != 0)
return;
if (CurrentBars[0] < 1)
return;
if (TriggerLimitBuy == true )
{
Print("Trigger Maket Buy");
Print( "Price " + (8 * TickSize));
// NEW CODE Start
if (Close[0] != Close[5] && xMoved != true)
{
Print("Trying to order...");
entryOrder = EnterLongLimit(0, true, 0, Low[0]-5*TickSize, "entryOrder"); //Submits limit order 5 ticks from current low, assigns it to MyOrder Order Object.
xMoved =true;
xCurrentBar = CurrentBar; //Sets value of current bar to build condition we used to modify the order if not filed.
}
else
{
Print("The close logic was not true no order attempted");
}
if(xOrderFilled == true)
{
Print("Filled");
}
else
{
Print("Order Not Filled");
if(CurrentBar> xCurrentBar+2) //
{
ChangeOrder(entryOrder, 1, Low[0] - 10*TickSize, 0); //Will adjust working limit to 10 ticks from current low.
Print("Order Changed");
}
}
// NEW CODE End
// EnterLongLimit(0, true, 1, Low[0], "entryOrder");
//EnterLong("entryOrder");
//EnterLongLimit(Convert.ToInt32(DefaultQuantity), (GetCurrentAsk(0) + (8 * TickSize)) , @"entryOrder");
TriggerLimitBuy = false;
}
}
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
{
// check if the current order matches the orderName passed in "EnterLong"()
// Assign entryOrder in OnOrderUpdate() to ensure the assignment occurs when expected.
// This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not guaranteed to be complete if it is referenced immediately after submitting
if (order.Name == "entryOrder")
entryOrder = order;
// if entry order exists
if (entryOrder != null && entryOrder == order)
{
Print(order.ToString());
if (order.OrderState == OrderState.Cancelled)
{
// Do something here
entryOrder = null;
}
}
}
protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
{
if (execution.Order.Name == "entryOrder")
{
Print("Order Filled");
Print(execution.Quantity.ToString());
Print(execution.ToString());
xOrderFilled= true;
xMoved =false;
}
}
#region Properties
[NinjaScriptProperty]
[Display(Name="TriggerLimitBuy", Description="Place a limt buy order", Order=1, GroupName="Parameters")]
public bool TriggerLimitBuy
{ get; set; }
#endregion
Comment