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

  #1 (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

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.
It seems as though I am having a hard time accessing the Account Position direction and AvgPrice from the Strategy.
When I Sync Account Position = True, it simply Flattens the position that I am already in. I don't want it to flatten, I want it to show up as a Position somewhere.

Maybe I can do it as an Unmanaged = True and just program it in a way that I handle everything, so no OCO needed

I was hoping to access something that said what my position is OnStartUp() and Cancel any open orders, then apply my stop using SubmitOrder(.....) and then tighten it accordingly.

I kind of want my entries to be manual, and the stops to be from the strategy. But I don't want to use ATM since I need to have control of how it is tightened based on the "Swing" indicator.

So I don't think there is anything supported and I am actually somewhat surprised since it seems like I have heard of people complaining that they don't want the Sync Account Position to "Flatten" their position, but simply add some trade management to an already existing position.

So, thinking maybe a workaround to this is possible if I can at least access the Object for Account Position that is not from the Strategy but from the manual position.

thanks
Spencer

Follow me on Twitter Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
Increase in trading performance by 75%
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
MC PL editor upgrade
MultiCharts
 
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
My NQ Trading Journal
14 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
13 thanks
  #2 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

You should try to use an indicator, and not a strategy, which has more "controls".
Take a look at NinjaTrader.Cbi.Globals.Accounts and its methods, that will allow you to control your orders yourself, without the strategy (safe) controls.
Highly unsupported, of course, but it works.

Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #3 (permalink)
 MooreTech 
Orlando, Florida
 
Experience: Advanced
Platform: NinjaTrader, TradeStation, MultiCharts, eSignal, MetaTrader
Trading: ES
Posts: 57 since Aug 2010
Thanks Given: 6
Thanks Received: 73


You may want to have a look at the Documentation for the NTDirect.DLL file. See the section on DLL functions at the link below:

NinjaTrader Version 7

If you have any questions about our products or services please contact me via Private Message
Follow me on Twitter Reply With Quote
Thanked by:
  #4 (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


sam028 View Post
You should try to use an indicator, and not a strategy, which has more "controls".
Take a look at NinjaTrader.Cbi.Globals.Accounts and its methods, that will allow you to control your orders yourself, without the strategy (safe) controls.
Highly unsupported, of course, but it works.

Hi Sam

so Indicators have more things available through its inheritance?
that is interesting. I will check it out.
But do place trades you would need a strategy right? So, I guess you would use the indicator to check for the account position through the strategy?

thanks
Spencer

Follow me on Twitter Started this thread Reply With Quote
  #5 (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


MooreTech View Post
You may want to have a look at the Documentation for the NTDirect.DLL file. See the section on DLL functions at the link below:

NinjaTrader Version 7

Hi MooreTech

thanks I will look into it. It seems like most of those files are located in C:\Program Files (x86)\NinjaTrader 7\bin
I tried to reference things from there like NTDirect.dll or NinjaTrader.Client.dll
but at least with the Client, it gave a bunch of problems to Ninja things when compiled. I think this is because this can mess up the "arrow direction" of the dependencies by probably creating a "dependency loop"

if you could give me an example of NTDirect.dll that would be great. thanks
Spencer

Follow me on Twitter Started this thread Reply With Quote
  #6 (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


sam028 View Post
You should try to use an indicator, and not a strategy, which has more "controls".
Take a look at NinjaTrader.Cbi.Globals.Accounts and its methods, that will allow you to control your orders yourself, without the strategy (safe) controls.
Highly unsupported, of course, but it works.

Hey Sam.
can you give me an example of your using statement and the object you would create?
thanks
Spencer

Follow me on Twitter Started this thread Reply With Quote
  #7 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629

In fact all can be done in an indicator. What's I've done is adding some extra buttons and fields to the "ChartTrader", so it's then possible to get the account name, then create an order.

See the code to create a buy limit order :
 
Code
                            
    string accName ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["cboAccount"].Text;

    
int quantity = (int)((NumericUpDown)ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["nudQuantity"]).Value;
    if (
quantity 1)
        return;            
    
Account a null;    
    for (
int i=0;i<=NinjaTrader.Cbi.Globals.Accounts.Count-1;i++)
    {
        if (
NinjaTrader.Cbi.Globals.Accounts[i].Name == accName)
        {
            
NinjaTrader.Cbi.Globals.Accounts[i];
        }
    }            
    if (
!= null)
    {
        
Order o a.CreateOrder(Instrument,OrderAction.Buy,OrderType.Limit,TimeInForce.Day,quantity,(double)nudBuyLmtPr.Value,0,"","Buy");            
        
o.Submit();                
    }


Success requires no deodorant! (Sun Tzu)
Follow me on Twitter Reply With Quote
Thanked by:
  #8 (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


sam028 View Post
In fact all can be done in an indicator. What's I've done is adding some extra buttons and fields to the "ChartTrader", so it's then possible to get the account name, then create an order.

See the code to create a buy limit order :
 
Code
                            
    string accName ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["cboAccount"].Text;

    
int quantity = (int)((NumericUpDown)ChartControl.Controls["pnlChartTrader"].Controls["ctrChartTraderControl"].Controls["nudQuantity"]).Value;
    if (
quantity 1)
        return;            
    
Account a null;    
    for (
int i=0;i<=NinjaTrader.Cbi.Globals.Accounts.Count-1;i++)
    {
        if (
NinjaTrader.Cbi.Globals.Accounts[i].Name == accName)
        {
            
NinjaTrader.Cbi.Globals.Accounts[i];
        }
    }            
    if (
!= null)
    {
        
Order o a.CreateOrder(Instrument,OrderAction.Buy,OrderType.Limit,TimeInForce.Day,quantity,(double)nudBuyLmtPr.Value,0,"","Buy");            
        
o.Submit();                
    }


thank you Sam. Your always so helpful. :-) I will give this a try

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

Great Thread!

I have a follow up question.

After submitting "Account" order from "Account" object (let's say limit order) - how to get notification when that order gets fully or partially filled (limit order - not the market one)?

I tried looking at internal methods in the Account.cs file of NinjaTrader:
public event ExecutionUpdateEventHandler Execution;

public event OrderStatusEventHandler OrderStatus;

public event PositionUpdateEventHandler PositionUpdate;

Should I create inherited class from Account? Will then I be able to get notified when some event has occured (like Position has been updated, or Order has changed its status)?
Any sample code/idea would be very appreciated!

Reply With Quote
  #10 (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
Great Thread!

I have a follow up question.

After submitting "Account" order from "Account" object (let's say limit order) - how to get notification when that order gets fully or partially filled (limit order - not the market one)?

I tried looking at internal methods in the Account.cs file of NinjaTrader:
public event ExecutionUpdateEventHandler Execution;

public event OrderStatusEventHandler OrderStatus;

public event PositionUpdateEventHandler PositionUpdate;

Should I create inherited class from Account? Will then I be able to get notified when some event has occured (like Position has been updated, or Order has changed its status)?
Any sample code/idea would be very appreciated!

Hello

so I might be interpreting you incorrect, but it sounds like you want to know the status of the order : i.e. PartiallyFilled, or Filled, etc..

From my experience, this is all handled via IOrders

 
Code
private IOrder entryOrder = null;
private IOrder stopOrder = null;
private IOrder targetOrder = null;

protected override void OnOrderUpdate(IOrder order)
{
     if (entryOrder != null && entryOrder == order)
     {
            if (order.OrderState == OrderState.Filled)
            {
                 // do this 
            }
           if (order.OrderState == OrderState.PartiallyFilled)
           {
                // do this
           }

     }

}
hope this is what you mean

Spencer

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