Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
How would I code SMA as a stoploss using
Collapse
X
-
Hello Kaywai,
You could plug in the value of the SMA for the price.
Code:SetStopLoss(CalculationMode.Price, SMA(14)[0]);
http://www.ninjatrader-support.com/H...tStopLoss.html
Ryan M.NinjaTrader Customer Service
-
You have to use addition variable for that.Originally posted by Baruch View PostNo its wrong for stoploss.
In Rayn's formula the stoploss can go up and down!
Baruch
When you enter the trade:
stopprice = SMA(period)[0];
SetStopLoss(CalculationMode.Price, stopprice);
While you are in the trade:
stopprice = Math.Max(SMA(period)[0], stopprice);
//for long position; for short position use Math.Min
SetStopLoss(CalculationMode.Price, stopprice);
Comment
-
This is also not correct. For example when you go long and the SMA is above the price!!You have to use addition variable for that.
When you enter the trade:
stopprice = SMA(period)[0];
SetStopLoss(CalculationMode.Price, stopprice);
But its easy do it correctly.
Baruch
Comment
-
-
Guys, Thanks for all the answers. It's kinda like a trailing stop. And since I am using SetStopLoss as my method, I was just thinking how I could tweak it automatically. The thought that first came to mind was SMA or more specifically TD Moving Average I. I just didn't know how to write the code for it.
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