|
Parlin NJ/USA
Posts: 7 since Mar 2015
Thanks Given: 0
Thanks Received: 0
|
Hi All,
I am using this snippet of code in my ninja 7 strategy within OnBarUpdate():
if (!Historical)
{rej.Set(0);
foreach (Account acct in Cbi.Globals.Accounts)
{PositionCollection positions=acct.Positions;
foreach (Position pos in positions)
if (pos.MarketPosition.ToString()=="Long")
{rej.Set(1);}
else if (pos.MarketPosition.ToString()=="Short")
{rej.Set(-1);}}}
where rej is an IntSeries
Ninja apparently does not support this type of coding, but it works with ninjascript.
My question is the following:
If I have only 1 account and I am trading only 1 instrument then the above snippet works for me.
But I would like for it to be more directed so that I can direct the code to access only a specific account for example Sim101 and within that account only a specific instrument for example ES futures.
What the code does is to allow the strategy know the current position of my actual trading account upon each bar update i.e. long=1, short=-1 or flat=0.
Since there is no NT documentation regarding accessing Accounts and this above coding I don't know how to modify the above code so as to not use foreach{} but to instead specify the account and instrument to query for the type of position currently being held.
Any assistance regarding this would be greatly appreciated.
Thanks
|