Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Increasing Order Sizes

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • NinjaTrader_Lance
    replied
    Hello,
    Originally posted by Aussiemike View Post
    I'm looking for a way to call the Margin value in the Instrument Manager? I want to allow one code to run on multiple instruments. Can i simply allow the code to do it's calcs and then use the accont size option in backtest screen?
    Yes you will need to set this on the Strategy Analyzer and you will want to use the AccountSize property http://www.ninjatrader.com/support/h...ccountsize.htm

    Also is there a way to consider multiple instruments in the one account. I don't want to say account is big enough to trade 10 lots and then trade 10 lots on both instruments. I can see that basically account size will allow every instrument to trade the full amount.

    Looking for a way to not take a trade in say EURUSD if the margin is already used up be AUDUSD
    You will have to custom code this logic yourself through the use of a multi series strategy. You can look at the sample that comes pre-built with NinjaTrader by going to tools -> edit ninjascript -> strategy -> SampleMultiInstrument
    Additionally look at: http://www.ninjatrader.com/support/h...nstruments.htm

    Please let me know if I can be of further assistance.

    Leave a comment:


  • Aussiemike
    replied
    Hi Lance,

    Thanks for this. Looks good. Trying to code adjusting lot sizes myself at the moment.

    I'm looking for a way to call the Margin value in the Instrument Manager? I want to allow one code to run on multiple instruments. Can i simply allow the code to do it's calcs and then use the accont size option in backtest screen?

    Also is there a way to consider multiple instruments in the one account. I don't want to say account is big enough to trade 10 lots and then trade 10 lots on both instruments. I can see that basically account size will allow every instrument to trade the full amount.

    Looking for a way to not take a trade in say EURUSD if the margin is already used up be AUDUSD

    Cheers

    Leave a comment:


  • NinjaTrader_Lance
    replied
    You will want to define your variables at the top of your code in the #region Variables section

    The following is pseudo code
    Code:
    private int qty;
    private double equity;
    //etc...
    
    
    OnBarUpdate()
    {
    equity = GetAccountValue(AccountItem.CashValue);
    qty = (int)((equity / 0.2)/1000)*1000;
    
    if(YOUR CONDITION)
    {
      EnterLong(qty, "Long");//will enter long with a market order
    }
    
    if (Position.MarketPosition == MarketPosition.Long)
    {
      if(YOUR CONDITION)
        ExitLong("Long");//exits based on entry signal
    }
    
    }
    Please refer to here for list of orders and their descriptions: http://www.ninjatrader.com/support/h...er_methods.htm

    Also, please be aware, GetAccountValue will only work in real time. If you wish to backtest your strategy the easiest way would be to manually change this value, but you can also look into setting the AccountSize. The later option will not update as account size changes. http://www.ninjatrader.com/support/h...a_strategy.htm

    Leave a comment:


  • hazza147
    replied
    Could I use something like the following:

    Code:
    //Calculate position size
    double equity = GetAccountValue(AccountItem.CashValue);
    double qty = equity / 0.2;
    EnterShort((int)qty);
    I'd want it to also RoundDown to the nearest 1000 as my broker only allows lots of 1000 to be traded. So if account balance was $2000 I'd want it to trade 10000.

    Leave a comment:


  • hazza147
    replied
    Originally posted by Radical View Post
    I think you would want to do something like (this is pseudo code)

    int qty = AccountSize / x;
    if (Position.MarketPosition != MarketPosition.Flat && Position.Quantity != qty)
    {
    int difference = qty - Position.Quantity;
    //then submit an order with a quantity equal to the 'difference' integer
    }

    Code:
    if (CrossAbove(MAseries1, MAseries2, 1))
    					ExitShort("ExitS", "S");
    					EnterLong(***********, "L");
    				else if (CrossBelow(MAseries1, MAseries2, 1))
    					ExitLong("ExitL", "L");
    					EnterShort(***********, "S");
    				#endregion
    What Syntax could I replace the *'s with to create a account size / x. I.e. if account size was $2000 and I wished to trade 10,000 the x would be 0.2. I'd want a dynamically updating one which looks at my live account size. I'm struggling to find the right syntax in the manual. Also would the Exit actions I've entered be sufficient to exit the previous trade?

    Leave a comment:


  • NinjaTrader_Lance
    replied
    I would need some more information on exactly how your strategy functions to give you a definitive answer. (Specifically what methods are you using for exiting your trades)

    The exit orders are stoploss and target orders. If you make it so these do not cancel, you will not be immediately taken out of a trade when you disable the strategy but the stoploss/target orders set by the strategy will remain active.

    Leave a comment:


  • hazza147
    replied
    Lance, just to confirm then. My idea of unclicking 'Cancel exit orders when a strategy is disabled' in NinjaScripts would not work then?

    Leave a comment:


  • NinjaTrader_Lance
    replied
    Hello,

    When you enable a new strategy it will have no connection to the old strategy. You can change your default quantity with an input variable but this will not affect any current open positions and will be placed in a new instance.

    You may consider starting an additional strategy with a smaller size. (original strategy would be trading at 5000 and the other at 1000) Please note: This may not work with your strategy depending on it's logic and it will not necessarily pick up where the other strategy left off. Instead it will be the same as starting the strategy for the first time.

    This could be a viable option if you do not wish to manually enter in a size but let the strategy determine it.
    Originally posted by Radical View Post
    I think you would want to do something like (this is pseudo code)

    int qty = AccountSize / x;
    if (Position.MarketPosition != MarketPosition.Flat && Position.Quantity != qty)
    {
    int difference = qty - Position.Quantity;
    //then submit an order with a quantity equal to the 'difference' integer
    }
    Here is some information on the
    Set order quantity option on the strategies properties section
    Sets how the order size is determined, options are:
    "by default quantity" - User defined order size
    "by strategy" - Takes the order size specified programmatically within the strategy
    "by account" - Allows you to set a virtual account value that is used to determine maximum order size based on margin settings per instrument set in the Instrument Manager
    http://www.ninjatrader.com/support/h...t_strategy.htm

    Leave a comment:


  • Radical
    replied
    I think you would want to do something like (this is pseudo code)

    int qty = AccountSize / x;
    if (Position.MarketPosition != MarketPosition.Flat && Position.Quantity != qty)
    {
    int difference = qty - Position.Quantity;
    //then submit an order with a quantity equal to the 'difference' integer
    }

    Leave a comment:


  • hazza147
    replied
    Lance. I don't want to close out the positions though, I am merely trying to increase the qty at which the strategy trades with, closing out the positions manually defeats the object of having a strategy.

    Leave a comment:


  • hazza147
    replied
    What about if I went into the NinjaScript tab in Options and unclicked 'Cancel exit orders when a strategy is disabled' would this leave the exit orders in so that when I re-enabled the strategy with a different qty it would close out the last position I.e. 5000 in the example discussed and then Sell 6000 so I am only short 6000?

    Leave a comment:


  • NinjaTrader_Lance
    replied
    Hello Harry,

    Thank you for your post. When you disable a strategy in NinjaTrader it will not close out your positions but will cancel pending orders generated by the strategy and stop any trade logic. You will have to manually close out your position before restarting the strategy.

    You can close out a couple of different ways. The simplest will be from the control center select the Positions tab and right click the position you wish to close and click close.

    Please let me know if I can be of further assistance.

    Leave a comment:


  • Radical
    replied
    The best way to do this would probably be to code the quantity logic into your strategy, and not use the Default Quantity. That way you would more or less have complete control over how you increase size.

    Leave a comment:


  • hazza147
    started a topic Increasing Order Sizes

    Increasing Order Sizes

    Hi,

    As my account grows I would like to increase the quantity I am Buying/Selling. I assumed that if I disabled my strategy, increased the default quantity and then re enabled it then NT would close out the last position i.e. 5000 and then Buy/Sell the new default quantity 6000. Instead what it does is if you were long 5000 it would Sell 6000 twice meaning you are now short 7000.

    What is the best way to increase default order quantity without having the problem discussed above?

    Kind Regards,
    Harry Seager

Latest Posts

Collapse

Topics Statistics Last Post
Started by Bobin, Today, 04:29 AM
0 responses
1 view
0 likes
Last Post Bobin
by Bobin
 
Started by Shai Samuel, Today, 02:35 AM
0 responses
5 views
0 likes
Last Post Shai Samuel  
Started by PatriciSmith, Today, 01:03 AM
0 responses
5 views
0 likes
Last Post PatriciSmith  
Started by joostb, Today, 12:59 AM
0 responses
6 views
0 likes
Last Post joostb
by joostb
 
Started by scmaoprah, Today, 12:51 AM
0 responses
4 views
0 likes
Last Post scmaoprah  
Working...
X