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
Mimic Entry Handling in Unmanaged Strategy
Collapse
X
-
Hello cutzpr,
This tracking would need to be accomplished with the logic of your script.
If you were tracking a single entry, you could look for the position to be flat to allow any new entries.
Or you could use a counter that increments on each (complete) entry order fill and decrements when an exit order fills.
If you are wanting multiple entries based on the signal name and logic to allow up to a set number of entries for each signal name, you would need custom logic to store this information. You might use a dictionary of ints used as counters where the key is the signal name. This would make one entry per signal name that tracks the number of entries for that signal name.Chelsea B.NinjaTrader Customer Service
-
I know there are several ways to go about it, this is what I figured. I am posting here to help anyone else that may find it useful
PHP Code:
Order lastOrder;
protected override void OnOrderUpdate(...)
{
lastOrder = order;
}
public bool MaxPositionSizeMet()
{
if(IsFlat()) return false;
else if (Position.Quantity >= this.maxPositions)
{
return true;
}
else return false;
}
public bool MaxEntriesPerDirectionMet()
{
OpenOrders.Add(lastOrder);
int count = 0;
if(IsFlat())
{
OpenOrders.Clear();
count = 0;
return false;
}
//For Max Entries for All Entries----------
foreach(Order o in OpenOrders)
{
if(o.FromEntrySignal == lastOrder.FromEntrySignal) count++;
}
if (count >= maxEntriesPerDirection) return true;
else return false;
//----------------------------------------
}
public bool zMaxUniqueEntriesMet()
{
OpenOrders.Add(lastOrder);
bool u = false;
if(zIsFlat())
{
OpenOrders.Clear();
return false;
}
if (OpenOrders.Any())
{
var OrderGroups = OpenOrders.GroupBy(x => x.FromEntrySignal);
foreach (var g in OrderGroups)
{
if (lastOrder.FromEntrySignal == g.Key)
{
if (g.Count() >= maxUniqueEntriesPerDirection)
u = true;
else
u = false;
}
}
}
return u;
}
Last edited by cutzpr; 09-30-2018, 10:51 PM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by geddyisodin, Today, 05:20 AM
|
5 responses
32 views
0 likes
|
Last Post Today, 11:39 AM | ||
Started by bmartz, Today, 09:30 AM
|
2 responses
12 views
0 likes
|
Last Post
by bltdavid
Today, 11:24 AM
|
||
Started by f.saeidi, Today, 11:02 AM
|
1 response
4 views
0 likes
|
Last Post Today, 11:08 AM | ||
Started by geotrades1, Today, 10:02 AM
|
4 responses
12 views
0 likes
|
Last Post
by geotrades1
Today, 11:08 AM
|
||
Started by rajendrasubedi2023, Today, 09:50 AM
|
3 responses
16 views
0 likes
|
Last Post Today, 10:57 AM |
Comment