Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
"On" stop loss
Collapse
X
-
Hello dafonseca,
No, do not add the OnExecution method to the OnBarUpdate method.
The OnExecution() method is a method just like OnBarUpdate. Put OnExecution below or above OnBarUpdate, but outside of it.
Below is a link to the help guide on OnExecution().
http://www.ninjatrader.com/support/h...nexecution.htmChelsea B.NinjaTrader Customer Service
Comment
-
Something weird has happened, When I insert this part on my code, without change anything on OnBarUpdate, my backtesting results change radically.
Any clue?
protected override void OnExecution(IExecution execution)
{
if (execution.Order.Name == "Stop loss")
{
// execute code
}
}
Comment
-
Hi dafonseca,
This code does not actually do anything.
May I see your script to see how you have added this code?
To export your script do the following:- Click File -> Utilities -> Export NinjaScript
- Enter a unique name for the file in the value for 'File name:'
- Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
- Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message
By default your exported file will be in the following location:- (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>
Below is a link to the help guide on Exporting NinjaScripts.
Chelsea B.NinjaTrader Customer Service
Comment
-
To update other forum members, the issue was using the Order child object of the execution object. It is not always there.
We changed:
protected override void OnExecution(IExecution execution)
{
if (execution.Order.Name == "Stop loss")
{
// execute code
}
}
To:
protected override void OnExecution(IExecution execution)
{
if (execution.Name == "Stop loss")
{
// execute code
}
}
And was able to correct the issue.Chelsea B.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
648 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 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
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
573 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment