Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Open Positions Check
Collapse
X
-
Hello Lisalisa,
Thank you for writing in.
To check if you have a open position, you could do this in the strategy wizard under Conditions, setting Current Market Position under Strategy on the left side, using Not Equal as an operator, and then setting on the right side under Strategy>Market Position and selecting Flat. Please see the attachment.
Or you could use the following statement.
if (Position.MarketPosition != MarketPosition.Flat)
An example in our Helpguide:
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
-
Suggestion
If you lose track of the positions you may have to loop through all the open positions and do something with each position, though not knowing what you are doing not sure this helps.
foreach (Position pos in Account.Positions)
{
if (pos.MarketPosition != MarketPosition.Flat)
{
// do something.
}
}
Ref link: http://ninjatrader.com/support/helpG.../?position.htm
Comment
-
I am writing a strategy. I know I have open positions when I backtested it because I could see profile and loss. However, when I tried to retrieve the open positions, I saw nothing.
In the OnBarUpdate method, I added these lines.
foreach (Position pos in Account.Positions)
{
Print("11111");
if (pos.MarketPosition != MarketPosition.Flat)
{
Print("22222");
}
}
Comment
-
So you are in backtest and with a single instrument and managed trades? Perhaps all you need is.
But I am not sure it makes sense to do this at each OnBarUpdate (or at Bar Close) as above).protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
// Calculate on the close of each bar
Calculate = Calculate.OnBarClose;
}
}
protected override void OnBarUpdate()
{
if(Position.MarketPosition == MarketPosition.Long)
{
SetTrailStop(CalculationMode.Pips, your_double_value)
}
if(Position.MarketPosition == MarketPosition.Short)
{
SetTrailStop(CalculationMode.Pips, your_double_value)
}
}
Comment
-
I can't get SetTrailStop to work with CalculationMode.Percent or CalculationMode.Price. I think it doesn't work because no matter what value I pass in, the profit/loss doesn't change when I backtest my strategy. However, if I use CalculationMode.Ticks, it changes the profit/loss.
How do I make it work with CalculationMode.Price or CalculationMode.Percent?
Also, how does SetTrailStop knows whether I am setting a stop order for a long or short position?
This is how I call it:
SetTrailStop("mybuysignal", CalculationMode.Percent, 2.0, true)SetTrailStop("mybuysignal", CalculationMode.Percent, 98.0, true)Last edited by lisalisa; 12-06-2016, 10:04 PM.
Comment
-
Hello lisalisa,
SetTrailStop can not be used with CalculationMode.Price, as price is static and would not change as a trailing stop would require.
See SetTrailStop section of our helpguide:
Regarding SetTrailStop and CalculationMode.Percent, you should use percent in terms of a decimal. For example for a 2 percent stop, you should enter .02.
SetTrailStop should include fromEntrySignal name should you wish to differentiate different SetTrailStop methods between long entries vs short entries.
For example,
SetTrailStop(“Long Entry”, CalculationMode.Ticks, 10, false)
SetTrailStop(“Short Entry”, CalculationMode.Ticks, 50, false)
Please let us know if you need further assistance.Alan P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Yesterday, 05:17 AM
|
0 responses
62 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
134 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
75 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
45 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
50 views
0 likes
|
Last Post
|

Comment