Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

To make a standard Fib setting as part of script

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

    #46
    What if I say actionsOccurred ? More than one.

    private bool actionsOccurred;
    if ((actionsOccurred ==false/* && conditions to trigger actions*/)
    actionsOccurred = true

    Comment


      #47
      Hello trdninstyle,

      It doesn't matter what you name your variable as long as the variable name is unique starts with a letter and doesn't contain syntax characters.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #48
        The point of the s is I'm trying to get my strategy to work. I know now that it works once in a life time and thats it. I would love to have it work more often. How? Come up with something other than

        private bool actionOccurred;
        if ((actionOccurred ==false/* && conditions to trigger action*/)
        actionOccurred = true

        I know I agreed to " Do you want the condition to be true once and then never again?" pg# 23

        Maybe I should have selected "Do you want the condition to not be true if the condition was true in the last 3 bars?" Same page #

        What does that look like? I only want it to color 3 bars even when there is more in a row. But not just once on my entire chart.

        Comment


          #49
          I found some good news, it does work even when I change colors the problem is it only works once, if the chart had a million days on it it will work once & thats it. See the last bar colored? The one after that did not color.

          Please, how can I get this to function more often? More often in the same day.

          Click image for larger version

Name:	2024-12-03 15_01_22-Chart - 5m ETH.png
Views:	89
Size:	21.9 KB
ID:	1326495

          Comment


            #50
            Hello trdninstyle,

            If you want the branching command that sets the bar brushes to evaluate as true multiple times, then you need another branching command to set the actionOccurred variable back to false.
            Discussed in post # 23 and post # 44.

            If you want the bool variable reset after 3 bars where the condition is false, there are multiple ways to structure the code.

            One option would be to:

            Add an int variable to count bars.


            Add an 'else if' clause to the original branching command that checks the counter int variable is less than 3.
            If it is, increment the counter by 1.

            else if (actionOccurred && barCounter < 3)
            {
            barCounter++;
            }

            Add an 'else if' cause (to the original branching command) that checks the counter int variable is 3 then set the counter to 0 and the bool to false to allow for the action to occur again.

            else if (actionOccurred)
            {
            actionOccurred = false;
            barCounter = 0;
            }

            Or you could have an entirely separate branching command with specific logic on when to allow for a new action.



            "But not just once on my entire chart."

            Please be specific. What are the conditions to allow the brushes to be set again after the action has occurred?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #51
              This makes sense, just reading thru it the first time I can see how that would work. This is freaking awesome, and I will digest it and then get to work on it.
              Thank you very much!

              Comment


                #52
                ,

                I looked at adding an int variable to count bars and the other way too, to gain some experience in both. In the first one I'm missing an expression, I tried diff expressions but couldnt get it.
                I placed in private int counter; & private bool isCounting, I kept these private int & isCounting the same for the 2nd option too.


                "Please be specific. What are the conditions to allow the brushes to be set again after the action has occurred?"
                That would be when the low of a bar breaks below the prior bars low. That would end the channel if in a channel, then a 2nd channel begins until a low is breached then that starts a 3rd, where there's usually more sellers than buyer in the 3rd channel going up.

                Click image for larger version  Name:	2024-12-04 09_52_15-NinjaScript Editor - Strategy - ChannelSeqDebugging.png Views:	0 Size:	44.7 KB ID:	1326574 Click image for larger version  Name:	2024-12-04 09_48_43-2024_12_04_09_47_41_NinjaScript_Editor_Strategy_ChannelSeqDebugging.png - Paint.png Views:	0 Size:	32.7 KB ID:	1326575 Click image for larger version  Name:	2024-12-04 09_42_16-Strategy Builder syntax - NinjaTrader Support Forum - DuckDuckGo.png Views:	0 Size:	6.9 KB ID:	1326576


                Here is the 2nd option, this one seems cleaner. In this I still need to make it part of the context per the errors.

                Click image for larger version  Name:	2024-12-04 10_28_20-Chart - 5m ETH.png Views:	0 Size:	49.0 KB ID:	1326577

                "Or you could have an entirely separate branching command with specific logic on when to allow for a new action."
                I'm already using more branching commands of the same for the fibs, historic and not historic.

                I can place both fib options in with the original branch command and it's logic box, can't I? End each one with a semi colon;

                Thank you for your kind help.
                Last edited by trdninstyle; 12-05-2024, 10:52 AM.

                Comment


                  #53
                  Hello trdninstyle,

                  Attached is an example with the suggestions I've made in posts #40, #44, # 50.

                  While the suggestions did work to wait a few bars, it would not have drawn on the last bar where the bool was reset.
                  To account for this, the actionOccurred bool is reset to false in a separate branching command before checking the value on the same bar.

                  ResetNBarsAfterEventExamples_NT8.zip
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #54
                    I'm working on it but I'm a bit confused between the sample zip and this one,



                    else if (actionOccurred && barCounter < 3)
                    {
                    barCounter++;
                    }

                    Add an 'else if' cause (to the original branching command) that checks the counter int variable is 3 then set the counter to 0 and the bool to false to allow for the action to occur again.

                    else if (actionOccurred)
                    {
                    actionOccurred = false;
                    barCounter = 0;
                    }

                    Comment


                      #55
                      Hello,

                      This is what I was mentioning in my previous post.

                      "While the suggestions did work to wait a few bars, it would not have drawn on the last bar where the bool was reset.
                      To account for this, the actionOccurred bool is reset to false in a separate branching command before checking the value on the same bar."

                      The else if would reset as expected, but on that bar it resets it cannot draw. So this was moved above the action branching so it can be reset and drawn on the same bar.​

                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #56
                        "So this was moved above the action branching.."

                        I saw that & I put that up there, but right now I'm confused as to where to put the second action branch. I'll probably see it more clearly in time.






                        public class ChannelSeqDebugging : Strategy
                        {

                        private bool actionsOccurred;
                        private int counter;


                        protected override void OnStateChange()
                        {
                        if (State == State.SetDefaults)
                        {
                        Description = @"1st bar is signal bar, 2nd bar is the trigger bar, 3rd bar is the FT bar. 1 Something is changing, 2 change is happening, 3 then one ft bar.";
                        Name = "ChannelSeqDebugging";
                        Calculate = Calculate.OnBarClose;
                        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;
                        counter = 0;


                        // Disable this property for performance gains in Strategy Analyzer optimizations
                        // See the Help Guide for additional information
                        IsInstantiatedOnEachOptimizationIteration = true;

                        MyBrush = Brushes.Aquamarine;
                        }
                        else if (State == State.Configure)
                        {
                        actionOccurred = false;
                        counter = 0;
                        }

                        }

                        protected override void OnBarUpdate()
                        {
                        if (BarsInProgress != 0)
                        return;

                        if (CurrentBars[0] < 3)
                        return;




                        if (actionOccurred && counter < 3)
                        {
                        actionOccurred = false;
                        counter = 0;
                        }




                        if ((actionsOccurred ==false/* && conditions to trigger action*/)
                        && (Close[2] > Open[2])
                        && (Close[1] > Open[1])
                        && (Close[0] > Open[0])
                        && (Close[2] > High[3])
                        && (Close[1] > High[2])
                        && (Close[0] > High[1])
                        && (Low[1] > Low[2])
                        && (Low[0] > Low[1])
                        && BarBrushes[3] != Brushes.Aquamarine)
                        {
                        actionsOccurred = true;
                        BarBrushes[0] = MyBrush;
                        BarBrushes[1] = MyBrush;
                        BarBrushes[2] = MyBrush;
                        }

                        else if (actionOccurred)

                        {
                        counter++;
                        }

                        }
                        Last edited by trdninstyle; 12-05-2024, 10:51 AM.

                        Comment


                          #57
                          Hello trdninstyle,

                          May I confirm you are understanding the logic and reading the comments in the example on what each part of the code does?
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #58
                            The actionOccurred == false ensures that the command branch happens only once and the in the logic block where actionOccurred=true along w/ MyBrush is what happens. But now we need to reset it back to false so it can be triggered back to true. Thats where else if comes in and the counter so it knows what number to count.

                            It's like a relay float switch it has to reset so it can be triggered again when called on.

                            Comment


                              #59
                              Hello trdninstyle,

                              In the example I have provided the actionOccurred bool is assigned back to false above the action branching command in a separate branching command on lines 63 to 68.

                              This is not in an else-if.

                              May I confirm you are understanding where the bool is being reset to false?
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #60
                                Value[0] = SMA(14)[0]; that sits right under OnBarUpdate, thats the command branch & thats where my command branch goes, a separate one.

                                63-68 if (actionOccurred && barCounter (On my script it would be counter)
                                This gets triggered back to false if the action is greater or equal than the selected # of bars so a new action could occur & it gets reset back to 0;


                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by NullPointStrategies, Yesterday, 05:17 AM
                                0 responses
                                65 views
                                0 likes
                                Last Post NullPointStrategies  
                                Started by argusthome, 03-08-2026, 10:06 AM
                                0 responses
                                139 views
                                0 likes
                                Last Post argusthome  
                                Started by NabilKhattabi, 03-06-2026, 11:18 AM
                                0 responses
                                75 views
                                0 likes
                                Last Post NabilKhattabi  
                                Started by Deep42, 03-06-2026, 12:28 AM
                                0 responses
                                45 views
                                0 likes
                                Last Post Deep42
                                by Deep42
                                 
                                Started by TheRealMorford, 03-05-2026, 06:15 PM
                                0 responses
                                50 views
                                0 likes
                                Last Post TheRealMorford  
                                Working...
                                X