Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ORB strategy

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

    #16
    Hello jfarman,

    Thank you for the information.

    Since RangeLow is 0, I suspect the value is not ever updating from the default value of 0 (shown in your first screenshot). Even in the Strategy Builder, you can add print statements to each set of actions. If the print shows up, then you know the actions should have been taken. If the print does not show up in the NinjaScript Output window, that means that the condition is never evaluated to true for the action to be taken for that set and you will need to go back and debug the conditions so they are triggered when expected. Even when you are changing the value of RangeHigh or RangeLow, you can add a print to verify the updated value is what is expected. For example, in Set 1 after the RangeHigh is updated, you could add another action in the "Do the following" section to print the value of RangeHigh. This way, you will also get new prints every time the variable is updated and if it is ever updated to an unexpected value you can narrow down where in the script is causing that and why.

    One of my colleagues has broken down some tips for debugging NinjaScript here:


    Thank you for your time and patience.

    Comment


      #17
      Hi again jfarman,

      What is this "RangHigh" I see in Set 1 ? It's not one of your 2 variables ("RangeHigh", "RangeLow") in your Strategy.
      Is this just a typo ? Did you mean "RangeHigh" ? If that's so, you have to correct it.
      (that's why I insisted to see all your Sets, including Set1 & Set2...)

      Comment


        #18
        Hello All!
        Good news is I was finally able to make the range work correctly!! I also figured out an alternative way. Alternatively, if you want to create a range for the first 15 minutes you can create a condition that states "Time = 9:45am". Then under actions, "Range high=high" and "Range low=low". The only stipulation I see is that you will need to have the strategy running on a 15 minute chart. You could do the same for multiple time frames by just adjusting the time to whichever time frame you want and based on what time the chart labels that bar as.

        I was also able to use the time frame conditions to stop any further trades after that subsequent (2nd) bar, however, I'm having trouble getting it to only take 1 trade per day/session. I was able to add a condition where the realized and/or unrealized P/L must equal 0 in order to place a trade. This, combined with only being able to place one trade at a time, stops any further trades after the first regardless of meeting other conditions. This works for market replay trading, but it causes an issue when I try to back test. When back tested, it only takes one trade regardless of the time frame I am testing. Plus I worry that if I were to have any other positions running at the time (in real time), then the strategy would not activate. So I am curious as to how you guys would recommend I achieve this condition and still be able to run the strategy through the analyzer, and not have my P/L affected.

        Lastly, I am trying to figure out how to achieve the desired profit targets with adjusted stop loss steps that I described in the previous post using "contract 1 & contract 2". It doesn't seem like a parabolic stop is what I'm looking for. I tried to create some more variables and then conditions with those variables, but was unable to get what I wanted. What are some options for how I could go about setting this up?

        Thanks for hanging in with me!! I appreciate all your help!

        Comment


          #19
          Hello jfarman,

          Thank you for the update. I am glad to hear that you were able to make some progress!

          As for only taking one trade per day/session, you could use a bool in your strategy that starts out as false. For your entry conditions, check that the bool is false. Once a trade is submitted, you can set it to true so that the entry condition can't evaluate until the bool is reset to false again. If you want it to reset each session, you could set a condition that checks in Misc > First bar of session equals Misc > true. For more information, including an example of how to use a bool in this way, please see the following post:
          Hello I am having an issue: I want to run my strategy 1 time then it automatically disables after it exits until I re-enable the strategy. I don't need it to unclick the enable button or anything I really just need the strategy to not start again after the exit even when the conditions are met. I have tried from previous


          Please elaborate more on what you are looking to achieve with your stop loss and profit targets. What behavior are you expecting vs. the behavior that you are actually seeing in testing? It's possible that the following samples might help to offer some ideas on how you could work with your stops in your strategy:


          Please let me know if I may be of further assistance.

          Comment


            #20
            Thank You Emily! That worked. I also figured out how to move my stop loss as the market price moves in my direction. I created variables based on average entry price to adjust my stops. The only thing I cannot seem to add is a trail stop after the variables conditions are met. I do not see a way to add a trail stop with the conditions and actions, and if I add a trail stop then that trail stop over rides the variables. I created multiple variable bools: LongStop1, LongStop2, TakeProfitLong and set them to false.

            Condition 1: In the Enter Long action, where a trade is initiated, I added Long stop 1=True
            Condition 2: If LongStop1=True Action: Exit Long Stop at average price -2 (This gives me the 2 point stop loss)
            Condition 3: If High=Average entry price +1.25 Action: LongStop1=False & LongStop2=True
            Condition 4: If LongStop2=True Action: Exit Long Stop at average position price + 0.25 (Moves stop to break even plus 1 tick)
            Condition 5: If High=Average entry price +2 Action: TakeProfitLong=True
            Condition 6: If TakePofitLong=True Action: Exit Long Limit at average position price +2 (Creates a 2 point take profit target)

            If I place a profit target or trailing stop loss in the "stops and targets" section then it over rides my variables and they don't trigger at all. I would like to be able to have a hard stop in place on trade initiation, then move the hard stop up after price moves in my direction, and then when price reaches further in my direction initiate a trailing stop to follow it further. From what I'm reading in the other posts it seems this is a common issue that does not have a direct fix. I could use a work around of just adding more variables and conditions as price moves in my direction and remove the take profit...it would just be more convenient to be able to add a trailing stop and would allow for tighter control.

            The other issue I'm having is that the back test function in the strategy analyzer does not yield me any results. I'm sure it's something I'm doing wrong but I can't seem to get it. I do need intra-bar data to run and back test this strategy. Do you have any suggestions for this?

            Thank You!!

            Comment


              #21
              Update...

              I was able to create another set of variables, conditions and actions to have the position exit at my desired profit targets with a limit order. However, I feel as is this is probably the longer way around what I am try to accomplish. And it also does not give me the trail stop function I'd like.

              This is what I am trying to make happen:

              For targets and stops I would like it to take 2 contracts. For explanation purposes, lets assume we are going long in a trade.
              - Contract 1 would have an 8 tick target from entry and 8 tick stop loss from entry. If price reaches/touches 4 ticks above/profit from entry, then stop loss would move to 1 tick above entry. Then profit would be taken at the 8 tick target mark.
              - Contract 2 would have only an 8 tick stop loss from entry. If price reaches/touches 4 ticks above/profit from entry, then stop loss would move to 1 tick above entry. If price reaches/touches 8 ticks above entry, then a trailing stop would initiate with a 6 tick trailing stop. Then the trade would close whenever the trailing stop was triggered or closed manually.​

              Comment


                #22
                Hello jfarman,

                Thanks for the update.

                Were you able to review the TrailBuilderExample_NT8 from the forum post I previously linked? That example uses variables for CurrentTriggerPrice, CurrentStopPrice, TrailFrequency, and TrailStopDistance - by using similar variables and updating those variables based on the conditions you described, you should be able to modify your stop loss and create a trailing stop as desired.

                Please review the examples from the following post again and if you are not getting the desired behavior, please describe what is happening in your strategy vs. what you would like to occur:


                I appreciate your time and patience.

                Comment


                  #23
                  Hello jfarman,

                  Would you be willing to share the script as it is it written right now?

                  Comment


                    #24
                    Hi Emily, can we create a ORB for 1 hour opening range from 09:15 am to 10:15 am and whenever a high or low breaks after 10:15 am the market analyzer will display it there.

                    Comment


                      #25
                      Originally posted by caspian View Post
                      Hi Emily, can we create a ORB for 1 hour opening range from 09:15 am to 10:15 am and whenever a high or low breaks after 10:15 am the market analyzer will display it there.
                      Hello caspian,

                      Thank you for your post and welcome to the NinjaTrader forum community!

                      It sounds as though you are looking to create an indicator rather than a strategy, as an indicator could be added to the market analyzer in an indicator column. You could set your indicator to check for the high or low to break based on the desired conditions, then what are you hoping to display in the Market Analyzer? If you provide a more detailed description of what you are looking for I could provide a simple snippet to demonstrate.

                      I look forward to your reply.

                      Comment


                        #26
                        Hi Emily. i want the market analyzer to perform as a scanner, so i use market profile. i want the market analyzer highligh those futures instruments which has broken todays IB range. this is the initial balace range, which starts from 09:15 am and it ends at 10:15 am. so the days high and low is within this range. now after 10:15 am if the ranges high or low is broken the market analyzer should mark them in red or green color. i am very bad in explaining i am sorry if i confused you.

                        Comment


                          #27
                          Originally posted by caspian View Post
                          Hi Emily. i want the market analyzer to perform as a scanner, so i use market profile. i want the market analyzer highligh those futures instruments which has broken todays IB range. this is the initial balace range, which starts from 09:15 am and it ends at 10:15 am. so the days high and low is within this range. now after 10:15 am if the ranges high or low is broken the market analyzer should mark them in red or green color. i am very bad in explaining i am sorry if i confused you.
                          Hello caspian,

                          Thank you for your reply.

                          This could be done by creating an indicator that saves the high and low from 9:15am-10:15am in variables. Then, after 10:15am, it could check if the Close[0] price is greater than the saved high or less than the saved low. You could do something like use a bool and when the price does not break the high or low, the bool is false. If it does break the high or low, the bool could be set to true. Finally, you could have an indicator plot (this would allow you to add it to the market analyzer) that is a value of 0 when the bool is false and 1 when the bool is true. You could set up conditions in the market analyzer that set the cell to red when it is 0 and green when it is 1.

                          You could use time filters in your strategy to tell if it is between 9:15am-10:15am or after 10:15am. The following reference sample demonstrates how to use time filters - they are used to limit trading hours, but the concept of filtering time in a strategy could be applied to your development of this indicator:


                          For an example of an indicator that uses a plot that changes based on a bool in order to display signals in the Market Analyzer, please see the following:


                          Please let us know if we may be of further assistance.

                          Comment


                            #28
                            Hi emily can you create one for me please

                            Comment


                              #29
                              Originally posted by caspian View Post
                              Hi emily can you create one for me please
                              Unfortunately, in the support department at NinjaTrader it is against our policy to create, debug, or modify, code or logic for our clients. Further, we do not provide C# programming education services or one-on-one educational support in our NinjaScript Support department. This is so that we can maintain a high level of service for all of our clients as well as our associates.

                              That said, through email or on the forum we are happy to answer any questions you may have about NinjaScript if you decide to code this yourself. We are also happy to assist with finding resources in our help guide as well as simple examples, and we are happy to assist with guiding you through the debugging process to assist you with understanding unexpected behavior.

                              You can also contact a professional NinjaScript Consultant who would be eager to create or modify this script at your request or assist you with your script. The NinjaTrader Ecosystem has affiliate contacts who provide educational as well as consulting services. Please let me know if you would like our NinjaTrader Ecosystem team to follow up with you with a list of affiliate consultants who would be happy to create this script or any others at your request or provide one-on-one educational services.​

                              Thank you for your time and patience.

                              Comment


                                #30
                                it gives me error please see the code

                                using System;
                                using NinjaTrader.NinjaScript;
                                using NinjaTrader.Gui.Tools;
                                using NinjaTrader.Cbi;
                                using NinjaTrader.NinjaScript.Strategies;

                                namespace NinjaTrader.NinjaScript.Strategies
                                {
                                public class IBRangeBreakoutScanner : Strategy
                                {
                                private double ibHigh;
                                private double ibLow;
                                private bool ibRangeBroken;

                                protected override void OnStateChange()
                                {
                                if (State == State.SetDefaults)
                                {
                                Description = "IB Range Breakout Scanner";
                                }
                                else if (State == State.DataLoaded)
                                {
                                // Calculate IB range from 09:15 am to 10:15 am
                                ibHigh = Highs[1][1];
                                ibLow = Lows[1][1];
                                }
                                }

                                protected override void OnBarUpdate()
                                {
                                if (BarsInProgress == 1)
                                {
                                if (ibRangeBroken)
                                {
                                // IB range already broken, no need to check further
                                return;
                                }

                                if (Closes[0][0] > ibHigh)
                                {
                                // Price broke above IB high
                                ibRangeBroken = true;
                                Alert("IBHighBreakout", Priority.High, "IB High Breakout", NinjaTrader.Cbi.AlertConstants.Reason.MarketAnalyz er, TextColor.Green, MarketDataType.Last, MarketDataSet.Last);
                                }
                                else if (Closes[0][0] < ibLow)
                                {
                                // Price broke below IB low
                                ibRangeBroken = true;
                                Alert("IBLowBreakout", Priority.High, "IB Low Breakout", NinjaTrader.Cbi.AlertConstants.Reason.MarketAnalyz er, TextColor.Red, MarketDataType.Last, MarketDataSet.Last);
                                }
                                }
                                }
                                }
                                }

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Today, 05:17 AM
                                0 responses
                                52 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                130 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                70 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                43 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                47 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X