Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
SetStopLoss + MACD
Collapse
X
-
SetStopLoss + MACD
Hello, I'm developing a strategy where I have a stoploss tick of 50, however, I don't want that to trigger UNLESS the MACD has also crossed over. There have been times where triggers are met, but the MACD doesn't agree. I don't want to adjust my tick size to 50, as I've backtested many resolutions from 20-75 and 50 is the sweet spot. If there is a way I can code the SetTrailSTOP with and/or MACD > AVG or MACD < AVG that would be wonderful. Thanks for the helpTags: None
-
Hello rdavido,
Thank you for your post.
You can set the SetTrailStop() in the OnBarUpdate() method and wait for your conditions, the only thing here is that the Set methods are submitted once the order fills. So if you need to wait for the macd to agree with the exit before you use the trail stop I would recommend not using the Set methods but using the Exit methods.
This means you would need to update the Exit method in OnBarUpdate() when your conditions is true (likely ExitLongStop() or ExitShortStop()) to act as a trailing stop.
For example:
Code:if(Position.MarketPosition == MarketPosition.Long && MACD(12, 26, 9)[0] < MACD(12, 26, 9).Avg[0]) { ExitLongStop(MAX(High, BarsSinceEntry())[0] - (50*TickSize)); }
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by SalmaTrader, 07-07-2026, 10:26 PM
|
0 responses
47 views
0 likes
|
Last Post
by SalmaTrader
07-07-2026, 10:26 PM
|
||
|
Started by CarlTrading, 07-05-2026, 01:16 PM
|
0 responses
22 views
0 likes
|
Last Post
by CarlTrading
07-05-2026, 01:16 PM
|
||
|
Started by CaptainJack, 06-17-2026, 10:32 AM
|
0 responses
15 views
0 likes
|
Last Post
by CaptainJack
06-17-2026, 10:32 AM
|
||
|
Started by kinfxhk, 06-17-2026, 04:15 AM
|
0 responses
21 views
0 likes
|
Last Post
by kinfxhk
06-17-2026, 04:15 AM
|
||
|
Started by kinfxhk, 06-17-2026, 04:06 AM
|
0 responses
23 views
0 likes
|
Last Post
by kinfxhk
06-17-2026, 04:06 AM
|

Comment