2008-09-17 00:00:00 Entered internal PlaceOrder() method at 2008-09-17 00:00:00: Action=SellShort OrderType=Limit [COLOR=Blue]Quantity=1[/COLOR] LimitPrice=16,93 StopPrice=0 SignalName='Short 1a' FromEntrySignal='' 2008-09-17 00:00:00 Entered internal PlaceOrder() method at 2008-09-17 00:00:00: Action=SellShort OrderType=Limit [COLOR=Blue]Quantity=1[/COLOR] LimitPrice=16,93 StopPrice=0 SignalName='Short 1b' FromEntrySignal='' 2008-09-17 00:00:00 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Short 1a' Mode=Price Value=19,706193831847 Currency=0 Simulated=False 2008-09-17 00:00:00 Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Short 1a' Mode=Price Value=11,3677523306809 Currency=0 Simulated=False 2008-09-17 00:00:00 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='Short 1b' Mode=Price Value=20,706193831847 Currency=0 Simulated=False 2008-09-17 00:00:00 Entered internal SetStopTarget() method: Type=Target FromEntrySignal='Short 1b' Mode=Price Value=4,80879132990353 Currency=0 Simulated=False 2008-09-18 00:00:00 Amended target order: Order='NT-00003/Sim101' Name='Profit target' State=Working Instrument='C' Action=BuyToCover Limit price=11,37 Stop price=0 [COLOR=Red]Quantity=2[/COLOR] Strategy='ScaleOutTEST' Type=Limit Tif=Gtc Oco='NT-00000' Filled=0 Fill price=0 Token='2d34b5b7fe454bb89e6fd3fe6665c296' Gtd='2099-12-01 00:00:00' 2008-09-18 00:00:00 Amended stop order: Order='NT-00002/Sim101' Name='Stop loss' State=Working Instrument='C' Action=BuyToCover Limit price=0 Stop price=19,71 [COLOR=Red]Quantity=2[/COLOR] Strategy='ScaleOutTEST' Type=Stop Tif=Gtc Oco='NT-00000' Filled=0 Fill price=0 Token='c2ec966c88594edab96b9fd399f9a4eb' Gtd='2099-12-01 00:00:00' 2008-09-18 00:00:00 Amended target order: Order='NT-00005/Sim101' Name='Profit target' State=Working Instrument='C' Action=BuyToCover Limit price=4,81 Stop price=0 [COLOR=Red]Quantity=2[/COLOR] Strategy='ScaleOutTEST' Type=Limit Tif=Gtc Oco='NT-00001' Filled=0 Fill price=0 Token='06a6dc8703744aa286ff338449075661' Gtd='2099-12-01 00:00:00' 2008-09-18 00:00:00 Amended stop order: Order='NT-00004/Sim101' Name='Stop loss' State=Working Instrument='C' Action=BuyToCover Limit price=0 Stop price=20,71 [COLOR=Red]Quantity=2[/COLOR] Strategy='ScaleOutTEST' Type=Stop Tif=Gtc Oco='NT-00001' Filled=0 Fill price=0 Token='3ca2640c58b84968b5028652fcb48ea1' Gtd='2099-12-01 00:00:00' 2008-09-18 00:00:00 Cancelled pending exit order, since associated position is closed: Order='NT-00003/Sim101' Name='Profit target' State=Working Instrument='C' Action=BuyToCover Limit price=11,37 Stop price=0 [COLOR=Red]Quantity=2[/COLOR] Strategy='ScaleOutTEST' Type=Limit Tif=Gtc Oco='NT-00000' Filled=0 Fill price=0 Token='2d34b5b7fe454bb89e6fd3fe6665c296' Gtd='2099-12-01 00:00:00' 2008-09-18 00:00:00 Cancelled OCO paired order: BarsInProgress=0: Order='NT-00003/Sim101' Name='Profit target' State=Cancelled Instrument='C' Action=BuyToCover Limit price=11,37 Stop price=0 [COLOR=Red]Quantity=2 [/COLOR]Strategy='ScaleOutTEST' Type=Limit Tif=Gtc Oco='NT-00000' Filled=0 Fill price=0 Token='2d34b5b7fe454bb89e6fd3fe6665c296' Gtd='2099-12-01 00:00:00' 2008-09-18 00:00:00 Cancelled pending exit order, since associated position is closed: Order='NT-00005/Sim101' Name='Profit target' State=Working Instrument='C' Action=BuyToCover Limit price=4,81 Stop price=0 [COLOR=Red]Quantity=2 [/COLOR]Strategy='ScaleOutTEST' Type=Limit Tif=Gtc Oco='NT-00001' Filled=0 Fill price=0 Token='06a6dc8703744aa286ff338449075661' Gtd='2099-12-01 00:00:00' 2008-09-18 00:00:00 Cancelled OCO paired order: BarsInProgress=0: Order='NT-00005/Sim101' Name='Profit target' State=Cancelled Instrument='C' Action=BuyToCover Limit price=4,81 Stop price=0 [COLOR=Red]Quantity=2 [/COLOR]Strategy='ScaleOutTEST' Type=Limit Tif=Gtc Oco='NT-00001' Filled=0 Fill price=0 Token='06a6dc8703744aa286ff338449075661' Gtd='2099-12-01 00:00:00'
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
What does the trace output mean?
Collapse
X
-
What does the trace output mean?
Hi! I'v programed a simple strategy based on your SampleScaleOut strategy that submits two entry orders with quantity = 1 and the names "long1a" and "long1b". I use the SetStopLoss() and SetProfitTarget() method in OnPositionUpdate() to submit entry orders. When I read the trace ouput I see that when the orders get filled the trace file writes that the Quantity is 2. How come? Does this quantity refer to the position quantity or to the order quantity?
Code:Tags: None
-
Hi!
Here is the strategy. I also attached a screenshot of the diagram.
Code:// This namespace holds all strategies and is required. Do not change it. namespace NinjaTrader.Strategy { /// <summary> /// Enter the description of your strategy here /// </summary> [Description("Enter the description of your strategy here")] public class ScaleOutTEST : Strategy { #region Variables // Wizard generated variables // User defined variables (add any user defined variables below) // Deklarera variabler private double Enter; private double SL; private double Target1; private double Target2; int Orderquantity = 1; //Skapa IOrder objekt private IOrder EnterLong1a = null; // This variable holds an object representing our enter order private IOrder EnterLong1b = null; // This variable holds an object representing our enter order private IOrder EnterShort1a = null; // This variable holds an object representing our enter order private IOrder EnterShort1b = null; // This variable holds an object representing our enter order #endregion /// <summary> /// This method is used to configure the strategy and is called once before any strategy method is called. /// </summary> protected override void Initialize() { /* The following settings configure your strategy to execute only one entry for each uniquely named entry signal. This can be configured in the Initalize() method or via the Strategy dialog window when running or backtesting a strategy */ EntriesPerDirection = 1; EntryHandling = EntryHandling.UniqueEntries; TimeInForce = Cbi.TimeInForce.Gtc; // (EoD strategy) TraceOrders = true; CalculateOnBarClose = true; } /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() { //calculate and asign/ reset the local varaibles Enter, SL, Taregt1 and Target2 prior to an order execution. if (Position.MarketPosition == MarketPosition.Flat) // { if (EMA(18)[0] >= EMA(55)[0]) { Enter = EMA(High, 18)[0]; SL = Enter - 2* ATR(18)[0]; Target1 = Enter + 4* ATR(18)[0]; Target2 = Enter + 8* ATR(18)[0]; } else { Enter = EMA(Low, 18)[0]; SL = Enter + 2* ATR(18)[0]; Target1 = Enter - 4* ATR(18)[0]; Target2 = Enter - 8* ATR(18)[0]; } } //Keep the variables Enter, SL, Taregt1 and Target2 contsant during a psotion to avoid extra comission due to order modification else if (Position.MarketPosition == MarketPosition.Long) { Enter = EMA(High, 18)[BarsSinceEntry(0, "Long 1a", 0)]; SL = Enter - 2* ATR(18)[BarsSinceEntry(0, "Long 1a", 0)]; Target1 = Enter + 4* ATR(18)[BarsSinceEntry(0, "Long 1a", 0)]; Target2 = Enter + 8* ATR(18)[BarsSinceEntry(0, "Long 1a", 0)]; } else if (Position.MarketPosition == MarketPosition.Short) { Enter = EMA(Low, 18)[BarsSinceEntry(0, "Short 1a", 0)]; SL = Enter + 2* ATR(18)[BarsSinceEntry(0, "Short 1a", 0)]; Target1 = Enter - 4* ATR(18)[BarsSinceEntry(0, "Short 1a", 0)]; Target2 = Enter - 8* ATR(18)[BarsSinceEntry(0, "Short 1a", 0)]; } // Only allow entries if we have no current positions open if (Position.MarketPosition == MarketPosition.Flat) { if (CrossAbove(EMA(18), EMA(55), 1)) { /* Enters two long positions. We submit two orders to allow us to be able to scale out half of the position at a time in the future. With individual entry names we can differentiate between the first half and the second half of our long position. */ EnterLong1a = EnterLongLimit(Orderquantity, Enter, "Long 1a"); EnterLong1b = EnterLongLimit(Orderquantity, Enter, "Long 1b"); } else if (CrossBelow(EMA(18), EMA(55), 1)) { /* Enters two short positions. We submit two orders to allow us to be able to scale out half of the position at a time in the future. With individual entry names we can differentiate between the first half and the second half of our long position. */ EnterShort1a = EnterShortLimit(Orderquantity, Enter, "Short 1a"); EnterShort1b = EnterShortLimit(Orderquantity, Enter, "Short 1b"); } } } protected override void OnExecution(IExecution execution) { /* We advise monitoring OnExecution to trigger submission of stop/target orders instead of OnOrderUpdate() since OnExecution() is called after OnOrderUpdate() which ensures your strategy has received the execution which is used for internal signal tracking. */ // Check and submit StopLoss and ProfitTarget orders for each fill if (EnterLong1a != null && EnterLong1a.Token == execution.Order.Token) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { // Submit the EXIT-orders which will be tied to entry order "Long 1a" SetStopLoss("Long 1a", CalculationMode.Price, SL, false); SetProfitTarget("Long 1a", CalculationMode.Price, Target1); // Resets the entryOrder object to null after the order has been partially filled if (execution.Order.OrderState != OrderState.PartFilled) { EnterLong1a = null; } } } // Check and submit StopLoss and ProfitTarget orders for each fill if (EnterLong1b != null && EnterLong1b.Token == execution.Order.Token) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { // Submit the EXIT-orders which will be tied to entry order "Long 1b" SetStopLoss("Long 1b", CalculationMode.Price, SL, false); SetProfitTarget("Long 1b", CalculationMode.Price, Target2); // Resets the entryOrder object to null after the order has been partially filled if (execution.Order.OrderState != OrderState.PartFilled) { EnterLong1b = null; } } } // Check and submit StopLoss and ProfitTarget orders for each fill if (EnterShort1a != null && EnterShort1a.Token == execution.Order.Token) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { // Submit the EXIT-orders which will be tied to entry order "Short 1a" SetStopLoss("Short 1a", CalculationMode.Price, SL, false); SetProfitTarget("Short 1a", CalculationMode.Price, Target1); // Resets the entryOrder object to null after the order has been partially filled if (execution.Order.OrderState != OrderState.PartFilled) { EnterShort1a = null; } } } // Check and submit StopLoss and ProfitTarget orders for each fill if (EnterShort1b != null && EnterShort1b.Token == execution.Order.Token) { if (execution.Order.OrderState == OrderState.Filled || execution.Order.OrderState == OrderState.PartFilled || (execution.Order.OrderState == OrderState.Cancelled && execution.Order.Filled > 0)) { // Submit the EXIT-orders which will be tied to entry order "Short 1b" SetStopLoss("Short 1b", CalculationMode.Price, SL, false); SetProfitTarget("Short 1b", CalculationMode.Price, Target2); // Resets the entryOrder object to null after the order has been partially filled if (execution.Order.OrderState != OrderState.PartFilled) { EnterShort1b = null; } } } } #region Properties #endregion } }
Comment
-
Andreas, please ensure you rerun this with Order Handling set to 'PerEntryExecution' under Tools > Options > Strategies > NinjaScript - http://www.ninjatrader-support.com/H...tegiesTab.htmlBertrandNinjaTrader Customer Service
Comment
-
Thanks, now when I set the Order Handling option to 'PerEntryExecution' the order quantity in the trace file is 1 as expected.
Since I had equities in mind for this strategy, I set the option for Order Handling to 'ByStrategyPosition'. Would there be any problem if I run this strategy live with the option for Order Handling set to 'ByStrategyPosition', besides the trace output displaying the wrong orderquantity?
Another question that comes to my mind is what if you want to run strategies for equities and futures at the same time? How can I set the Order Handling option on strategy level?
/AndreasLast edited by poseidon_sthlm; 01-11-2010, 01:40 PM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by sdauteuil, 09-23-2021, 10:16 AM
|
4 responses
1,208 views
0 likes
|
Last Post Today, 11:41 PM | ||
Started by agclub, 04-21-2024, 08:57 PM
|
5 responses
34 views
0 likes
|
Last Post
by agclub
Today, 09:47 PM
|
||
Started by ESHunter, Today, 08:06 PM
|
2 responses
18 views
0 likes
|
Last Post
by ESHunter
Today, 09:27 PM
|
||
Started by ETFVoyageur, 05-07-2024, 07:05 PM
|
19 responses
150 views
0 likes
|
Last Post
by ETFVoyageur
Today, 09:14 PM
|
||
Started by ETFVoyageur, Yesterday, 10:13 PM
|
3 responses
26 views
0 likes
|
Last Post
by ETFVoyageur
Today, 09:08 PM
|
Comment