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 franatas, Today, 01:53 AM
          2 responses
          13 views
          0 likes
          Last Post franatas  
          Started by DawnTreader, 05-08-2024, 05:58 PM
          8 responses
          32 views
          0 likes
          Last Post DawnTreader  
          Started by haas88, 03-21-2024, 02:22 AM
          19 responses
          220 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by ZeroKuhl, Yesterday, 04:31 PM
          4 responses
          33 views
          0 likes
          Last Post ZeroKuhl  
          Started by cupir2, Yesterday, 07:44 PM
          3 responses
          22 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X