Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

One trade per day

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

    One trade per day

    Is there still no way for a non-programmer to limit a strategy to one trade per day?

    I have looked at some old posts containing code but given my strategy is already complicated enough I don't know where to put the sample code to limit the strategy to one trade per day.

    There should really be some work done on the strategy builder interface to make it more functional and user-friendly for non-programmers.

    #2
    User_456,

    Is this a strategy builder strategy that you've created and want to add a filter to only trade once per day? Is your comment about usability on the Strategy Builder specific to this feature or are you saying that in general. Appreciate any additional feedback you would be willing to give on it.

    -Brett

    Comment


      #3
      Yes sir, it's about usability in the Strategy Builder. Both specific and general. It seems to me that there should be some more basic features of the Strategy Builder that don't require coding. I'm sure that I'm in the minority of users who have no background in programming and the forums do have a great of support but a timer or scheduler for Strategy Builder would seem to be a basic building block of the interface.

      Comment


        #4
        Can someone please tell me why my strategy is executing more than one trade per day after attempting to incorporate the below code to limit "MaxTrades" to 1? Thanks very much in advance.

        public class OpeningRangeUnlocked : Strategy
        {
        private HighLowByTimeRange HighLowByTimeRange1;
        private int maxTrades = 1; // This variable sets the maximum number of trades to take per day.
        private int tradeCounter = 0; // This variable represents the number of trades taken per day.

        protected override void OnStateChange()
        {
        if (State == State.SetDefaults)
        {
        Description = @"";
        Name = "OpeningRangeUnlocked";
        Calculate = Calculate.OnEachTick;
        EntriesPerDirection = 1;
        EntryHandling = EntryHandling.AllEntries;
        IsExitOnSessionCloseStrategy = true;
        ExitOnSessionCloseSeconds = 30;
        IsFillLimitOnTouch = false;
        MaximumBarsLookBack = MaximumBarsLookBack.TwoHundredFiftySix;
        OrderFillResolution = OrderFillResolution.Standard;
        Slippage = 0;
        StartBehavior = StartBehavior.WaitUntilFlat;
        TimeInForce = TimeInForce.Gtc;
        TraceOrders = false;
        RealtimeErrorHandling = RealtimeErrorHandling.StopCancelClose;
        StopTargetHandling = StopTargetHandling.PerEntryExecution;
        BarsRequiredToTrade = 20;
        // Disable this property for performance gains in Strategy Analyzer optimizations
        // See the Help Guide for additional information
        IsInstantiatedOnEachOptimizationIteration = true;
        MaxTrades = 1;
        }
        else if (State == State.Configure)
        {
        SetProfitTarget(@"LongMarket", CalculationMode.Ticks, 8);
        SetStopLoss(@"LongMarket", CalculationMode.Ticks, 8, false);
        SetProfitTarget(@"ShortMarket", CalculationMode.Ticks, 8);
        SetStopLoss(@"ShortMarket", CalculationMode.Ticks, 8, false);
        HighLowByTimeRange1 = HighLowByTimeRange(8, 30, 8, 50);
        HighLowByTimeRange1.Plots[0].Brush = new SolidColorBrush(Colors.Chartreuse);
        HighLowByTimeRange1.Plots[1].Brush = new SolidColorBrush(Colors.Red);
        AddChartIndicator(HighLowByTimeRange1);
        }
        }

        protected override void OnBarUpdate()
        {
        // Make sure there are enough bars.
        if (CurrentBars[0] < 1)
        return;

        // Reset the tradeCounter value at the first tick of the first bar of each session.
        if (Bars.IsFirstBarOfSession && IsFirstTickOfBar)
        {
        Print("resetting tradeCounter");
        tradeCounter = 0;
        }

        // If the amount of trades is less than the permitted value and the position is flat, go on to the next set of conditions.
        if (tradeCounter < MaxTrades && Position.MarketPosition == MarketPosition.Flat)

        // Set 1
        if ((Time[0].TimeOfDay > new TimeSpan(8, 50, 01))
        && (Time[0].TimeOfDay < new TimeSpan(10, 30, 00))
        && ((Close[0] + (2 * TickSize)) >= HighLowByTimeRange1.HighestHigh[0]))
        {
        EnterLong(Convert.ToInt32(DefaultQuantity), @"LongMarket");
        tradeCounter++;
        }
        // Set 2
        if ((Time[0].TimeOfDay > new TimeSpan(8, 50, 01))
        && (Time[0].TimeOfDay < new TimeSpan(10, 30, 00))
        && ((Close[0] + (-2 * TickSize)) <= HighLowByTimeRange1.LowestLow[0]))
        {
        EnterShort(Convert.ToInt32(DefaultQuantity), @"ShortMarket");
        tradeCounter++;
        }
        }

        #region Properties
        [Display(GroupName="Parameters", Description="Maximum number of trades to take per day.")]
        public int MaxTrades
        {
        get { return maxTrades; }
        set { maxTrades = Math.Max(1, value); }
        }
        #endregion

        Comment


          #5
          You are using some kind of open block syntax, and it is the cause of your problem. Enclose all blocks: do not use consecutive if statements without properly nesting them in blocks. I know that the syntax allows it. It does not mean that you have to do it. This kind of hard-to-find bug is why I always nest if's properly.

          Here is your issue. Regardless of this:
          Code:
          if (tradeCounter < MaxTrades && Position.MarketPosition == MarketPosition.Flat)
          your "Set 2" will always be processed, because your if statement, as it is not followed by a properly enclosed block will apply to only the next immediate statement, effectively, your "Set 1" Use braces and create a proper block for all the statements that you want an if statement to filter, even if it is only one statement.

          Comment


            #6
            Hello user_456,

            I wanted to skip back to this post:

            Originally posted by user_456 View Post
            Yes sir, it's about usability in the Strategy Builder. Both specific and general. It seems to me that there should be some more basic features of the Strategy Builder that don't require coding. I'm sure that I'm in the minority of users who have no background in programming and the forums do have a great of support but a timer or scheduler for Strategy Builder would seem to be a basic building block of the interface.
            We can take in feature requests but I am unable to see what specifically you are requesting. In regard to the first post, there are various ways to limit a strategy or form conditions that limit a strategies trades, but it would depend on the conditions you are looking to use.

            Could you provide some specific details regarding the features you would like to see or the features that are currently there that you feel need changed?

            I can relay information to development for further review.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Sure, and thanks for following up. I would suggest that as much as you guys monitor the forums and are very responsive in that regard, you might consider keeping track of the most common questions on the forums and building those features in that can easily be added to the GUI.

              For example, I've seen numerous posts similar to my question about coding a timer or scheduler into a strategy. Why not just build that into the Strategy Builder interface? Another example, colored wicks... background colors that are different between regular and extended hours.. or overlaying volume on a chart without having to configure an indicator... or an option to extend a horizontal line left of the current price... Why not just incorporate that as a setting like in TOS and other programs?

              Some common sample strategies that can be easily customized would be great too. I know I can download some in various locations and have done so, however I would tend to trust built-ins more since I'm not a coder.

              I'm very aware that NT has a very robust ecosystem so I'm not suggesting trying to make NT into TOS. But some people are not made to be coders. I am one of them... dyslexic

              Let me end by saying your support is outstanding & friendly. Thanks very much for the follow up.

              Comment


                #8
                Hello,

                Thank you for the additional details. So it is known, we do track all of these submissions as features requests to understand the features people want to see, please know this will be reviewed. There are many items being requested and reviewed so it is not certain when or if an item would be implemented but we are tracking these items.

                For example, I've seen numerous posts similar to my question about coding a timer or scheduler into a strategy. Why not just build that into the Strategy Builder interface?
                For the timer, are you referring to a Start time/date picker and End time/date picker for a condition? Could you provide a specific example of what you are trying to see implemented?

                Currently you can add time based conditions to create schedules or times that logic can or can not be executed. Strategies are event driven by market events and order events, a timer specifically would not necessarily make sense if you are referring to an actual timer that re occurs at X interval because it would not be synced with the events of the market or strategy. If you are referring to an actual timer, could you provide a use case as an example?

                colored wicks... background colors
                You can currently color the Background, a Bar, a bars Outline from the builder, these are in the Actions -> Drawing Tools.
                I will add a request for "Wick" and also potentially that this gets its own section to not be confused with Drawing objects.

                overlaying volume on a chart without having to configure an indicator
                Strategies in general are capable of basic plotting now, I can put in a request to see if this could be exposed as a tab in the builder.

                or an option to extend a horizontal line left of the current price
                This can currently be accomplished using a Ray, a Ray will extend to one edge of the panel, using a start bar of 0 and a end bar of 1 can point this horizontally left if the same price is used for both Price anchors.

                Some common sample strategies that can be easily customized would be great too. I know I can download some in various locations and have done so, however I would tend to trust built-ins more since I'm not a coder
                I can submit a request for further samples for the builder, in general the platform does not provide full complete working strategies as this would entail that it should "work" correctly for everyone's trading. Instead we provide base frameworks for core concepts that you could build off of as it would be highly specific on what you want to do with your trading. I will submit a request for further examples of concepts using the wizard much like the NinjaScript samples and tips page on the forum.

                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment


                  #9
                  No expectations, just providing feedback per your questions. Along those lines, please accept my suggestions as very secondary to fixing existing bugs and system crashes.

                  "For the timer, are you referring to a Start time/date picker and End time/date picker for a condition? Could you provide a specific example of what you are trying to see implemented?

                  "Currently you can add time based conditions to create schedules or times that logic can or can not be executed. Strategies are event driven by market events and order events, a timer specifically would not necessarily make sense if you are referring to an actual timer that re occurs at X interval because it would not be synced with the events of the market or strategy. If you are referring to an actual timer, could you provide a use case as an example? "

                  Yes sir, but please keep in mind that my suggestions are from a non-coder standpoint. So while C# can do most anything, I'm suggesting common issues that might be suited for the GUI in Strategy Builder so that the coding for very common purposes is not necessary.

                  To answer your question, a "Run once per x(day, hour, minute)" field in the GUI in Strategy Builder is sort of what I'm suggesting. For an opening range breakout strategy, this might be an appropriate use of a timer or scheduler.

                  On the background color, I know everything can be done programmatically but again I'm suggesting a simple GUI change that allows a color picker for extended hours trading versus regular trading hours. There are numerous posts on here about incorporating this code in an indicator.

                  As for pre-built strategies, I'm not saying they have to be profitable or catered to specific traders. This would be virtually impossible. I'm suggesting a wider range of strategy approaches so that non-coders will have a larger selection of strategies from which to tweak in order to make them their own such as ORB's, Market Profile, Volume Profile, common patterns, common candlesticks.

                  Thanks again for your time.

                  Comment


                    #10
                    Yes.

                    I would create a boolean variable (true / false) and have it reset at a certain time (perhaps midnight?) to a "false" value, then when a trade is executed, change it to "true.

                    That could be tested on every bar so that if a trade had been executed already (i.e. "true") then it would just quit and wait until it was reset.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by PaulMohn, Today, 12:36 PM
                    1 response
                    14 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Started by yertle, Yesterday, 08:38 AM
                    8 responses
                    36 views
                    0 likes
                    Last Post ryjoga
                    by ryjoga
                     
                    Started by rdtdale, Today, 01:02 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_LuisH  
                    Started by alifarahani, Today, 09:40 AM
                    3 responses
                    17 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Started by RookieTrader, Today, 09:37 AM
                    4 responses
                    20 views
                    0 likes
                    Last Post RookieTrader  
                    Working...
                    X