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 geotrades1, Today, 10:02 AM
|
2 responses
5 views
0 likes
|
Last Post
by geotrades1
Today, 10:43 AM
|
||
Started by ender_wiggum, Today, 09:50 AM
|
1 response
5 views
0 likes
|
Last Post Today, 10:10 AM | ||
Started by rajendrasubedi2023, Today, 09:50 AM
|
1 response
12 views
0 likes
|
Last Post Today, 10:05 AM | ||
Started by bmartz, Today, 09:30 AM
|
1 response
10 views
0 likes
|
Last Post Today, 09:48 AM | ||
Started by geddyisodin, Today, 05:20 AM
|
3 responses
27 views
0 likes
|
Last Post Today, 09:36 AM |
Comment