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

Is a loop possible within MRO?

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

    Is a loop possible within MRO?

    Hi everyone

    At the moment, I have some code that currently works fine within an MRO* essentially as follows:

    Code:
    MRO(delegate {return
        MACD(4, 8, 4).Avg[0] > 0
        && MACD(6, 12, 6).Avg[0] > 0
        && MACD(8, 16, 8).Avg[0] > 0
        && MACD(10, 20, 10).Avg[0] > 0;
        }, 1, 30);
    My question is this:

    Is there any way I can introduce a loop into the MRO to automate this process, so that instead of having just these four MACD tests, all I would have to do is change one variable so I can have an arbitrary number of them, something like:

    Code:
    for (int i = 2; i <= TopMACD; i++)
                {
                    MACD(2*i, 4*i, 2*i).Avg[0] > 0
                }
    placed somehow within the MRO code. As yet, all my efforts in this direction have failed!

    This may not be possible, of course, but any advice on this will be much appreciated.

    (* For readers new to Ninja: MRO = Most Recent Occurrence: this is a very powerful method)

    #2
    Hello arbuthnot,

    Thank you for you post.

    You will need some value that is generated from this for loop, and likely creating bools to determine if MACD 1, MACD 2, MACD 3, etc. is greater than 0 until your defined "TopMACD" is meet.

    In what context are you looking to use the for loop, will the value(s) be used for the MRO()?

    You would then still need additional variables defined for each run of the for loop for the MACDs you test. Such as fast, slow and smooth.

    Please let me know if I may be of further assistance in this matter.

    Comment


      #3
      Thanks very much, Patrick, for the extremely helpful tips in your reply.

      It seems that a loop, such as the one I was considering, isn't possible within the MRO function. Moreover, it's obvious that the MRO method itself must be based a loop of some description, and I don't think it would be impossible to reproduce this to incorporate the result I was hoping for.

      However, I've thought of a much simpler solution, which isn't very elegant but does do the job perfectly. When I have more time, I may well try to find an attractive coding solution.

      In the meantime, this is how I've achieved the objective:

      I have these lines of code (within the MRO) that I want to increase or decrease in number:

      Code:
           MACD(a, 2*a, a).Avg[0] > 0
          && MACD(b, 2*b, b).Avg[0] > 0
      
           ...
      
          && MACD(j, 2*j, j).Avg[0] > 0;
      I declare a variable:

      Code:
      int topMACD = 6; // the '6' is arbitrary
      Then before the MRO ( and assuming 10 is the maximum no. of lines of this code I need), I place the following:

      Code:
      int a = Math.Min(1, TopMACD);
      int b = Math.Min(2, TopMACD);
      int c = Math.Min(3, TopMACD);
      int d = Math.Min(4, TopMACD);
      int e = Math.Min(5, TopMACD);
      int f = Math.Min(6, TopMACD);
      int g = Math.Min(7, TopMACD);
      int h = Math.Min(8, TopMACD);
      int i = Math.Min(9, TopMACD);
      int j = Math.Min(10, TopMACD);
      This isn't elegant because there's a lot of redundancy here, esp. when choosing a low value for TopMACD. But at least it works - and that's the important thing!

      Much obliged for your suggestions, Patrick, which I will try to use when I can get down to some serious thinking about this.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by funk10101, Today, 12:02 AM
      0 responses
      3 views
      0 likes
      Last Post funk10101  
      Started by gravdigaz6, Yesterday, 11:40 PM
      1 response
      7 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by MarianApalaghiei, Yesterday, 10:49 PM
      3 responses
      10 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by XXtrader, Yesterday, 11:30 PM
      0 responses
      4 views
      0 likes
      Last Post XXtrader  
      Started by love2code2trade, 04-17-2024, 01:45 PM
      4 responses
      28 views
      0 likes
      Last Post love2code2trade  
      Working...
      X