// Average out long
if (
Position.MarketPosition == MarketPosition.Long
&& Position.Quantity == 1
&& (Low[0] < EMA2[0])
)
{
EnterLong(Convert.ToInt32(PositionSize), @"LongAverage");
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Averaging out / adding to position doesn't work
Collapse
X
-
Averaging out / adding to position doesn't work
So, I have some logic that enters long on a breakout, then I want to average out once we hit a homebase (50 MA). So, the objective is if price dips below my second MA and I already have one contract I'd average that out to 2. Any idea why this doesn't work?
Code:Tags: None
-
Further testing revealed that I do actually hit the block on if statement, is seem that Entering positions won't execute for some reason. Maybe I'm using it wrong? I try to enter long or short after I already had one contract on that side. I simple want to add another one (average in).
This code above confirms that if condition is true as I update lastAction value but I did not sell second lot while holding one short already at that time. Maybe I should use another command other than EnterShort if I'm already short? Or syntax on adding position is different? Can't figure this out ...Code:// Average out short if ( //Position.MarketPosition == MarketPosition.Short Position.MarketPosition != MarketPosition.Long && Position.Quantity <= 5 && (EMA1[0] < EMA2[0]) && (High[0] > EMA1[0]) ) { lastAction = "Average Out Short"; EnterShort(Convert.ToInt32(PositionSize), @"ShortAverage"); }
-
Hello Xcoder,
Thanks for your notes.
EntriesPerDirection and EntryHandling could be used to control the maximum number of entries allowed per direction while a position.
If you set Entry Handling to EntryHandling.AllEntries, NinjaScript will process all entry order methods up to the maximum allowable entries set in the EntriesPerDirection property. For example, if you set EntriesPerDirection to 3 and use EntryHandling.AllEntries, up to a total of 3 entry orders will process.
If you set Entry Handling to EntryHandling.UniqueEntries, NinjaScript will process order entry methods up to the maximum allowable entries set by the EntriesPerDirection property for each uniquely named entry. For example, if you have two entry order methods using unique signal names ("entry1" and "entry2"), set EntriesPerDirection to 3, and use EntryHandling.UniqueEntries, a maximum number of 3 entry orders will process for each uniquely named entry order (up to 3 orders for "entry1" and 3 orders for "entry2").
See the help guide documentation below for more information.
EntriesPerDirection: https://ninjatrader.com/support/help...rdirection.htm
EntryHandling: https://ninjatrader.com/support/help...ryhandling.htm<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
-
Brandon, I guess I'll post a follow up here which is not directly connected to original topic.
While messing with some 3rd party indicators I've installed something that introduced a namespace conflict. They were using EMA name which I could not fix and could not find any residual code after I've removed all indicators I installed.
Then I've reinstalled NT from scratch after cleaning files and documents. Now I get not same but similar message. Script editor seem to compile but I don't like seeing these. Any conflict even if just a warning is not good in my books.
Do you know how I can fix this? I may need to do better job searching this forum but I can't find an answer yet.
Comment
-
Hello Xcoder,
Thanks for your notes.
If what you are seeing are warnings in Visual Studio and not compile errors in the NinjaScript Editor then these should be ignored.
The NinjaScript Editor ignores the known warnings by default because they are benign and we expect them to come up. The default indicators are included in this DLL because the vendor code must be able to use the standard tools that NinjaTrader offers. The warning comes up because we use fully qualified names/reflection etc internally and Visual Studio can not see this.
<span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
50 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
126 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
69 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
42 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment