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

cant Print() without sacrifice

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

    cant Print() without sacrifice

    Hello,

    for (int barIndex = ChartBars.FromIndex; barIndex <= ChartBars.ToIndex; barIndex++)
    {
    if (Bars.GetHigh(barIndex) > highPrice)
    {
    highPrice = Bars.GetHigh(barIndex);
    index = barIndex;


    }
    }

    for (int barIndex = index; barIndex <= index0; barIndex++)
    {
    if (Bars.GetLow(barIndex) < lowPrice)
    {
    lowPrice = Bars.GetLow(barIndex);
    index2 = barIndex;

    Print("index2" + index2);
    }
    }



    The Print() wont show up in OW. Meaning i can get my variable index2 to work in my code.
    I tried every thing and i am out of idea.
    It seems very difficult to get in the same code a low and a high bar. If i remove brackets i lose one or the other. i need both index in an independent way.

    Any suggestions.

    thank you

    #2
    Hello frankduc,

    Thank you for your post.

    To clarify, you're trying to identify first the highest high currently on the chart, then find the index of the bar with the lowest low after that, is that correct? What is index0 defined as?

    Thanks in advance; I look forward to resolving this for you.
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      The first loop give me the highest bar in the chart. No problem here.

      The second loop is suppose to give me the lowest bar between index and index0. index is the highest bar in the chart. index0 is a bar somewhere before the index (highest bar). index0 come from another for loop.

      I need the lowest bar between index and index0 but if i print() nothing show in the OW.

      I tried with local variables :

      for (int barIndex = index; barIndex <= index0; barIndex++)

      {
      double lowPrice = Int32.MaxValue;
      if (Bars.GetLow(barIndex) < lowPrice)
      {
      int index2;

      lowPrice = Bars.GetLow(barIndex);
      index2 = barIndex;

      Print("index2" + index2);
      }
      }


      But it wont work either. Every time i try to find more than one highest or lowest point with more that one for loop there's always one that wont work. I need index2 but how to make it work puzzle me.

      As you can see in the chart the vertical red line give is index0 but horizontal line end up at wrong place because i need the lowest value between highest point 2946.5 (index) and index0, lowest point between the two would be 2851.5.

      Its like the first for loop (index) is preventing the second for loop to execute and block the answer of index2.

      Any solutions for me?

      Thanks

      Attached Files

      Comment


        #4
        Hello frankduc,

        Thank you for your reply.

        I think you're running into issues with the logic of the second loop. From the screenshot you've attached, index0 would be a smaller number than index when the platform would try to execute that code. You have this:

        for (int barIndex2 = index; barIndex2 <= index0; barIndex2++)

        But, since your high bar index was a higher number than index0 to begin with, this never executes. You want to reverse this if you're looking for a bar between index0 and index. I also set the low price to be the low of the bar at index, so you have something to compare the low for each bar to:

        lowPrice = Bars.GetLow(index);
        for (int barIndex2 = index0; barIndex2 <= index; barIndex2++)
        {
        //second loop contents
        }

        Please let us know if we may be of further assistance to you.
        Kate W.NinjaTrader Customer Service

        Comment


          #5
          It seems that it only counts from index0 all the bars to index without ever finding the lowest value. The OW show index2 0, index2 1, index2 2,-----> index2 88 (index)

          I am starting to believe the issue comes from the fact that one of my loop in my logic is searching for more that one answer. The vertical line index0 is moving and jumping to every bar that meat the condition. When it reach the last possibility it return all the bars without returning the lowest value when it should be returning the lowest value close to index0 for each bar that meat the condition.

          Logically every time the loop find a bar that meat the condition it should automatically return the lowest value close to index0.

          I dont know what to do anymore.

          Comment


            #6
            Hello frankduc,

            Thank you for your reply.

            I would need to look at the full code to give you much more of an answer. However, this would be a great script to add more prints to so you can print the values of your indexes and even what the lowPrice and highPrice would be for each iteration of the loops and see if the results make sense based on what you're trying to do.

            If you export and attach what you've got for your indicator, I'd be happy to take a look at the full code.

            Thanks in advance; I look forward to being of further assistance to you.
            Kate W.NinjaTrader Customer Service

            Comment


              #7
              I already check every one of my variables and indexes, and everything works fine.

              Where do i send that [email protected] at your attention?

              Comment


                #8
                Hello frankduc,

                Thank you for your reply.

                Yes, please send an email to platformsupport [at] ninjatrader [dot] com. Please include ATTN Kate W. in the subject line and a link to this thread in the body of the email. Attach your script to this email and I'll be happy to take a look.

                Thanks in advance; I look forward to assisting you further.
                Kate W.NinjaTrader Customer Service

                Comment


                  #9
                  Like you can see on the chart i want to cumulate all volume from index (top of the trend) to the vertical red line. So first bar 100 + second bar 156 + third bar 320 etc, going backward.

                  If i for loop this way, am i doing it right or is it FromIndex?

                  for (int barIndexx = index; barIndexx <= ChartBars.ToIndex; barIndexx--)
                  {
                  sumOfVolumes10 += Bars.GetVolume(barIndex);


                  Thanks

                  Comment


                    #10
                    Hello frankduc,

                    Thank you for your reply.

                    The way you have this loop structured means that if it ran once, it would run indefinitely, because it only runs if barindexx is less than or equal to ChartBars.ToIndex the first run, and then after every loop you're decrementing the barindexx. So no matter what, if it was true once, it'll continue to be true, and you're stuck with an infinite loop. However, since ChartBars.ToIndex would give you the bar index of the last bar on the chart (the leftmost bar). This index will by its nature be less than barindexx and that loop would never run.

                    ​​​​​​​Which indexes specifically hold the bar indexes you want to loop between?

                    Thanks in advance; I look forward to assisting you further.
                    Kate W.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Haiasi, Today, 06:53 PM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by ScottWalsh, Today, 06:52 PM
                    1 response
                    6 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by ScottW, Today, 06:09 PM
                    1 response
                    4 views
                    0 likes
                    Last Post NinjaTrader_Manfred  
                    Started by ftsc2022, 10-25-2022, 12:03 PM
                    5 responses
                    256 views
                    0 likes
                    Last Post KeyonMatthews  
                    Started by Board game geek, 10-29-2023, 12:00 PM
                    14 responses
                    244 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Working...
                    X