Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Only one Trade Per Day

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

    Only one Trade Per Day

    Could someone give me a few pointers please?

    I am trying to ensure my strategy only trades a maximum of once per day. I had tried to achieve this by having an interger variable called 'tradedtoday'. When I entered into a trade i set the variable to 1. In order to enter a trade, the variable has to be 0. It resets at the begining of a new session. For some reason this doesn't work. I can't see anything worng with the code.

    I was wondering if there are any built in functions that would achieve the same goal? or can anyone see an obvious problem with my intial solution?

    Many thanks

    Mark

    #2
    Your logic is sound. Please provide exact code snippet of what exactly you have currently. Thanks.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      @MJUK10: You can also get the last trades and ask for date and time of the last trade. If there is no trade during this session or day you can place a new one ...

      BTW: For myself, I'm using the variable alternative with a boolean one because it is easier to read and faster than iterating through all past trades ...

      Greets
      DT

      Comment


        #4
        Thanks for replies guys been out of town hence the delay in responding.

        Josh, code is as follows:

        // Entry Condition: Aup
        if (Bars.BarsSinceSession > OR
        && AupConditionSet == 1
        && Avalue == 0
        && (CurrentBar - TriggerAup) > (OR/2)
        && tradedtoday == 0
        )

        {
        // EnterLongStop()
        EnterLong(DefaultQuantity, "");
        Avalue = 1;
        tradedtoday = 1;
        }
        tradedtoday is defined as a interger in the variables section. I would assume that once a trade ,either short or long, is made the tradedtoday condition will no longer be set to 0 so should then cause the trade to not trigger. Any ideas? The short code is exactly the same.

        DT, how would your method work? What functions should I use?

        Cheers

        Mark

        Comment


          #5
          @Mark: I'm using the same logic than you ... with bool-variables

          Code:
          #region Variables
          private bool     tradedLong     = false;
          private bool     tradedShort    = false;
          ....
          #endregion
          Every new day you have to set the variabled back to false ...

          Code:
          protected override void OnBarUpdate()
           {
                  if (ToDay(Time[0]) != ToDay(Time[1]) && 
                      FirstTickOfBar) 
                  {    
                       tradedLong     = false; 
                       tradedShort    = false; 
                       ...
                  }
                  ...
          }
          Before you enter a trade you can check the variables ... like your code below ...

          For the alternative you have to ask the trade collection and then the Time of last trade ...

          Code:
          Trade lastTrade = Performance.AllTrades[Performance.AllTrades.Count - 1]; 
          
          if (lastTrade.Entry.Time ...
          Hope this will help you
          DT

          Comment


            #6
            Thanks DT. I'll give it a go.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            648 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            369 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            108 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            572 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            573 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X