Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Reverse at Stop
Collapse
X
-
Reverse at Stop
I would like to reverse my strategy position if my stop is hit. I don't rhink I 've seen any methods to do that. How do I know when my stop is hit, in order to issue the opposite order? What is the best way I can do this using the available Ninjascript functionality?Tags: None
-
Check for your position direction. If your trail stop is hit your position would be zero at that moment place a short order if you were long.
Code:bool enteredLong = false; if (Close[0] > Open[0]) { EnterLong(); enteredLong = true; } if (enteredLong && Position.MarketPosition == MarketPosition.Flat) { EnterShort(); enteredLong = false; }
Josh P.NinjaTrader Customer Service
Comment
-
Revers trailing stop
Hello Josh,
I am also interested to know how to reverse a trailing stop but the code you posted does not work and I can not achive to make it work.
The strategy goes long all the time the trailing stop is trigered but never short.
I supose this happense because you declared the bool = false in OnBarUpdate so after the strategy goes Long and enterlong is set to = true, the next bar enterlong is again reseted to false (or am I wrong??), so the strategy goes always long.
I can not leave the bool without asigning a valuo but I also do not achive to asigne the bool corectly in Initialize (allways get the error, entered long does not exist in the current context), so I dont know haw to make it work.
Can someone help out please.
Originally posted by Josh View PostCheck for your position direction. If your trail stop is hit your position would be zero at that moment place a short order if you were long.
Code:bool enteredLong = false; if (Close[0] > Open[0]) { EnterLong(); enteredLong = true; } if (enteredLong && Position.MarketPosition == MarketPosition.Flat) { EnterShort(); enteredLong = false; }
Last edited by whitegun; 04-03-2008, 08:53 AM.
Comment
-
Flatten All Positions ?
Under a strategy, is there any way to check for open positions; and if found, then flatten everything ?
Like..
if (Position.MarketPosition != MarketPosition.Flat)
{
.. Flatten everything !
}
Just curious.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by samish18, 04-17-2024, 08:57 AM
|
16 responses
55 views
0 likes
|
Last Post
by samish18
Today, 03:30 PM
|
||
Started by arvidvanstaey, Today, 02:19 PM
|
3 responses
9 views
0 likes
|
Last Post Today, 03:23 PM | ||
Started by jordanq2, Today, 03:10 PM
|
2 responses
8 views
0 likes
|
Last Post
by jordanq2
Today, 03:23 PM
|
||
Started by traderqz, Today, 12:06 AM
|
10 responses
18 views
0 likes
|
Last Post
by traderqz
Today, 02:49 PM
|
||
Started by algospoke, 04-17-2024, 06:40 PM
|
5 responses
47 views
0 likes
|
Last Post Today, 02:36 PM |
Comment