Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.




    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,


    You could also have a counter in OnOrderUpdate on the fill of your entry order, you could see the following example,
    The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


    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 mattbsea, Today, 05:44 PM
      0 responses
      1 view
      0 likes
      Last Post mattbsea  
      Started by RideMe, 04-07-2024, 04:54 PM
      6 responses
      31 views
      0 likes
      Last Post RideMe
      by RideMe
       
      Started by tkaboris, Today, 05:13 PM
      0 responses
      2 views
      0 likes
      Last Post tkaboris  
      Started by GussJ, 03-04-2020, 03:11 PM
      16 responses
      3,281 views
      0 likes
      Last Post Leafcutter  
      Started by WHICKED, Today, 12:45 PM
      2 responses
      19 views
      0 likes
      Last Post WHICKED
      by WHICKED
       
      Working...
      X