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

Help modifying this code

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

    Help modifying this code

    I am a complete programming novice, so here is this piece of code that i got from somewhere else and i am trying to make a slight modification to it. What this code entails is essentially when a certain EXACT retracement percentage exists (in this case 38.2, 50, 61.8, 70.7, 78.6, and 88.6%), it triggers a condition called ab_retr_0382, ab_retr_0500, etc. I instead want the condition to be triggered when the retracement is within the RANGE of those ratios. So what i want to do this this:

    if the retracement is between 0.382 to 0.499, then the condition is ab_ret_0382.

    if the retracement is between 0.500 to 0.617, then the condition is ab_ret_0500.

    if the retracement is between 0.618 to 0.706, then the condition is ab_ret_0618.

    if the retracement is between 0.707 to 0.785, then the condition is ab_ret_0707.

    if the retracement is between 0.786 to 0.885, then the condition is ab_ret_0786.

    if the retracement is 0.886, then the condition is ab_ret_0886. (already set this way)



    How would i change the code below to make this happen? i'm sure its just some slight change in the syntax, but i'm not sure. I was thinking it would be something like " ab_retr_0382 = isRetracement(dist,retr,BETWEEN 0.382 AND 0.499);", but i don't know what command that "between" property would be or proper syntax.

    dist = aVal-bVal;
    retr = cVal-bVal;

    if(!isMinRetracement(dist,retr,0.382))
    {
    continue;
    }

    if(!isMaxRetracement(dist,retr,0.886))
    {
    break;
    }

    ab_retr_0382 = isRetracement(dist,retr,0.382);
    ab_retr_0500 = isRetracement(dist,retr,0.500);
    ab_retr_0618 = isRetracement(dist,retr,0.618);
    ab_retr_0707 = isRetracement(dist,retr,0.707);
    ab_retr_0786 = isRetracement(dist,retr,0.786);
    ab_retr_0886 = isRetracement(dist,retr,0.886);


    Thanks

    #2
    Hello sra18376,

    Thank you for your post.

    You would want to check if the Retracement is greater than or equal to .382 AND Retracement is less than or equal to .499
    Code:
    if(Retracment >= 0382 && Retracement <= .499)
    {
        //do something here
    }
    This will allow you to check if the value of the Retracement is within the bounds that you are setting in the IF Statement.

    Let me know if I can be of further assistance.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Would this modification achieve my goal then?

      if ((retr/dist) >=0.382 && (retr/dist) <=0.499){
      ab_retr_0382;
      } else if ((retr/dist) >=0.5 && (retr/dist) <=0.617){
      ab_retr_0500;
      } else if ((retr/dist) >=0.618 && (retr/dist) <=0.706){
      ab_retr_0618;
      } else if ((retr/dist) >=0.707 && (retr/dist) <=0.785){
      ab_retr_0707;
      } else if ((retr/dist) >=0.786 && (retr/dist) <=0.885){
      ab_retr_0786;
      } else if ((retr/dist) =.886){
      ab_retr_0886;
      }

      EDIT: fixed
      Last edited by sra18376; 06-18-2014, 09:58 AM.

      Comment


        #4
        sra18376,

        Looks good.
        Cal H.NinjaTrader Customer Service

        Comment


          #5
          I tried the code and I got the following error messages and where they were referenced from:

          Error codes CS0201 on each "ab_retr_",

          CS0131 on last "retr" in "(retr/dist)",

          CS0029 in same spot, but in the perinthesis.

          I highlighted the locations in red.


          Code:
          if ((retr/dist) >=0.382 && (retr/dist) <=0.499){
          [COLOR="Red"]ab_retr_0382[/COLOR];
          } else if ((retr/dist) >=0.5 && (retr/dist) <=0.617){
          [COLOR="red"]ab_retr_0500[/COLOR];
          } else if ((retr/dist) >=0.618 && (retr/dist) <=0.706){
          [COLOR="red"]ab_retr_0618[/COLOR];
          } else if ((retr/dist) >=0.707 && (retr/dist) <=0.785){
          [COLOR="red"]ab_retr_0707[/COLOR];
          } else if ((retr/dist) >=0.786 && (retr/dist) <=0.885){
          [COLOR="red"]ab_retr_0786[/COLOR];
          } else if ([COLOR="red"]([/COLOR][COLOR="red"]retr[/COLOR]/dist) =.886){
          [COLOR="red"]ab_retr_0886[/COLOR];
          }

          what can i do to fix these messages?

          Comment


            #6
            sra18376,

            You would want to assign a value to the ab_retr.

            Such as, if the condition is true then -
            ab_retr_0382 = true;


            This means that ab_retr_0382 needs to be declared as a bool in the script, in the variable section.
            Cal H.NinjaTrader Customer Service

            Comment


              #7
              Thank you. Any ideas on the other error codes? or will declaring a bool fix all 3 of them?

              Comment


                #8
                You will need to have a bool for all 6 of them.
                Cal H.NinjaTrader Customer Service

                Comment


                  #9
                  I meant all 3 error codes

                  Comment


                    #10
                    That should clear them up but if it doesn't get a screenshot and attach it so I can see them.

                    To send a screenshot press Alt + PRINT SCREEN to take a screen shot of the selected window. Then go to Start--> Accessories--> Paint, and press CTRL + V to paste the image. Lastly, save as a jpeg file

                    For detailed instructions please visit the following link
                    http://take-a-screenshot.org/

                    To attach a picture -
                    Click Reply -> Go Advanced -> Click the PaperClip icon in the toolbar
                    Cal H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Mizzouman1, Today, 07:35 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post Mizzouman1  
                    Started by i019945nj, 12-14-2023, 06:41 AM
                    6 responses
                    66 views
                    0 likes
                    Last Post i019945nj  
                    Started by aa731, Today, 02:54 AM
                    1 response
                    8 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by BarzTrading, Today, 07:25 AM
                    0 responses
                    3 views
                    0 likes
                    Last Post BarzTrading  
                    Started by ruudawakening, Today, 12:58 AM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Jesse  
                    Working...
                    X