Announcement

Collapse
No announcement yet.

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

    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
            }
        
        }
        ​​

        Comment


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

          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
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X