For example I bought 100 shares at 30$, then I bought 100 shares at 31, so I have a position 200 shares with average price 30.50$. But all I tried in NT creates second position so I have 2 positions at 30$ and 31$ 100 shares each and I can manage them separately, but I need to manage them as one position.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Adding to position
Collapse
X
-
Adding to position
How can I add to existing position to manage them as one position?
For example I bought 100 shares at 30$, then I bought 100 shares at 31, so I have a position 200 shares with average price 30.50$. But all I tried in NT creates second position so I have 2 positions at 30$ and 31$ 100 shares each and I can manage them separately, but I need to manage them as one position.Tags: None
-
JoydeepNinjaTrader Customer Service
-
-
The idea is to add to position every 1% of move and to exit at 30% trail stop on the whole position. So I count how many ticks was MAX profit and set stoploss to 30% of its value.Code:protected override void OnBarUpdate() { if ((Bars.GetDayBar(1) == null)) { return; } Quantity = 100; if(Position.MarketPosition == MarketPosition.Flat) { if (CrossAbove(Close, CorrelationSPY(deviation).UpLine, 1)) { EnterLong(Quantity, Instruments[BarsInProgress].FullName + " long"); SetStopLoss(Instruments[BarsInProgress].FullName + " long", CalculationMode.Percent, StopLoss, false); } if (CrossBelow(Close, CorrelationSPY(deviation).DownLine, 1)) { EnterShort(Quantity, Instruments[BarsInProgress].FullName + " short"); SetStopLoss(Instruments[BarsInProgress].FullName + " short", CalculationMode.Percent, StopLoss, false); } } else { if(BarsSinceEntry()>5) { if(Position.MarketPosition == MarketPosition.Long) { if(CrossAbove(Close,Position.AvgPrice*(1+0.01*Position.Quantity/Quantity),1)) { EnterLong(Quantity, Instruments[BarsInProgress].FullName + " long"); } SetTrailStop(Instruments[BarsInProgress].FullName + " long",CalculationMode.Ticks, (int)((MAX(High,BarsSinceEntry())[0]-Position.AvgPrice)*0.3), false); } if(Position.MarketPosition == MarketPosition.Short) { if(CrossAbove(Close,Position.AvgPrice*(1-0.01*Position.Quantity/Quantity),1)) { EnterShort(Quantity, Instruments[BarsInProgress].FullName + " short"); } SetTrailStop(Instruments[BarsInProgress].FullName + " short",CalculationMode.Ticks,(int)((Position.AvgPrice - MIN(Low,BarsSinceEntry())[0])*0.3), false); } } } }Last edited by nysetrader; 06-13-2012, 12:07 PM.
Comment
-
Hello nysetrader,
If the strategy is a multi-timeframe strategy (and not multi-instrument strategy) then the order names for the 2 entry are the same. The internal order handling rules will reject the order (unless Entry per direction is set to 2 or more).
Also you cannot use the SetStopLoss and SetTrialStop in the same strategy unless unique names are assigned to each orders.
Please make sure you assign unique names to the orders and check if it works or not.
Please let me know if I can assist you any further.JoydeepNinjaTrader Customer Service
Comment
-
Entry per direction is set to 30. How should I code adding to position?
The first entry is made by simple condition, then I'm adding to position every 1% of move. As I understand you I cannot use same ID for orders when I'm doing adding. How should I code SetTrailStop for the whole position? without any ID? Can you make a sample for it?
Comment
-
SetTrailStop in Initialize section is not suitable, because I need to use it only after adding to position. I've tried entries without any names, and it closes only last position, not the whole.
Comment
-
Hello,
You have you use either SetTrailStop or SetStopLoss in a strategy you cannot use both.
In the case that you needed auto trail be did not want SetTrailStop or wanted a more advanced auto trail then what SetStopLoss delivars you would need to program the stop loss move up yourself.
Please see this guide here that should help show you how you would do this in your strategy.
and even more advanced:
The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()
-BrettBrettNinjaTrader Product Management
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
648 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
369 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
108 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
572 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
574 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|
Comment