Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Increasing number of lots

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

    Increasing number of lots

    Hey guys, I'm having trouble with a small problem in one of my strategies when running Live.

    The strategy is set to only work on bar close otherwise it will get into false trades, the lot size is set to 10k but if the strategy reverses the trade Short->Long or Long->Short then the lot size will increase by 10k to 20k.

    If its at 20k it will increase to 30k, so on and so forth. The highest I've seen it go was 70k. I need to figure out how to make this not increase my lot size and still exit the trade and get into the opposite trade.

    I can't figure out how to make it do this except for using FirstTick, and even then I can't figure out how to make it work without making it calculateonbarclose = false

    Code:
    if (CrossAbove(Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Signal, Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Main, 1))
                {
    				ExitLong("", "");	
    				previousExit = CurrentBar;
                }
    			
    			// Condition set 2
                if (CrossBelow(Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Signal, Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Main, 1))
                {
    				ExitShort("", "");
    				previousExit = CurrentBar;
                }
    			
                // Condition set 1
                if (CrossAbove(Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Signal, Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Main, 1)
                    && Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Main[0] > SignalLevelMin
                    && Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Main[0] < SignalLevelMax)
                {
                    EnterShort(DefaultQuantity, "");
                }
    
                // Condition set 3
                if (CrossBelow(Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Signal, Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Main, 1)
                    && Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Main[0] < -SignalLevelMin
                    && Ergodic(ErgodicFast, SignalLevelMax, SignalLevelMin, SignalPeriod, ErgodicSlow).Main[0] > -SignalLevelMax)
                {
    				EnterLong(DefaultQuantity, "");
                }

    #2
    Hi magnatauren,

    Is it possible you are calling an exit order on the same bar as an entry order?

    If so, this can cause your strategy to take the double the opposite direction.

    When calling an entry method in the opposite direction of your position this will cause your position to be reversed. NinjaTrader will automatically submit an order to close your existing position and then enter an order to enter you into the opposite position.

    If you exit and then call an entry method in the same run of OnBarUpdate, the Position.MarketPosition will not have known that your position is closed and will combine your orders and end up sending 3 orders. The first order is the exit position from your exit method, the second order is to close the position from NinjaTrader automatically reversing your position, the third order is to enter you into the opposite position.

    This is not elaborated on in the help guide but the help guide does say "Entry methods are used to submit orders that create a market position if none exists or to reverse an existing position.". This is in the Entry Methods section in the link below.



    Adding prints with the bar time to each condition can let you know if this is what is happening.

    If this is not the issue, may I have a export of you code that demonstrates the issue?

    To export your script do the following:
    1. Click File -> Utilities -> Export NinjaScript
    2. Enter a unique name for the file in the value for 'File name:'
    3. Select the strategy from the objects list on the left -> click the right facing arrow ">" to add the strategy to the export
    4. Click the 'Export' button -> click 'yes' to add any referenced indicators to the export -> click OK to clear the export location message


    By default your exported file will be in the following location:
    • (My) Documents/NinjaTrader 7/bin/Custom/ExportNinjaScript/<export_file_name.zip>


    Below is a link to the help guide on Exporting NinjaScripts.
    http://www.ninjatrader.com/support/h...nt7/export.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      That sounds like the problem, thank you very much!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by suroot, 04-10-2017, 02:18 AM
      4 responses
      3,021 views
      0 likes
      Last Post truepenny  
      Started by Stanfillirenfro, Today, 07:23 AM
      1 response
      6 views
      0 likes
      Last Post NinjaTrader_Gaby  
      Started by cmtjoancolmenero, Yesterday, 03:58 PM
      2 responses
      22 views
      0 likes
      Last Post cmtjoancolmenero  
      Started by olisav57, Yesterday, 07:39 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_ChelseaB  
      Started by cocoescala, 10-12-2018, 11:02 PM
      7 responses
      944 views
      0 likes
      Last Post Jquiroz1975  
      Working...
      X