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 charlesugo_1, 05-26-2026, 05:03 PM
|
0 responses
56 views
0 likes
|
Last Post
by charlesugo_1
05-26-2026, 05:03 PM
|
||
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
143 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
160 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|
||
|
Started by CarlTrading, 05-10-2026, 08:12 PM
|
0 responses
96 views
0 likes
|
Last Post
by CarlTrading
05-10-2026, 08:12 PM
|
||
|
Started by Hwop38, 05-04-2026, 07:02 PM
|
0 responses
276 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|

Comment