Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Translating a v6.0 strategy to 7
Collapse
X
-
-
maninjapan, there's unfortunately no full sample, but a sample SubmitOrder call for a StopLimit exit could look like this, please note that this would use a StopLimit order with no offset a stop and limit price are the same -
Code:SubmitOrder(0, OrderAction.Sell, OrderType.StopLimit, 2, Position.AvgPrice - 10 * TickSize, Position.AvgPrice - 10 * TickSize, "", "ExStopLimit");
Comment
-
Thanks, Figured that bit out. When I first started the strategy I was using the following condition to start the strategy
however, now that I have worked my way down to the exits and have Buy and Sell orders working simultaneously, it obviously isnt working, as soon as I get filled on a Buy order it keeps entering new entry Buy orders.Code:if (entryBuyOrder == null)
How can I write the statement so that it enters the initial orders on starting the strategy and then doesnt renew the entry order until an exit order has been filled?
Do I need to move the entry orders to OnExecution as well? They are currently under OnBarUpdate?
Comment
-
Great progress - you could just add a check in OnBarUpdate() to your order submission conditions to enter only if you're flat (Position.MarketPosition == MarketPosition.Flat) - or you could go more advanced by including a check to the order fillstate of your exitOrder to again submit entries.
Comment
-
Thanks, slow progress but one step at a time in the right direction. Will just checking if the position status is flat work? Considering unmanaged = true?
Comment
-
Before that, looks like I need to add a Cancel order command somewhere to cancel the remaining exit order. (if it hits the stop loss, then the lprofit target order is remaining.) Do I have to add this under On Execution? (I tried to add it in under OnBarUpdate, but recieved an error in the log.
Comment
-
well one more problem down, one more in its place.....
After the entry order is executed it successfully submits the OCO order and this also works as expected. However while waiting for the OCO orders to be executed, I Get an error in the log
Im using a foreign language version of windows but I believe the error translates to NullReferenceException or similar???? Is this caused by a major error in the code and easy to fix or by something more subtle and more difficult to troubleshoot?Error on calling 'OnBarUpdate' method for strategy....
I dont have any problems with this section before it executes it's first trade.
Below is the intro to the OnBarUpdate Section.
Code:protected override void OnBarUpdate() { // Submit an entry limit order if we currently don't have an entry order open if (entryBuyOrder == null && Position.MarketPosition == MarketPosition.Flat) { int now = ToTime(DateTime.Now); int diff = now - this.lastTime; if (diff >= this.waitSecond || diff < 0) { this.bid = GetCurrentBid(); this.ask = GetCurrentAsk(); if (this.bid == this.ask) return; this.lastTime = now; this.Print("bid = " + this.bid + ", ask = " + this.ask); } // Buy entryBuyOrder = SubmitOrder(0,OrderAction.Buy,OrderType.Limit,1,this.bid - this.offsetTicks * TickSize,0,"","Long Limit"); // Sell entrySellOrder = SubmitOrder(0,OrderAction.SellShort,OrderType.Limit,1,this.ask + this.offsetTicks * TickSize,0,"","Short Limit"); } else
Comment
-
Trying to work through this one, not getting very far though.
The error occurs after an entry order is filled, but not immediately.
The fact that the error occurs on calling 'OnBarUpdate', does this mean that I need to be looking for the problem within this section? Or may it also be within the OnExecution section where the exit orders are being handled?
Comment
-
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
649 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
576 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment