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

How to limit strategy to one trade per day?

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

    How to limit strategy to one trade per day?

    I have a strategy that works well--sort of--except that I only want it to take only one trade per day. Any ideas?

    #2
    Billy, you'll have to use some sort of a true/false (boolean) flag to check whether or not a trade has been placed already in the day combined with a date/time checker to reset the flag every new day.

    Something like this:
    Code:
    // in variables
    bool alreadyTradedToday = false;
    
    OnBarUpdate()
    {
       if (CurrentBar < 2) return;
       if (Time[0].DayOfWeek != Time[1].DayOfWeek) // new day, reset bool flag
       {   alreadyTradedToday = false; }
    
       if ([Long Entry Conditions are true] && alreadyTradedToday == false)
       {
          alreadyTradedToday = true;
          EnterLong();
       }
       
        // same, but opposite for shorts
    }
    AustinNinjaTrader Customer Service

    Comment


      #3
      Thanks, Austin. I'll give it a try.

      Comment


        #4
        This is really useful thanks!

        How would you change it if you only wanted 1 trade per month?

        Thanks!

        Comment


          #5
          Hello freddy250,

          Thank you for your inquiry.

          All you would need to do is change Time[0].DayOfWeek and Time[1].DayOfWeek to Time[0].Month and Time[1].Month.

          I would suggest looking at this link to learn more about the DateTime structure, which is what a Time[index] returns: https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

          Please, let us know if we may be of further assistance.
          Zachary G.NinjaTrader Customer Service

          Comment


            #6
            perfect thanks!

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by tsantospinto, 04-12-2024, 07:04 PM
            7 responses
            126 views
            0 likes
            Last Post aligator  
            Started by futtrader, 04-21-2024, 01:50 AM
            5 responses
            56 views
            0 likes
            Last Post NinjaTrader_Eduardo  
            Started by PeakTry, Today, 10:49 AM
            0 responses
            2 views
            0 likes
            Last Post PeakTry
            by PeakTry
             
            Started by llanqui, Today, 10:32 AM
            0 responses
            5 views
            0 likes
            Last Post llanqui
            by llanqui
             
            Started by StockTrader88, 03-06-2021, 08:58 AM
            45 responses
            3,994 views
            3 likes
            Last Post johntraderuser2  
            Working...
            X