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

To write a shorter version for multiple bars closing greater than the open

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

    To write a shorter version for multiple bars closing greater than the open

    Instead of writing it like this: Close(3) > Open(3) && Close(2) > Open(2) && Close(1) > Open(1) && Close(0) > Open(0)

    Can I write it more like this?

    Close(3),2,1,0)); Similar to the slope which is where I saw it but want to apply it to the bars. Print(Slope(SMA(20), 10, 0));

    If I can, I just want to see the correct way of writing it. Thanks.


    #2
    Hi trdninstyle, thanks for posting. The only way to index the price value is Close[], with brackets. There is no short hand way to write this, you can add the code into a method so you do not need to keep writing the same code multiple times.

    Kind regards,

    -ChrisL
    Chris L.NinjaTrader Customer Service

    Comment


      #3
      Thanks, ChrisL,

      Can you please show me a brief example? Just so I can better understand.

      Comment


        #4
        Hi trdninstyle, Im happy to help out. Please make sure to study the C# fundamentals as it will greatly help in speeding up NinjaScript development process. The Microsoft documentation is the best place for text based tutorials on the C# basics:

        https://learn.microsoft.com/en-us/do...tructs/methods (publicly available)

        One way of doing this would be:


        Code:
        public class MyCustomIndicatorClass : Indicator
        {
        
        private bool MyCustomMethod()
        {
        return (Close[0] > Open[0]);
        }
        
        protected override void OnBarUpdate()
        {
        
            if(MyCustomMethod())
            {
               //the method returned true
            }
        
        }
        ​​
        Chris L.NinjaTrader Customer Service

        Comment


          #5
          Thank you for showing me. I will study that.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Jonafare, 12-06-2012, 03:48 PM
          5 responses
          3,984 views
          0 likes
          Last Post rene69851  
          Started by Fitspressorest, Today, 01:38 PM
          0 responses
          2 views
          0 likes
          Last Post Fitspressorest  
          Started by Jonker, Today, 01:19 PM
          0 responses
          2 views
          0 likes
          Last Post Jonker
          by Jonker
           
          Started by futtrader, Today, 01:16 PM
          0 responses
          7 views
          0 likes
          Last Post futtrader  
          Started by Segwin, 05-07-2018, 02:15 PM
          14 responses
          1,791 views
          0 likes
          Last Post aligator  
          Working...
          X