• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Limit trades per direction

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

    Limit trades per direction

    Hey fellas,

    I want to add an input parameter to control the number of trades per direction. I found some code online that should do this. But, the problem I'm running into is that we know the order is filled by an EnterLong or EnterShort statement so we can increment or decrement the counter. In my code, I'm using EnterLongStopMarket and EnterLongStopLimit orders so we're not in an order until it is filled.

    Any suggestions on how to do this? Here's the current sample code:

    protected override void OnBarUpdate()
    {
    //Reset condition

    if (CrossBelow(SMA(20), SMA(89), 1))
    {
    longtrade= 0; //reset long trigger
    }

    //Enter Trade
    if (CrossAbove(CCI(20), 0, 1) && longtrade <= 3)
    {
    EnterLong(1, "Long 1a");
    if (longtrade == 0)
    {
    longtrade = 1;
    }
    if (longtrade >0)
    {
    longtrade = longtrade + 1;
    }
    }
    }

    #2
    Hello PN720,

    Thank you for your note.

    If you are using the managed approach you could use Entries Per Direction and Entry Handling to control this.

    https://ninjatrader.com/support/help...rdirection.htm
    https://ninjatrader.com/support/help...ryhandling.htm

    You could see the following sample which stops a strategy after 3 consecutive losers, for how you can pull previous trades and for which you could base your counter off,
    https://ninjatrader.com/support/foru...ad.php?t=19289

    You could also have a counter in OnOrderUpdate on the fill of your entry order, you could see the following example,
    https://ninjatrader.com/support/foru...ead.php?t=7499

    If neither of these approaches work could you please provide more detail on what you're attempting to do?

    Please let us know if you need further assistance.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      That code sample with the 3 consecutive losses was exactly what I needed to see.

      Thanks, fellas!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by EnveousColnago, Yesterday, 05:43 PM
      7 responses
      36 views
      0 likes
      Last Post Lancer
      by Lancer
       
      Started by PeterGolz, 01-17-2020, 10:42 AM
      11 responses
      73 views
      0 likes
      Last Post reubenlasky  
      Started by utilizator, Today, 11:36 AM
      0 responses
      6 views
      0 likes
      Last Post utilizator  
      Started by EnveousColnago, Today, 07:24 AM
      1 response
      11 views
      0 likes
      Last Post NinjaTrader_ShawnB  
      Started by tornadoatc, Today, 10:31 AM
      0 responses
      4 views
      0 likes
      Last Post tornadoatc  
      Working...
      X