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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
67 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
36 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
60 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
62 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
53 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment