• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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){
          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;
          }

          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 Vincere, Today, 04:38 AM
                    0 responses
                    2 views
                    0 likes
                    Last Post Vincere
                    by Vincere
                     
                    Started by trader_rick, Today, 04:02 AM
                    1 response
                    3 views
                    0 likes
                    Last Post NinjaTrader_ChrisSch  
                    Started by percma, Today, 02:51 AM
                    0 responses
                    5 views
                    0 likes
                    Last Post percma
                    by percma
                     
                    Started by Abilene, Today, 01:27 AM
                    0 responses
                    15 views
                    0 likes
                    Last Post Abilene
                    by Abilene
                     
                    Started by simjs, Yesterday, 08:11 PM
                    1 response
                    5 views
                    0 likes
                    Last Post NinjaTrader_ChrisSch  
                    Working...
                    X