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

    #61
    /* the action branching command will only evaluate as true if actionOccurred is false */
    if (actionOccurred == false (Thereby allowing a new action to take place)

    /* && your conditions to trigger action here.

    This is where my original command branch goes.

    for this simple example I'll use the high of the current bar is greater than an SMA,
    which will be true for several bars in a row */

    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)

    I guess you had to walk me through it.

    Comment


      #62
      Hello trdninstyle,

      Value[0] = SMA(14)[0]; is just for the example. This sets a plot to the value of an SMA. This is not where the actionOccurred bool is reset to false.
      This is also not the action branching command. The action branching command is the one where the logic block triggers the action. In the example script the action is to draw a dot. In your script the action is to set BarBrushes.
      Chelsea B.NinjaTrader Customer Service

      Comment


        #63
        Okay, I'm getting there. This is how I initially copied it

        Click image for larger version  Name:	2024-12-04 16_23_41-NinjaScript Editor - Indicator - ResetNBarsAfterEventExamples.png Views:	0 Size:	75.1 KB ID:	1326671

        Click image for larger version  Name:	2024-12-04 16_46_21-2024_12_04_16_38_11_NinjaScript_Editor_Indicator_ResetNBarsAfterEventExamples.pn.png Views:	0 Size:	77.8 KB ID:	1326676

        Click image for larger version

Name:	2024-12-04 17_02_15-NinjaScript Editor - Strategy - ChannelSeqDebugging.png
Views:	24
Size:	18.5 KB
ID:	1326678
        4 errors on actionOccurred
        Last edited by trdninstyle; 12-04-2024, 04:04 PM.

        Comment


          #64
          The actionOccurred has an error out of context. Could you please show me what I do have right and where it is wrong.


          Click image for larger version

Name:	2024-12-05 11_17_24-NinjaScript Editor - Strategy - ChannelSeqDebugging.png
Views:	32
Size:	58.5 KB
ID:	1326718 Click image for larger version

Name:	2024-12-05 11_19_17-NinjaScript Editor - Strategy - ChannelSeqDebugging.png
Views:	24
Size:	53.4 KB
ID:	1326719 Click image for larger version

Name:	2024-12-05 11_20_46-Chart - 5m ETH.png
Views:	27
Size:	85.5 KB
ID:	1326720

          Comment


            #65
            Hello trdninstyle,

            I see you have a private variable named actionsOccurred declared in the scope of the class.

            Where do you have a variable named actionOccurred declared?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #66
              I Gotcha lol

              I fixed that and turned around the > so it would be greater, if (actionOccurred && barcounter > 3).
              It works like a charm now even after I change colors. Thanks

              Comment


                #67
                The else if (actionOccurred) the if (actionOccurred && barcounter >3) and else if (State == State.Configure) items are done just once and it applies throughout the script?

                Because as I started to do the bear side & I only got to the actionOccurred = true; in the logic block compiled it & I checked the chart and it worked for that too. Or should I place those items in there too? For the bear side in case it causes problems later.

                I don't want to put items in there if they are not needed.

                Thank you

                Comment


                  #68
                  Hello trdninstyle,

                  An 'else if' clause only applies the 'if' clause it is below.
                  Meaning you could adjust the code to separate the 'else if' branching command and logic block that increments the barCounter variable.
                  Or you could add a second bool variable and actionOccured and use those in similar code for another action.

                  Use prints to understand the behavior of your code. You can print all values in a condition and a value before it is used to see how everything is processing.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #69
                    I can use the else if for the fib drawings because right now it draws too many, I mean, for the 'weaker' channel then another strong bar it turns into a strong channel and it draws 2 fibs, one for the weaker and one for the stronger and it's too messy. or I should work on the OnRender for those.

                    But anyway, on the bear side it's working without those else if etc below it, see the pic please. It paints only 3 bars when there are 4 or more, which is good.

                    It's these two items thats making it work;
                    (actionOccurred == false/* && conditions to trigger action*/)
                    actionOccurred = true;

                    It must be picking up on the else if scenarios from the original. But what your saying is, if I wanted something different here I could put it under here & write it.

                    Click image for larger version

Name:	2024-12-05 14_56_15-NinjaScript Editor - Strategy - ChannelSequence.png
Views:	35
Size:	65.0 KB
ID:	1326751 Click image for larger version

Name:	2024-12-05 15_11_06-Chart - 5m ETH.png
Views:	24
Size:	7.0 KB
ID:	1326752

                    Comment


                      #70
                      Or you could add a second bool variable and actionOccured and use those in similar code for another action.
                      private bool actionOccurred;
                      private bool strongerFib;

                      I added a second bool strongerFib to work with actionOccurred. Would I need to have the else if laid out like the one I just got done with? Or do I just need one else if to go between the weaker fib command branch and the stronger fib command branch. Just for the fib command branch not the actual command branch for coloring of the bars.

                      Here's how I have it, I know it's not how you would write it up lol, it compiles but its not applicable.

                      Click image for larger version  Name:	2024-12-06 10_52_27-2024_12_06_10_46_25_NinjaScript_Editor_Strategy_ChannelsDebugging.png.png Views:	0 Size:	102.7 KB ID:	1326833 Click image for larger version  Name:	2024-12-06 10_57_58-2024_12_06_10_55_00_NinjaScript_Editor_Strategy_ChannelsDebugging.png.png Views:	0 Size:	102.7 KB ID:	1326834

                      Comment


                        #71
                        How could I make these fib drawings to draw only the called 3 bars thats being colored? And not from the bars that print afterwards.


                        Click image for larger version

Name:	2024-12-10 08_41_36-2024_12_10_08_38_39_Chart_5m_ETH.png.png
Views:	17
Size:	29.4 KB
ID:	1327139 Click image for larger version

Name:	2024-12-10 08_42_34-2024_12_10_08_33_37_Chart_5m_ETH.png.png
Views:	16
Size:	12.7 KB
ID:	1327140 Click image for larger version

Name:	2024-12-10 08_43_06-2024_12_10_08_34_30_Chart_5m_ETH.png.png
Views:	15
Size:	19.7 KB
ID:	1327141
                        Click image for larger version

Name:	2024-12-10 08_50_34-NinjaScript Editor - Strategy - Channels.png
Views:	15
Size:	23.6 KB
ID:	1327142

                        Comment


                          #72
                          Hello trdninstyle,

                          Put the call to Draw.FibonacciRetracements() in the same logic block as the BarBrushes assignments.
                          Chelsea B.NinjaTrader Customer Service

                          Comment


                            #73
                            I thought about that before & tried it but I did it again and what happens is, if I don't select FibLookBack it won't color in the 3 bars. I have to also put FibLookBack == true in the command branch, unless I make two command branches, one without FibLookBack and the Draw.FibonacciRetracements() in logic block then one with it.

                            I tried what I just explained above, it doesn't draw the fib but it does keep the 3 bars colored in. Would I have to keep all of the else if's the same for the second command branch & logic block? I placed the 2nd one just under the first one without repeating all of the else if 's.

                            Click image for larger version  Name:	2024-12-10 10_12_49-Chart - 5m RTH.png Views:	0 Size:	98.8 KB ID:	1327165

                            I'll remove the && BarBrushes[3] != Brushes.Aquamarine) on the 2nd one, then try it.
                            Makes no difference.
                            Last edited by trdninstyle; 12-10-2024, 09:23 AM.

                            Comment


                              #74
                              Hello trdninstyle,

                              I'm not advising to make changes to the branching commands or to add this FibLookBack to the branching command.

                              If you are trying to make the drawing object call optional, then nest a condition within the (outer branch's) logic block.

                              if ((actionsOccurred ==false/* && conditions to trigger action*/)
                              {
                              BarBrushes[0] = MyBrush;

                              if (FibLookBack == true)
                              {
                              Draw.FibonacciRetracements();
                              }
                              }

                              Keep in mind a basic understanding of C# programming is prerequisite to writing NinjaScript code.
                              Chelsea B.NinjaTrader Customer Service

                              Comment


                                #75
                                Like this?

                                Click image for larger version

Name:	2024-12-10 11_33_59-2024_12_10_11_33_10_Chart_5m_RTH.png.png
Views:	14
Size:	50.7 KB
ID:	1327180

                                Comment

                                Latest Posts

                                Collapse

                                Topics Statistics Last Post
                                Started by tmk-c, 07-19-2017, 11:29 PM
                                6 responses
                                1,685 views
                                0 likes
                                Last Post Brightredmegaphone  
                                Started by Trader4Life, Today, 09:20 PM
                                0 responses
                                2 views
                                0 likes
                                Last Post Trader4Life  
                                Started by WileCoyote, Today, 08:26 PM
                                0 responses
                                8 views
                                0 likes
                                Last Post WileCoyote  
                                Started by madankumars, 11-18-2019, 11:12 AM
                                10 responses
                                175 views
                                0 likes
                                Last Post ulisesguerrero  
                                Started by rrsch, Today, 10:26 AM
                                2 responses
                                12 views
                                0 likes
                                Last Post rrsch
                                by rrsch
                                 
                                Working...
                                X