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

MRO() issue

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

    MRO() issue

    Hello,
    I'm having an issue with the MRO and trying to nail down the the proper variables in order to have an beginning and ending to draw a line. Because I'm using the MRO I can't just use the CurrentBar as my variable so I tried CurrentBar - barsAgo. Using the Print() (as I showed in the picture) I am indeed getting the right bar number to start and end the line (trust me on that), but when I plug those variables into a Drawline() or DrawDiamond() the lines and diamonds get placed at the very beginning of the chart. Can someone give me a clue as to why this is happening?
    Thanks

    Code:
    if(start_of_A &&  CrossBelow(RSI(14,3), 50, 1))
       {
         int barsAgo = MRO(delegate {return Stochastics(7, 14, 3).K[0] > 78 &&                   Stochastics(7, 14, 3).K[0] < Stochastics(7, 14, 3).K[1]
     && Stochastics(7, 14, 3).K[1] > Stochastics(7, 14, 3).K[2];}, 1, 15);
      if(barsAgo > -1)
              {                                
                 end_of_A = CurrentBar - barsAgo;
                 DrawDiamond("End of A" + CurrentBar, true, end_of_A , High[end_of_A] + .05, Color.Green);
                 DrawLine("A Line" + CurrentBar, start_of_A1, Low[ start_of_A1], end_of_A, High[end_of_A], Color.Red);
                   Print(Time[0] + " start_of_A1 " + start_of_A1);
                    Print(Time[0] + " High " + end_of_A);
                    start_of_A = false;
               }
                                
        }
    Attached Files

    #2
    Hello,

    Thank you for the question.

    Did you try just using your barsAgo variable?

    The MRO returns a BarsAgo so you could use that value directly with a drawing object as they input a BarsAgo value.

    Can you confirm if this works in your example?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Jesse,
      Thanks for your help on this. I took your advice and used the barsAgo for the ending variable of the DrawLine() and the lines are concluding in the right spot, but each line is still starting at the beginning of the chart which tells me that the first variable is being set to 0. I'm using another MRO to set the value of the first variable, but that variable is only declared within the MRO so if I try to use it in the next MRO it's value is 0. Can you think of any way around this?

      Comment


        #4
        Hello,

        You would need to check the values you are passing to the line. If the line is starting at the Beginning or left most of the chart, likely the Current bar is being used as that would be the amount of bars ago from the current bar.

        The BarsAgo for a line would start at 0 which would be the CurrentBar or right most bar, any number Greater than 0 would take you left or backwards in time.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment


          #5
          Jesse,
          I checked the start variable and it is indeed giving the proper bar number to start the lines, but when the line is printed somehow that variable is being changed to 0. I think this issue is withing the MRO. The barsAgo was given value in the current MRO and the start_of_A1 was given value inside another MRO. The Print() is showing the proper value for start_of_A1 never the less once the line is drawn the value is 0.
          Code:
          DrawLine("A Line" + CurrentBar, start_of_A1, Low[start_of_A1], barsAgo, High[barsAgo], Color.Red);
          Print(Time[0] + " start_of_A1 " + start_of_A1);

          Comment


            #6
            I figured out what needed to be done to fix this and in case someone else has an MRO question I'll describe what I did.
            In order to get the first MRO variable to work in the second MRO condition, to print a line, a new int inside the first MRO need to be declared.
            Code:
            beginning_of_A = CurrentBar - barsAgo1;
            Then in the 2nd MRO I needed to declare the barsAgo1 as an int and assign it beginning_of_A.
            Code:
            int barsAgo1 = beginning_of_A;
            Once this was done the barsAgo1 int would work inside the second MRO.
            Code:
            DrawLine("A Line" + CurrentBar, CurrentBar - barsAgo1, Low[CurrentBar - barsAgo1], barsAgo, High[barsAgo], Color.Red);
            Once this was done the line would draw.
            Last edited by CaptainAmericaXX; 11-19-2015, 01:49 PM. Reason: Figured out what needed done

            Comment


              #7
              I'm having another MRO issue.
              My code is this:
              Code:
              int barsAgo = MRO(delegate {return temp_High_Price[0] > 0 || temp_High_Price[1] > 0;}, 1, 5);
                    if (barsAgo > -1){
                       Print("***");
                       Print(CurrentBar);
                       Print("barsAgo = " + barsAgo);
                       Print("The bar high was[0] " + temp_High_Price[0]);
                       Print("The bar high was[1] " + temp_High_Price[1]);
                       Print("The bar high was[2] " + temp_High_Price[2]);
                       Print("***");
                                      }    
                          }
              In Output I get:
              Code:
              ***
              300
              barsAgo = 1
              The bar high was[0] 0
              The bar high was[1] 0
              The bar high was[2] 56.68
              ***
              My question is: How did the MRO evaluate to true and return barsAgo = 1 when both temp_High_Price[0] & [1] = 0? It wasn't until [2] that temp_High_Price got a value greater than 0. This is happening multiple times in my code.
              I am using the MRO inside a for loop.
              Last edited by CaptainAmericaXX; 12-02-2017, 10:31 AM. Reason: Giving more information

              Comment


                #8
                Hello,

                Thank you for the post.

                I am unable to tell from this sample what may be happening, do you have a more complete sample with a specific test case that shows the output you provided?

                I had tried creating a DataSeries and filling it with data, but because there are no bars where a zero price is reported in the series this is not the same test. Could you provide a specific example of what you are seeing?

                You could also try substituting temp_High_Price with a Close series to check if that also has the same problem, I would guess not in case there are no occurrences with a 0 price.

                Also In your temp_High_Price logic, is there a specific reason why there would be a zero price on bar 300? Was this a valid data point or was a price set for those bars in the data series?


                I look forward to being of further assistance.
                JesseNinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by DJ888, 04-16-2024, 06:09 PM
                6 responses
                18 views
                0 likes
                Last Post DJ888
                by DJ888
                 
                Started by Jon17, Today, 04:33 PM
                0 responses
                1 view
                0 likes
                Last Post Jon17
                by Jon17
                 
                Started by Javierw.ok, Today, 04:12 PM
                0 responses
                6 views
                0 likes
                Last Post Javierw.ok  
                Started by timmbbo, Today, 08:59 AM
                2 responses
                10 views
                0 likes
                Last Post bltdavid  
                Started by alifarahani, Today, 09:40 AM
                6 responses
                41 views
                0 likes
                Last Post alifarahani  
                Working...
                X