Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

IsRising/IsFalling from BarsAgo

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

    IsRising/IsFalling from BarsAgo

    Click image for larger version

Name:	fsdafadsfasdfasgdgagageffaefaefeafafa.png
Views:	173
Size:	25.6 KB
ID:	1212071
    How is it possible to write this to where I can have IsFalling from 1 bars ago and IsRising from 0 bars ago?
    Basically I'm trying to enter a long when its flipped from falling to rising so that it doesnt enter a million trades back to back.
    Thanks

    #2
    Hello ezrollin,

    IsFalling compares the series with 0 bars ago to 1 bar ago.

    if (MySeries[1] < MySeries[0])
    {
    // series is falling
    }

    Just replace the bars ago [1] < less than bars ago [0], with bars ago [2] < less than bars ago [1].


    To have one action per bar, use a bool. In the action set the bool to true. When IsFirstTickOfBar is true set the bool back to false. Require the bool to be false in the condition.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thanks for your reply Chelsea.
      It took me a minute to figure out what you meant but I got it. I'm slow.


      I'm trying to create my own deal to see how many bars back an action occured:
      So I created a custom series as a double for my barsago[?]
      if the condition occured then the action is supposed to set the barsago[] to the series double to show how many bars ago.

      however when I select my custom series action it just sets it to 0 and stays at 0 the whole time (yet I'm sure the condition occured).
      What am I doing wrong??? Thanks

      In easy graphical format:

      Click image for larger version

Name:	fsdafadsfasdfasgdgagageffaefaefeafafa.png
Views:	171
Size:	25.8 KB
ID:	1212372


      Click image for larger version

Name:	fsdafadsfasdfasgdgagageffaefaefeafafa.png
Views:	165
Size:	28.7 KB
ID:	1212373


      Click image for larger version

Name:	fsdafadsfasdfasgdgagageffaefaefeafafa.png
Views:	173
Size:	28.9 KB
ID:	1212374

      Comment


        #4
        Hello,

        Thank you for your note.

        A series has a slot to hold a value for every bar on the chart. If you set a value on a bar and that bar closes, the value is now 1 bar ago and the new bar slot has a value of 0.

        If you want to carry the value forward, in Set 1 set the current bars value to the value of the series from 1 bar ago.

        This example linked below does this with the current bar number.
        with regard to the attached image: Line A is an indicator Line B is the m period MAX of line A Line C is an average of this indicator A Line D is another average of this indicator A is it possible, possibly using the strategy builder, but without adding a temporary variable, to set on the condition: line C crosses below line D

        Is there a way to increment an int in the strategy builder? When I go to set an int equal to itself there's no way to add 1 to it as well. Just wondering if this is possible in the wizard.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Click image for larger version  Name:	fsdafadsfasdfasgdgagageffaefaefeafafa.png Views:	0 Size:	26.1 KB ID:	1212594

          Click image for larger version  Name:	fsdafadsfasdfasgdgagageffaefaefeafafa.png Views:	0 Size:	29.4 KB ID:	1212592

          Is this how I am supposed to do it?
          I dont think what I'm doing will work.
          I'm trying to set that if this condition is true then it became true on this bar[0].
          Thanks
          Last edited by ezrollin; 08-18-2022, 10:54 PM.

          Comment


            #6
            Hello ezrollin,

            I'm trying to set that if this condition is true then it became true on this bar[0].
            If you have a Series<int> (Series of integer values) and call it "ConditionTrueOnBar" you can assign "ConditionTrueOnBar" the value of Misc > CurrentBar, and this Series would hold the bar index that the condition became true on.

            I may not be following entirely on how you plan to use this in your Strategy Builder script, (working with bar indexes is more flexible when you work with unlocked code) but if your goal is to detect IsRising after IsFalling, you would essentially be looking at the last 3 bars (including the current bar) that would look for a "V" or a "^" in shape.

            For example, Close[2] < Close[1] > Close[0] would mean Falling after Rising

            and, Close[2] > Close[1] < Close[0] would mean Rising after Falling
            JimNinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_Jim View Post
              Hello ezrollin,



              If you have a Series<int> (Series of integer values) and call it "ConditionTrueOnBar" you can assign "ConditionTrueOnBar" the value of Misc > CurrentBar, and this Series would hold the bar index that the condition became true on.
              I see so if I write my action like:
              MyTrueBarsago[0] = CurrentBars[Default Input]

              That will make it true on that bar even though its not clear in the name (CurrentBars)? Took me a long time to realize this lol thanks

              Comment


                #8
                Originally posted by NinjaTrader_Jim View Post

                I may not be following entirely on how you plan to use this in your Strategy Builder script, (working with bar indexes is more flexible when you work with unlocked code) but if your goal is to detect IsRising after IsFalling, you would essentially be looking at the last 3 bars (including the current bar) that would look for a "V" or a "^" in shape.

                For example, Close[2] < Close[1] > Close[0] would mean Falling after Rising

                and, Close[2] > Close[1] < Close[0] would mean Rising after Falling

                Click image for larger version

Name:	fsdafadsfasdfasgdgagageffaefaefeafafa.png
Views:	137
Size:	31.8 KB
ID:	1212728

                I dont have the option of working with bars ago on this one so I was trying to make something custom to workaround the limitation thanks

                Comment


                  #9
                  Hello ezrollin,

                  If you want to carry a value forward, you would be setting this to itself, with BarsAgo set to 1.

                  MyTrueBarsago[0] = MyTrueBarsago[1];

                  This sets the current bar value to the previous bar value and 'carries it forward a bar'.

                  Yes, IsRising IsFalling does not have the bars ago. You will need to compare the current bar to the previous bar as advised in posts #2 and #6.
                  Chelsea B.NinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by GussJ, 03-04-2020, 03:11 PM
                  11 responses
                  3,221 views
                  0 likes
                  Last Post xiinteractive  
                  Started by andrewtrades, Today, 04:57 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Manfred  
                  Started by chbruno, Today, 04:10 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post chbruno
                  by chbruno
                   
                  Started by josh18955, 03-25-2023, 11:16 AM
                  6 responses
                  438 views
                  0 likes
                  Last Post Delerium  
                  Started by FAQtrader, Today, 03:35 PM
                  0 responses
                  9 views
                  0 likes
                  Last Post FAQtrader  
                  Working...
                  X