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 siroki, Today, 03:22 AM
      0 responses
      11 views
      0 likes
      Last Post siroki
      by siroki
       
      Started by nailui, Today, 03:01 AM
      1 response
      12 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by an.fedorov, Today, 02:32 AM
      0 responses
      10 views
      0 likes
      Last Post an.fedorov  
      Started by rustyspring, Today, 01:31 AM
      1 response
      14 views
      0 likes
      Last Post NinjaTrader_Jason  
      Started by op1031, Today, 12:26 AM
      0 responses
      12 views
      0 likes
      Last Post op1031
      by op1031
       
      Working...
      X