EnterLongLimit(tradeParams.max, Bars.LastPrice); ExitLongLimit(tradeParams.max, Bars.LastPrice + TickSize * 2); ExitLongStopLimit(tradeParams.max, Bars.LastPrice - TickSize * 5);
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
Can't place several orders
Collapse
X
-
Can't place several orders
In my strategy, when I got some signal, I want to enter into a position with current price and then set Take-limit-order and Stop-limit-order. I write this code:
Code:Tags: None
-
Hello Defake,
The ExitLongLimit and ExitLongStopLimit would not be placed until the entry order is filled.
Under tips at the following section of our helpguide for ExitLongLimit you will see,
This method is ignored if a long position does not exist
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
-
Originally posted by NinjaTrader_AlanP View PostHello Defake,
The ExitLongLimit and ExitLongStopLimit would not be placed until the entry order is filled.
Under tips at the following section of our helpguide for ExitLongLimit you will see,
This method is ignored if a long position does not exist
Please let us know if you need further assistance.
Okay, I read example from http://ninjatrader.com/support/helpG...r_handling.htm
And try to repeat this in my strategy. But anyway I can't place exit orders even if the enter order is already filled.
Placing enter order:
Code:if (Position.Quantity == 0 && curOrder == null) { if (decision > 0) { curOrder = EnterLongLimit(tradeParams.max, Bars.LastPrice, "EnterOrder"); toLongOrder = true; } else if (decision < 0) { curOrder = EnterShortLimit(tradeParams.max, Bars.LastPrice, "EnterOrder"); toLongOrder = false; } }
Code:protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError) { // if exited from trade, clear all remaining orders (e.g. remaining stop order) if (order.Name == "ExitOrder" && orderState == OrderState.Filled) Orders.Clear(); // if Enter order is filled, place exit orders if (curOrder != null && order == curOrder && order.OrderState == OrderState.Filled) { if (toLongOrder) { ExitLongLimit(tradeParams.max, order.AverageFillPrice + TickSize * tradeParams.take, "ExitOrder", "EnterOrder"); ExitLongStopLimit(tradeParams.max, order.AverageFillPrice - TickSize * tradeParams.stop, "ExitOrder", "EnterOrder"); } else { ExitShortLimit(tradeParams.max, order.AverageFillPrice - TickSize * tradeParams.take, "ExitOrder", "EnterOrder"); ExitShortStopLimit(tradeParams.max, order.AverageFillPrice + TickSize * tradeParams.stop, "ExitOrder", "EnterOrder"); } curOrder = null; } }
Comment
-
Originally posted by Defake View PostThanks for response! And sorry for late...
Okay, I read example from http://ninjatrader.com/support/helpG...r_handling.htm
And try to repeat this in my strategy. But anyway I can't place exit orders even if the enter order is already filled.
Placing enter order:
Code:if (Position.Quantity == 0 && curOrder == null) { if (decision > 0) { curOrder = EnterLongLimit(tradeParams.max, Bars.LastPrice, "EnterOrder"); toLongOrder = true; } else if (decision < 0) { curOrder = EnterShortLimit(tradeParams.max, Bars.LastPrice, "EnterOrder"); toLongOrder = false; } }
Code:protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError) { // if exited from trade, clear all remaining orders (e.g. remaining stop order) if (order.Name == "ExitOrder" && orderState == OrderState.Filled) Orders.Clear(); // if Enter order is filled, place exit orders if (curOrder != null && order == curOrder && order.OrderState == OrderState.Filled) { if (toLongOrder) { ExitLongLimit(tradeParams.max, order.AverageFillPrice + TickSize * tradeParams.take, "ExitOrder", "EnterOrder"); ExitLongStopLimit(tradeParams.max, order.AverageFillPrice - TickSize * tradeParams.stop, "ExitOrder", "EnterOrder"); } else { ExitShortLimit(tradeParams.max, order.AverageFillPrice - TickSize * tradeParams.take, "ExitOrder", "EnterOrder"); ExitShortStopLimit(tradeParams.max, order.AverageFillPrice + TickSize * tradeParams.stop, "ExitOrder", "EnterOrder"); } curOrder = null; } }
Comment
-
Hello Defake,
I would suggest adding print statements to check whether your conditions are becoming true. For example I would put a print statement above if(toLongOrder), Print(“Getting to this part”);, as well as within that block to see if it’s being considered and whether the if statement is becoming true. You could also print the value of your variables as well as what you are checking them against, for example Print(order.ToString());
I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...
I’ve provided a link covering debugging which you may find helpful.
Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Stanfillirenfro, Today, 07:23 AM
|
1 response
3 views
0 likes
|
Last Post Today, 07:37 AM | ||
Started by cmtjoancolmenero, Yesterday, 03:58 PM
|
2 responses
20 views
0 likes
|
Last Post Today, 07:24 AM | ||
Started by olisav57, Yesterday, 07:39 PM
|
1 response
9 views
0 likes
|
Last Post Today, 07:23 AM | ||
Started by cocoescala, 10-12-2018, 11:02 PM
|
7 responses
944 views
0 likes
|
Last Post
by Jquiroz1975
Today, 07:21 AM
|
||
Started by oviejo, Today, 12:28 AM
|
1 response
12 views
0 likes
|
Last Post Today, 07:20 AM |
Comment