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

For Loop issue

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

    For Loop issue

    Ok I know this will be difficult to answer because I can't give all of my code. I have several methods and dataseries that are tied to this block of code. I could reprint it all but it would probably be a lot to sift through so I thought I'd share the issue and ask a general question first.
    Here is the offending block of code:
    Code:
    public void Leg3_Find_Leg3_Top(bool leg3_Bottom_Found, int leg3_Top_BarNumber, IDataSeries price_Peak, double leg4_High_Value)
                {
                    if(leg3_Bottom_Found){
                        for(int x = leg3_Top_BarNumber; x < 10 + leg3_Top_BarNumber; x++){
                            if(price_Peak[x] != 0 &&
                                price_Peak[x] > leg4_High_Value){
                                Leg3_Top_Found            = true;
                                Leg3_Top_BarNumber        = x;
                                Leg3_Top_HighValue        = price_Peak[x];
    
                            }
                        }
                    }
                }
    leg3_Bottom_Found = Showing that the last wave was found.
    leg3_Top_BarNumber = Bar number the previous high was found on. Starting point for new loop.
    price_Peak = My method that finds "Price Peaks". Returns 0 if bar is not a peak.
    leg4_High_Value = High of wave 4.

    Essentially I'm trying map the 5 wave moves of the Elliot Wave pattern. I'm working backwards using loops to map each wave/leg. Finding waves 5 and 4 are simple. When I try to get the top of wave 3 for some reason the loop is missing what should have been the beginning of 3 and going to the beginning of 1. It's doing this consistently across the chart. I made an image of what I want it to do and what it is actually doing. Blue line is what I want. Red line is what it is doing.

    Any help would be appreciated.

    Click image for larger version

Name:	WrongBar_LI (2).jpg
Views:	544
Size:	97.3 KB
ID:	1057711
    Attached Files

    #2
    Originally posted by CaptainAmericaXX View Post
    Ok I know this will be difficult to answer because I can't give all of my code. I have several methods and dataseries that are tied to this block of code. I could reprint it all but it would probably be a lot to sift through so I thought I'd share the issue and ask a general question first.
    Here is the offending block of code:
    Code:
    public void Leg3_Find_Leg3_Top(bool leg3_Bottom_Found, int leg3_Top_BarNumber, IDataSeries price_Peak, double leg4_High_Value)
    {
    if(leg3_Bottom_Found){
    for(int x = leg3_Top_BarNumber; x < 10 + leg3_Top_BarNumber; x++){
    if(price_Peak[x] != 0 &&
    price_Peak[x] > leg4_High_Value){
    Leg3_Top_Found = true;
    Leg3_Top_BarNumber = x;
    Leg3_Top_HighValue = price_Peak[x];
    
    }
    }
    }
    }
    leg3_Bottom_Found = Showing that the last wave was found.
    leg3_Top_BarNumber = Bar number the previous high was found on. Starting point for new loop.
    price_Peak = My method that finds "Price Peaks". Returns 0 if bar is not a peak.
    leg4_High_Value = High of wave 4.

    Essentially I'm trying map the 5 wave moves of the Elliot Wave pattern. I'm working backwards using loops to map each wave/leg. Finding waves 5 and 4 are simple. When I try to get the top of wave 3 for some reason the loop is missing what should have been the beginning of 3 and going to the beginning of 1. It's doing this consistently across the chart. I made an image of what I want it to do and what it is actually doing. Blue line is what I want. Red line is what it is doing.

    Any help would be appreciated.

    Click image for larger version

Name:	WrongBar_LI (2).jpg
Views:	544
Size:	97.3 KB
ID:	1057711
    You are examining the last 10 bars before the leg4_High_Value, and isolating the highest high, it would seem. Your picture seems to confirm that. If you want an intervening condition to stop the loop, you will need to break out when that condition happens. What condition are you seeing that leads you to your expectation? Code it in and break out of the loop.

    Comment


      #3
      Hi CaptainAmericaXX, thanks for your post.

      I would recommend an analysis of the code through Visual Studio. In Visual Studio you can set break points in your code and step through each line, helping to see what values are being used in the loop.

      Instructions Visual Studio debugging are below:


      Please let me know if I can assist further.
      Chris L.NinjaTrader Customer Service

      Comment


        #4
        Yes, about analysing this through VS. I sent a post earlier about not being able to access VS. I followed all the steps and have the indicator attached but I'm getting an error. "The breakpoint will not currently be hit. No symbols have been loaded for this document." I've looked online but can't find any examples that show me how to resolve this. Can you help me set it up?
        Later:
        I realized that I hadn't followed all the steps. I didn't compile my script after selecting debug. I'm having another issue though. I'll open a new post to discuss it.
        Last edited by CaptainAmericaXX; 05-17-2019, 08:51 AM.

        Comment


          #5
          Thank you koganam! I can't believe I left the break out. I looked over this for an hour. Someday this coding stuff will click.

          Comment


            #6
            Hi CaptainAmericaXX, thanks for your reply.

            I just replied to you on your other post, I'll just copy the same thing here.


            Please make sure you click the visual studio icon at the top of the NinjaScript editor to launch the custom NT project. This will load up the debug symbols for NinjaTrader. Please also make sure to right click the code> Enable debug mode, and compile your script within the editor after enabling debug mode.
            Chris L.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by CaptainAmericaXX View Post
              Thank you koganam! I can't believe I left the break out. I looked over this for an hour. Someday this coding stuff will click.
              Don't mention it.

              That is why I tell everyone who will listen, that, especially if the code involves loops, write down the technical spec, or at least the entire flow logic, and only after that, translate it to code. Heck, even then, I still get it wrong often, but at least then it is just me coding like a pendejo, not the logic.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by bmartz, Today, 09:30 AM
              2 responses
              11 views
              0 likes
              Last Post bltdavid  
              Started by f.saeidi, Today, 11:02 AM
              1 response
              2 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by geotrades1, Today, 10:02 AM
              4 responses
              12 views
              0 likes
              Last Post geotrades1  
              Started by rajendrasubedi2023, Today, 09:50 AM
              3 responses
              16 views
              0 likes
              Last Post NinjaTrader_BrandonH  
              Started by lorem, Today, 09:18 AM
              2 responses
              11 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Working...
              X