Announcement

Collapse
No announcement yet.

How do I make the DiNapoli DeTrended Oscillator into a Multi-Colored Line?

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

  • How do I make the DiNapoli DeTrended Oscillator into a Multi-Colored Line?

    The Question
    How do I make the DiNapoli DeTrended Oscillator into a Multi-Colored Line?

    The Problem
    I've been trying for the past few days to try to turn the a regular DiNapoli Detrended Oscillator into a multi-colored "instant color line." I'm following Introductory Tutorial 3 as my guide (specifically pages 21-23 on creating an instant color line) and duplicate those settings on the DiNapoli. However, my attempts always result in a single color line.

    The Desired Result
    Before I go any further, check out the attachment below to get an idea of what I'm trying to create.

    Click image for larger version

Name:	denapoli two color line.jpg
Views:	1
Size:	37.1 KB
ID:	246994

    The "actual" is what I have right now which is a line with only a single color. However, what I would like to have (i.e. photoshopped) is a DiNapoli Detrended oscillator line that changes colors when it goes above or below the zero-line.

    The (partially working) Code
    Here's the best alteration that I could come up with (my additions in red).

    Code:
    function preMain()
    {
        setStudyTitle("DiNapoli Detrended Oscillator"); 
        setCursorLabelName("Detrend Osc",0);
        setDefaultBarFgColor(Color.RGB(0x75,0x71,0x99), 0);
      
        addBand(0, PS_DASH, 1,(Color.RGB(0x22,0x22,0x22)), "a");
        
    [COLOR="#B22222"]    setDefaultBarFgColor (Color.grey);
        setPlotType(PLOTTYPE_INSTANTCOLORLINE,0);[/COLOR]
        
    }
    function main(nLength) {
        if (nLength == null)    	
        nLength = 7;
        
    [COLOR="#B22222"]    if (nLength >= 50) setBarFgColor (Color.blue);
        if (nLength < 50) setBarFgColor (Color.red);[/COLOR]
        
        var vPrice = getValue("close",0,-nLength); 
        if(vPrice == null)    
        return;
        
        var Detrend = 0.0;
        var Sum = 0.0;
        var i = 0;
        
        //Average
        for (i = 0; i < nLength; i++)
                Sum += vPrice[i];
        Detrend = vPrice[0] - Sum / nLength;
        return Detrend;
    }
    What the previous code shows
    Click image for larger version

Name:	code red.jpg
Views:	1
Size:	23.1 KB
ID:	246995
    What results is the red part of the code but not the blue.

    Anyone have a good solution?
    Last edited by VideCorEsig; 04-02-2015, 06:23 PM.

  • #2
    VideCorEsig
    First of all you need to understand that nLength is a parameter and not the result that is being returned by the formula to the chart. This parameter is set to 7 by default in the following line of code
    nLength = 7;
    So when you write the following condition
    if (nLength >= 50) setBarFgColor (Color.blue);
    if (nLength < 50) setBarFgColor (Color.red);

    all you are in effect doing is saying “if the value of nLength is greater or equal to 50 then color the plot in blue and if the value of nLength is less than 50 color the plot in red”. Since 7 is less than 50 the plot will obviously be red.
    What is being returned to the chart is the variable Detrend so you need to base your condition on the value of that variable eg
    if (Detrend >= 0) setBarFgColor (Color.blue);
    if (Detrend < 0) setBarFgColor (Color.red);

    and you need to insert these two lines of code immediately after the line in which the variable Detrend is calculated ie
    Detrend = vPrice[0] - Sum / nLength;
    Once you do this the indicator will be colored in blue above the 0 line and in red below it
    Alex


    Originally posted by VideCorEsig View Post
    The Question
    How do I make the DiNapoli DeTrended Oscillator into a Multi-Colored Line?

    The Problem
    I've been trying for the past few days to try to turn the a regular DiNapoli Detrended Oscillator into a multi-colored "instant color line." I'm following Introductory Tutorial 3 as my guide (specifically pages 21-23 on creating an instant color line) and duplicate those settings on the DiNapoli. However, my attempts always result in a single color line.

    The Desired Result
    Before I go any further, check out the attachment below to get an idea of what I'm trying to create.

    [ATTACH]16752[/ATTACH]

    The "actual" is what I have right now which is a line with only a single color. However, what I would like to have (i.e. photoshopped) is a DiNapoli Detrended oscillator line that changes colors when it goes above or below the zero-line.

    The (partially working) Code
    Here's the best alteration that I could come up with (my additions in red).

    Code:
    function preMain()
    {
        setStudyTitle("DiNapoli Detrended Oscillator"); 
        setCursorLabelName("Detrend Osc",0);
        setDefaultBarFgColor(Color.RGB(0x75,0x71,0x99), 0);
      
        addBand(0, PS_DASH, 1,(Color.RGB(0x22,0x22,0x22)), "a");
        
    [COLOR="#B22222"]    setDefaultBarFgColor (Color.grey);
        setPlotType(PLOTTYPE_INSTANTCOLORLINE,0);[/COLOR]
        
    }
    function main(nLength) {
        if (nLength == null)    	
        nLength = 7;
        
    [COLOR="#B22222"]    if (nLength >= 50) setBarFgColor (Color.blue);
        if (nLength < 50) setBarFgColor (Color.red);[/COLOR]
        
        var vPrice = getValue("close",0,-nLength); 
        if(vPrice == null)    
        return;
        
        var Detrend = 0.0;
        var Sum = 0.0;
        var i = 0;
        
        //Average
        for (i = 0; i < nLength; i++)
                Sum += vPrice[i];
        Detrend = vPrice[0] - Sum / nLength;
        return Detrend;
    }
    What the previous code shows
    [ATTACH]16753[/ATTACH]
    What results is the red part of the code but not the blue.

    Anyone have a good solution?

    Comment


    • #3
      OMG thank you thank thank thank you!!!! So (and correct me if I'm wrong), all I was doing was attempting to alter a part (nLength) rather than the overall product (Detrend). And in order for the alteration to be effective, I needed to insert the coloring instructions immediately following the targeted product. Also, the 50 was way off lol.

      Trying to understand the basic concept some more, would the same alterations translate to a GET Oscillator or are they completely different animals?

      When I look at the GET Oscillator I don't see anything that resembles Detrend = vPrice[0] - Sum / nLength;. What made the most sense to me would be the interval (which after trying all the others seemed like the best choice but does not work). My attempt looks like this:

      Code:
      [COLOR="#006400"]NOTE: Omitted Lines 1-76 to save space[/COLOR]
      
      function main(Length1,Length2,Strength,Symbol,Interval,Params){
      
          if(bInit == false){
              if(Symbol == null) Symbol = getSymbol();     
              if(Interval == null) Interval = getInterval();
              
      [COLOR="#B22222"]            if (Interval >= 0) setBarFgColor (Color.blue);
                  if (Interval < 0) setBarFgColor (Color.red);[/COLOR]
              
              var vSymbol = Symbol+","+Interval;
              
              x_osc = getSeries(AGet.osc(Length1,Length2,Strength,OSC_OSC,sym(vSymbol)));
              x_oscBandUp = getSeries(AGet.osc(Length1,Length2,Strength,OSC_BANDUP,sym(vSymbol)));
              x_oscBandDown = getSeries(AGet.osc(Length1,Length2,Strength,OSC_BANDDOWN,sym(vSymbol)));
              
              setShowTitleParameters(Params);
              bInit = true;
              
          };
          
          return new Array (x_osc,x_oscBandUp,x_oscBandDown);
      }
      Would I need to add in something in like Detrend = vPrice[0] - Sum / nLength; to gain the same functionality as the colored dinapoli?

      Comment


      • #4
        VideCorEsig

        So (and correct me if I'm wrong), all I was doing was attempting to alter a part (nLength) rather than the overall product (Detrend).
        Just to be clear, in writing that conditional statement (ie IF this THEN do this IF that THEN do that) you are not “altering” anything. You are just checking if the result of a given calculation fits certain conditions in which case you do something (apply a color, trigger an alert, what have you)
        In your case you were applying a conditional statement to the parameter of the study (ie nLength which is the number of bars that the study uses for its calculations).

        And in order for the alteration to be effective, I needed to insert the coloring instructions immediately following the targeted product.
        That is generally true – in particular for basic code - but you will very (and I mean very) quickly find out that there are all sorts of diverse ways in which a formula can be written.

        When I look at the GET Oscillator I don't see anything that resembles *Detrend = vPrice[0] - Sum / nLength;*.
        That is because in the DiNapoli formula that value was being calculated by that equation whereas in the GET Oscillator formula that value is being calculated by a built-in function. As I said you will quickly find out that there are many ways to do things in EFS (as well as in any programming language)

        What made the most sense to me would be the interval (which after trying all the others seemed like the best choice but does not work).
        What you did in this case is exactly the same error you did in the DiNapoli formula ie you created a conditional statement on a parameter and not on the value that is being returned to the chart which is calculated by the AGet.osc() built-in function.
        Here is how you would need to modify the formula in its most basic form to accomplish the same result as with the DiNapoli study



        Please note that it is not my intention to modify every single formula you may have or want and given that you seem to be quite unfamiliar with programming in EFS I would suggest that you take some time to learn a bit more about it.
        To this effect I would suggest that you review the JavaScript for EFS videos and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS. Also serach the forums as they are an invaluable resource in as much as many of the things you are trying to do have been discussed before (and in many cases at length)
        Alex


        Originally posted by VideCorEsig View Post
        OMG thank you thank thank thank you!!!! So (and correct me if I'm wrong), all I was doing was attempting to alter a part (nLength) rather than the overall product (Detrend). And in order for the alteration to be effective, I needed to insert the coloring instructions immediately following the targeted product. Also, the 50 was way off lol.

        Trying to understand the basic concept some more, would the same alterations translate to a GET Oscillator or are they completely different animals?

        When I look at the GET Oscillator I don't see anything that resembles Detrend = vPrice[0] - Sum / nLength;. What made the most sense to me would be the interval (which after trying all the others seemed like the best choice but does not work). My attempt looks like this:

        Code:
        [COLOR="#006400"]NOTE: Omitted Lines 1-76 to save space[/COLOR]
        
        function main(Length1,Length2,Strength,Symbol,Interval,Params){
        
            if(bInit == false){
                if(Symbol == null) Symbol = getSymbol();     
                if(Interval == null) Interval = getInterval();
                
        [COLOR="#B22222"]            if (Interval >= 0) setBarFgColor (Color.blue);
                    if (Interval < 0) setBarFgColor (Color.red);[/COLOR]
                
                var vSymbol = Symbol+","+Interval;
                
                x_osc = getSeries(AGet.osc(Length1,Length2,Strength,OSC_OSC,sym(vSymbol)));
                x_oscBandUp = getSeries(AGet.osc(Length1,Length2,Strength,OSC_BANDUP,sym(vSymbol)));
                x_oscBandDown = getSeries(AGet.osc(Length1,Length2,Strength,OSC_BANDDOWN,sym(vSymbol)));
                
                setShowTitleParameters(Params);
                bInit = true;
                
            };
            
            return new Array (x_osc,x_oscBandUp,x_oscBandDown);
        }
        Would I need to add in something in like Detrend = vPrice[0] - Sum / nLength; to gain the same functionality as the colored dinapoli?

        Comment


        • #5
          @ACM

          Originally posted by ACM View Post
          That is because in the DiNapoli formula that value was being calculated by that equation whereas in the GET Oscillator formula that value is being calculated by a built-in function. As I said you will quickly find out that there are many ways to do things in EFS (as well as in any programming language)
          So I suppose the reason why, for example, the GET oscillator efs and the basic oscillator look so different is because the program (right word??? script?) is not necessarily in the script but accessed separately? Neat. I had though that it would have all been all self contained on one efs script. Lol I had originally thought that the basic oscillator was unalterable just because it didn't have as much detail as the GET Oscillator.

          Originally posted by ACM View Post
          What you did in this case is exactly the same error you did in the DiNapoli formula ie you created a conditional statement on a parameter and not on the value that is being returned to the chart which is calculated by the AGet.osc() built-in function.
          I think that one of the major setbacks I had learning about how the DiNapoli and GET oscillator coloring work may have been as simple as thinking that they were both oscillators (and therefore the same) and not knowing that there was more beyond the superficial efs I saw in each indicator. Not only that, but getting to identify whats what so I avoid the aforementioned issue.

          Originally posted by ACM View Post
          Please note that it is not my intention to modify every single formula you may have and given that you seem to be quite unfamiliar with programming in EFS I would suggest that you take some time to learn a bit more about it.
          To this effect I would suggest that you review the JavaScript for EFS videos and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS. Also serach the forums as they are an invaluable resource in as much as many of the things you are trying to do have been discussed before (and in many cases at length)
          Oh yeah no worries. I've just been getting into this over the last few days and there's certainly a lot more to learn, so definitely not my intent to get freebies. And actually, thanks for the links. I thought that the limit of the resources for this was limited to the Knowledgebase content and the pdf I found was the best explanation, but the videos look really informative. Ima spend the weekend getting down the basic concepts. Again, thanks for the help and the clarifications!
          Last edited by VideCorEsig; 04-03-2015, 05:40 PM.

          Comment


          • #6
            VideCorEsig

            So I suppose the reason why, for example, the GET oscillator efs and the basic oscillator look so different is because the program (right word??? script?) is not necessarily in the script but accessed separately? Neat. I had though that it would have all been all self contained on one efs script. Lol I had originally thought that the basic oscillator was unalterable just because it didn't have as much detail as the GET Oscillator.
            If by “basic oscillator” you mean the DiNapoli oscillator you posted earlier the difference is due to the fact that one [the GET oscillator] is calculated using a built-in function (which performs all the necessary computations on its own and returns a result) whereas the other has no built-in function so all the calculations have to be performed in the formula itself. No different than what you would need to do in an Excel sheet if you did not have a specific function ie you would have to write all the necessary equations yourself. For example if the AVERAGE() function did not exist in Excel and you wanted to do an average of the cells A1, B1 and C1 you would calculate it by writing =(A1+B1+C1)/3
            Alex


            Originally posted by VideCorEsig View Post
            @ACM



            So I suppose the reason why, for example, the GET oscillator efs and the basic oscillator look so different is because the program (right word??? script?) is not necessarily in the script but accessed separately? Neat. I had though that it would have all been all self contained on one efs script. Lol I had originally thought that the basic oscillator was unalterable just because it didn't have as much detail as the GET Oscillator.



            I think that one of the major setbacks I had learning about how the DiNapoli and GET oscillator coloring work may have been as simple as thinking that they were both oscillators (and therefore the same) and not knowing that there was more beyond the superficial efs I saw in each indicator. Not only that, but getting to identify whats what so I avoid the aforementioned issue.



            Oh yeah no worries. I've just been getting into this over the last few days and there's certainly a lot more to learn, so definitely not my intent to get freebies. And actually, thanks for the links. I thought that the limit of the resources for this was limited to the Knowledgebase content and the pdf I found was the best explanation, but the videos look really informative. Ima spend the weekend getting down the basic concepts. Again, thanks for the help and the clarifications!

            Comment

            Working...
            X