NexusFi: Find Your Edge


Home Menu

 





Strategy Position and Account Position


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one spinnybobo with 8 posts (0 thanks)
    2. looks_two ninjauser with 4 posts (0 thanks)
    3. looks_3 sam028 with 2 posts (4 thanks)
    4. looks_4 Camdo with 1 posts (0 thanks)
    1. trending_up 8,766 views
    2. thumb_up 5 thanks given
    3. group 6 followers
    1. forum 15 posts
    2. attach_file 1 attachments




 
Search this Thread

Strategy Position and Account Position

  #11 (permalink)
 Camdo 
Boston, MA / USA
 
Experience: Intermediate
Platform: NinjaTrader
Trading: ES
Posts: 251 since Apr 2013
Thanks Given: 2,698
Thanks Received: 392


spinnybobo View Post
Hello,
I am currently working on a strategy that allows me to enter the trade manually in NinjaTrader and then apply a Strategy to it with stops and targets.

Here is my strategy that does what you ask. After a manual entry, start the strategy. You have to enter the date and time when you want the strategy to become effective. This is a bother, but necessary for tailstop flexibility. It will exit when RSI crosses above the oversold level, or on stoploss, or profit limit, or on a tail stop. You can easily modify the strategy for whatever your exit plan is.
ExitSlPlTsRsi.cs

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Exit Strategy
NinjaTrader
Increase in trading performance by 75%
The Elite Circle
MC PL editor upgrade
MultiCharts
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
GFIs1 1 DAX trade per day journal
16 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
My NQ Trading Journal
12 thanks
  #12 (permalink)
 ninjauser 
Houston Texas
 
Experience: Advanced
Platform: NinjaTrader, MetaTrader, TradeStation
Trading: EUR/USD
Posts: 5 since Jun 2013
Thanks Given: 7
Thanks Received: 1

Thanks,

However, I am trying to work with Account orders and not IOrder objects. I haven't found a way of getting IOrder object from Account Order. Idea is I can enter position manually and then enable strategy which will pick up the current position (which is working fine).

Then I want my strategy (or myself even before I start strategy) to place limit order.

If/When NinjaTrader is restarted - it should be able to get list of current "Working" orders - which I know how to do.

Problem is when order actually gets filled or partially filled - I want to get notified at this exact moment that execution has occured...

And as I am writing it - I tried using different event and found out that even OnPositionUpdate happens as any of the limit orders get filled... that opens a way for me to look for collection of orders and check their status to determine what has actually happened...

Thanks for replying anyway! I think I can move on now...

Reply With Quote
  #13 (permalink)
 ninjauser 
Houston Texas
 
Experience: Advanced
Platform: NinjaTrader, MetaTrader, TradeStation
Trading: EUR/USD
Posts: 5 since Jun 2013
Thanks Given: 7
Thanks Received: 1


The only problem - it works only for first limit order. Second limit order in a row doesn't trigger this event unless I disable/enable strategy in NinjaTrader...

Reply With Quote
  #14 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


ninjauser View Post
The only problem - it works only for first limit order. Second limit order in a row doesn't trigger this event unless I disable/enable strategy in NinjaTrader...

Hi

the event you want to use is either
 
Code
protected override void OnExecution(IExecution execution)
{

}

or 

protected override void OnOrderUpdate(IOrder order)
{

}
as for reading a manual position inside of a strategy (since Ninja holds those separate) I have not figured a way of how to do this

Follow me on Twitter Started this thread Reply With Quote
  #15 (permalink)
 ninjauser 
Houston Texas
 
Experience: Advanced
Platform: NinjaTrader, MetaTrader, TradeStation
Trading: EUR/USD
Posts: 5 since Jun 2013
Thanks Given: 7
Thanks Received: 1

Those events are for supported stuff

I am looking for unsupported

Here are functions I created to get current "Manual" position:

public double NtGetUnrealizedNotional(Account account, Instrument instrument)
{
Position myPosition = account.Positions.FindByInstrument(instrument);
if (myPosition == null)
{
return 0;
}
return myPosition.GetProfitLoss(Close[0], PerformanceUnit.Currency);
}
public int NtGetUnrealizedQuantity(Account account, Instrument instrument)
{
Position myPosition = account.Positions.FindByInstrument(instrument);
if (myPosition == null)
{
return 0;
}
return myPosition.Quantity;
}

With regards to limit orders - I wonder is there an answer to maybe this thread as alternative (get notified when specific price touches, and then just send a Market order) - prefer to have even and not to do polling from the strategy.

I prefer to run my strategy on every close bar and not on open.

Indicator trigger event in a Strategy - [AUTOLINK]NinjaTrader[/AUTOLINK] Support Forum

Reply With Quote
  #16 (permalink)
 
spinnybobo's Avatar
 spinnybobo 
Crete, IL/USA
 
Experience: Intermediate
Platform: NinjaTrader, Mt4
Broker: Tradestation/Tradestation, NinjaTrader, FXCM and Tallinex
Trading: ES, CL, EUR/USD, TF
Posts: 173 since Aug 2009
Thanks Given: 105
Thanks Received: 61


ninjauser View Post
Those events are for supported stuff

I am looking for unsupported

Here are functions I created to get current "Manual" position:

public double NtGetUnrealizedNotional(Account account, Instrument instrument)
{
Position myPosition = account.Positions.FindByInstrument(instrument);
if (myPosition == null)
{
return 0;
}
return myPosition.GetProfitLoss(Close[0], PerformanceUnit.Currency);
}
public int NtGetUnrealizedQuantity(Account account, Instrument instrument)
{
Position myPosition = account.Positions.FindByInstrument(instrument);
if (myPosition == null)
{
return 0;
}
return myPosition.Quantity;
}

With regards to limit orders - I wonder is there an answer to maybe this thread as alternative (get notified when specific price touches, and then just send a Market order) - prefer to have even and not to do polling from the strategy.

I prefer to run my strategy on every close bar and not on open.

Indicator trigger event in a Strategy - [AUTOLINK]NinjaTrader[/AUTOLINK] Support Forum

it sounds like you are basically saying you want to be notified when an execution actually happens rather than it would happen "delayed" if you put your methods inside of OnBarUpdate() ?

try putting NtGetUnrealizedNotional(Account account, Instrument instrument) inside of OnExecution.
If your "limit order" you use is called

 
Code
private IOrder target1Order = null;


protected override void OnExecution(IExecution execution)
{
      if (target1Order != null && target1Order.Order == execution.Order)
      {
              if (execution.Order.OrderStatus == OrderStatus.Filled)
              {
                   NtGetUnrealizedNotional(Account account, Instrument instrument);
              }
      }
}
A guy from Ninja actually said it is better to put order information inside of OnOrderUpdate
and to put non order stuff like calculating PnL and stuff inside of OnExecution

This is because order information always happens in correct sequence inside of OnOrderUpdate, but is not guaranteed to happen in correct sequence inside of OnExecution since Ninja's multithreaded nature, etc..

Follow me on Twitter Started this thread Reply With Quote




Last Updated on February 13, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts