Thanks
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
trailing stops in umanaged framework
Collapse
X
-
trailing stops in umanaged framework
Hello. I'm working in unmanaged framework where I have multiple trades on the same instrument, for which each has it's own stop/ profit target. I've got it working so I can put in static stops/ targets associated with each trade, but I'm having trouble figuring out how I might set up trailing stops for each of those. Essentially, I might have 6 separate stops out, and the price of each would need to be updated (by same amount) following every bar update. Have you guys encountered any examples of this? I could imagine just cycling through all the stops and making the adjustment, but some might have already been filled, etc
ThanksTags: None
-
Hello stewarco,
Thank you for your note.
I put together a sample for the unmanaged approach which will submit a buy order, then a stop which is assigned to an order object and that order object is added to a list of type Order. Then on each bar update, this list is looped to check that the order is a stop market order and above the price which would trigger a change order call for that stop.
With your additional stop orders, you’d just add them to this list and have each changed as needed.
Please see attached.Alan P.NinjaTrader Customer Service
-
possibly relate question
Hi. This methodology works great. However, I'm having a new problem which may or may not be related. When I try to run a playback simulation, I'm getting the error about "Strategy has been disabled because it attempted to modify a historical order that has transitioned to a live order." I currently have the standard language:
else if (State == State.Realtime)
{
// one time only, as we transition from historical
// convert any old historical order object references
// to the new live order submitted to the real-time account
if (entryOrder != null)
entryOrder = GetRealtimeOrder(entryOrder);
if (stopOrder != null)
stopOrder = GetRealtimeOrder(stopOrder);
if (targetOrder != null)
targetOrder = GetRealtimeOrder(targetOrder);
}
However, each stopOrder is going into stopList for updating the trailing levels. So do I need to update the code above to cycle through the entire list of outstanding stops? Or is the issue completely unrelated?
Thanks
Comment
-
Hello stewarco,
The sample I provided only should run in real time so this looks unrelated.
For the issue with attempting to modify a historical order that has transitioned to a live order, please see the following link discussing how to resolve this.
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
Comment
-
follow up
Hey Alan. I reviewed the section you provided, and included language as referenced below but I'm still having that issue. I guess I'm not entirely clear on the historical to realtime transition, but are you saying if I have multiple stop and target orders outstanding when I transition to realtime they'd still be picked up by
else if (State == State.Realtime)
{
// one time only, as we transition from historical
// convert any old historical order object references
// to the new live order submitted to the real-time account
if (entryOrder != null)
entryOrder = GetRealtimeOrder(entryOrder);
if (stopOrder != null)
stopOrder = GetRealtimeOrder(stopOrder);
if (targetOrder != null)
targetOrder = GetRealtimeOrder(targetOrder);
}
Thanks
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by traderqz, Yesterday, 12:06 AM
|
11 responses
27 views
0 likes
|
Last Post Today, 05:11 AM | ||
Started by PaulMohn, Today, 03:49 AM
|
0 responses
8 views
0 likes
|
Last Post
by PaulMohn
Today, 03:49 AM
|
||
Started by inanazsocial, Today, 01:15 AM
|
1 response
10 views
0 likes
|
Last Post Today, 02:18 AM | ||
Started by rocketman7, Today, 02:12 AM
|
0 responses
11 views
0 likes
|
Last Post
by rocketman7
Today, 02:12 AM
|
||
Started by dustydbayer, Today, 01:59 AM
|
0 responses
4 views
0 likes
|
Last Post
by dustydbayer
Today, 01:59 AM
|
Comment