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 barsago value printing 0

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

    MRO barsago value printing 0

    Simple condition and I want to print the time and bars ago from current. However, I'm not sure what I am missing here as the time prints correctly at the bar when the condition meets but the barsAgoLong always prints 0. Probably an array error but any ideas?

    Code:
     
     
    
    int barsAgoLONG = MRO(() => ShortPercent >= 0.90 , 1, 20);
    
    if (barsAgoLONG > -1)
    {
    
    Print(" " + Time[barsAgoLONG] + " " + barsAgoLONG); 
    
    Draw.Dot(this, @"InitateCustomCode " + CurrentBars[0].ToString(), true, 0, GetCurrentAsk(0), Brushes.Pink);
    
    
    
    }

    #2
    Hello Boonfly8,

    Thank you for your note.

    Could it be that (ShortPercent >= 0.90) is always true? Thus the most recent occurrence is always going to be bar index zero, or the current bar?

    If you add,
    Code:
    Print("ShortPercent_"+ShortPercent.ToString());
    int barsAgoLONG = MRO(() => ShortPercent >= 0.90 , 1, 20);
    And check the output window, is ShortPercent Always >=.9?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Hi Alan P,

      it is definitely not always true as the output does print out the time when it happens, and it doesn't happen all the time. However, the barsago value is 0. Here's an example of the output

      7/20/2018 7:51:00 AM 0
      7/20/2018 7:52:00 AM 0
      7/20/2018 7:53:00 AM 0
      7/20/2018 7:55:00 AM 0
      7/20/2018 7:56:00 AM 0
      7/20/2018 9:20:00 AM 0
      7/20/2018 9:52:00 AM 0
      7/20/2018 9:53:00 AM 0
      7/20/2018 9:55:00 AM 0
      7/20/2018 10:08:00 AM 0
      7/20/2018 10:49:00 AM 0
      7/20/2018 10:54:00 AM 0
      7/20/2018 10:56:00 AM 0
      7/20/2018 10:57:00 AM 0
      7/20/2018 10:59:00 AM 0
      7/20/2018 11:01:00 AM 0
      7/20/2018 11:07:00 AM 0
      7/20/2018 11:08:00 AM 0
      7/20/2018 11:12:00 AM 0
      7/20/2018 11:13:00 AM 0
      7/20/2018 11:14:00 AM 0

      Comment


        #4
        Hello,

        Without the script I would be unable to know. I suggest the following links on debugging.

        I’ve provided a link to a youtube video which covers an example of using prints to understand behavior:
        Dive into manipulating C# code from within an unlocked NinjaScript strategy using the NinjaScript Editor.NinjaTrader 7 is an award winning end to end online ...


        I’ve provided a link covering debugging which you may find helpful.
        Debugging: http://ninjatrader.com/support/forum...ead.php?t=3418

        If you try the above and still unable to figure out the issue, please leave the print statements in the script and you can upload a copy and I'll take a look and see if anything jumps out.

        To export a NinjaScript from NinjaTrader 8 do the following:
        From the Control Center window select Tools -> Export -> NinjaScript...
        Click Add>Select the indicator>OK>Export.
        Then attach that file you saved; under My Docs>NT8>Bin>Custom>Select the downloaded .zip file.

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hey Alan, the code is simple so I'll leave it here. I tried to see the outputs but there's something that's going on that I'm not seeing. Instead of using ShortPercent, I made the condition simpler, but still the same result...seeing 0.


          Code:
            else if (State == State.DataLoaded)
             {    
              BollInitiate = Bollinger(Close, 2, 20);
              
              BollInitiate.Plots[0].Brush = Brushes.DeepSkyBlue;
              BollInitiate.Plots[1].Brush = Brushes.Goldenrod;
              BollInitiate.Plots[2].Brush = Brushes.DeepSkyBlue;
              AddChartIndicator(BollInitiate);
              
              
             }
          Code:
          protected override void OnBarUpdate()
            { 
            
          
              Print("ShortPercent_"+ShortPercent.ToString()); //Alan's Print Statement 
              int barsAgoLONG = MRO(() => GetCurrentBid() <= BollInitiate.Lower[0] , 1, 5);
             
                 if (barsAgoLONG > -1)
              {
               
               Print(" " + Time[barsAgoLONG] + " " + barsAgoLONG);     
           
               Draw.Dot(this, @"InitateCustomCode " + CurrentBars[0].ToString(), true, 0, GetCurrentAsk(0), Brushes.Pink);
               
               
               
              }
           
          
               
               
           
            }

          Comment


            #6
            Hello Boonfly8,

            When I apply the code I am unable to replicate and it works as expected. See screen shot.

            If you test the attached script do you see the correct prints?

            If not, who is your data provider? What instrument and time frame are you applying this to?

            I look forward to your reply.
            Attached Files
            Alan P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by josh18955, 03-25-2023, 11:16 AM
            6 responses
            435 views
            0 likes
            Last Post Delerium  
            Started by FAQtrader, Today, 03:35 PM
            0 responses
            3 views
            0 likes
            Last Post FAQtrader  
            Started by rocketman7, Today, 09:41 AM
            5 responses
            18 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by frslvr, 04-11-2024, 07:26 AM
            9 responses
            127 views
            1 like
            Last Post caryc123  
            Started by selu72, Today, 02:01 PM
            1 response
            14 views
            0 likes
            Last Post NinjaTrader_Zachary  
            Working...
            X