Announcement

Collapse
No announcement yet.

Price Osc color change

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

  • Price Osc color change

    Hello,

    I would like the following price hist to be green when moving up and red when moving down.

    Currently i get color change when it goes above and below the zero line.

    Can anyone help with the added script lines?

    Thanks,


    var vOsc = null;

    function preMain() {
    setStudyTitle("Price Oscillator");
    setCursorLabelName("Osc");
    setDefaultBarFgColor(Color.blue);
    setDefaultBarThickness(4);
    setPlotType(PLOTTYPE_HISTOGRAM);
    addBand(0, PS_SOLID, 1, Color.lightgrey);
    checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicOsc.efs");

    var fp1 = new FunctionParameter("Short", FunctionParameter.NUMBER);
    fp1.setLowerLimit(1);
    fp1.setDefault(8);

    var fp2 = new FunctionParameter("Long", FunctionParameter.NUMBER);
    fp2.setLowerLimit(1);
    fp2.setDefault(20);

    var fp3 = new FunctionParameter("Source", FunctionParameter.STRING);
    fp3.setName("MA1Source");
    fp3.addOption("Close");
    fp3.addOption("High");
    fp3.addOption("Low");
    fp3.addOption("Open");
    fp3.addOption("HL/2");
    fp3.addOption("HLC/3");
    fp3.addOption("OHLC/4");
    fp3.setDefault("Close");

    var fp4 = new FunctionParameter("Type", FunctionParameter.BOOLEAN);
    fp4.setName("Exponential");
    fp4.setDefault(true); //Edit this value to set a new default

    }

    function main(Short, Long, Source, Type) {

    if (vOsc == null) vOsc = new OscStudy(Short, Long, Source, Type);

    /********************************************
    Insert your code following this text block
    Use vOsc.getValue(OscStudy.OSC) for your code
    *********************************************/

    if (vOsc.getValue(OscStudy.OSC)>0)
    setBarFgColor(Color.green);

    if(vOsc.getValue(OscStudy.OSC)<0)
    setBarFgColor(Color.red);



    return vOsc.getValue(OscStudy.OSC);

    }

  • #2
    Re: Reply to post 'Price Osc color change'

    2 changes highlighted below should help.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    >

    Comment


    • #3
      hmm, i think ur reply didnt post correctly.

      Please can u repost the highlighted changes.

      Thanks

      Comment


      • #4
        abbers
        The enclosed revision should do what you want
        Alex

        PHP Code:
        var vOsc null;

        function 
        preMain() {
            
        setStudyTitle("Price Oscillator");
            
        setCursorLabelName("Osc");
            
        setDefaultBarFgColor(Color.blue);
            
        setDefaultBarThickness(4);
            
        setPlotType(PLOTTYPE_HISTOGRAM);
            
        addBand(0PS_SOLID1Color.lightgrey);
            
            
            var 
        fp1 = new FunctionParameter("Short"FunctionParameter.NUMBER);
            
        fp1.setLowerLimit(1); 
            
        fp1.setDefault(8);

            var 
        fp2 = new FunctionParameter("Long"FunctionParameter.NUMBER);
            
        fp2.setLowerLimit(1); 
            
        fp2.setDefault(20);

        var 
        fp3 = new FunctionParameter("Source"FunctionParameter.STRING);
            
        fp3.setName("MA1Source");
            
        fp3.addOption("Close");
            
        fp3.addOption("High");
            
        fp3.addOption("Low");
            
        fp3.addOption("Open");
            
        fp3.addOption("HL/2");
            
        fp3.addOption("HLC/3");
            
        fp3.addOption("OHLC/4");
            
        fp3.setDefault("Close"); 

            var 
        fp4 = new FunctionParameter("Type"FunctionParameter.BOOLEAN);
            
        fp4.setName("Exponential");
            
        fp4.setDefault(true); //Edit this value to set a new default 

        }

        function 
        main(ShortLongSourceType) {

            if (
        vOsc == nullvOsc = new OscStudy(ShortLongSourceType);
                    
        /********************************************
        Insert your code following this text block   
        Use vOsc.getValue(OscStudy.OSC) for your code
        *********************************************/

            
        if (vOsc.getValue(OscStudy.OSC)>vOsc.getValue(OscStudy.OSC,-1))
            
        setBarFgColor(Color.green);

            if(
        vOsc.getValue(OscStudy.OSC)<vOsc.getValue(OscStudy.OSC,-1))
            
        setBarFgColor(Color.red);



            return 
        vOsc.getValue(OscStudy.OSC);
            

        Comment


        • #5
          Thanks again Alexis.

          Comment


          • #6
            Price osc with color change

            Can this file be downloaded?

            I can't copy / paste and create new file.

            Thanks for your help,

            bandraguy

            Comment


            • #7
              bandraguy
              The script is essentially the same as the builtinOsc.efs that you should have in your computer in the Builtin folder of Formulas. The only difference is the addition of these lines
              PHP Code:
              if (vOsc.getValue(OscStudy.OSC)>vOsc.getValue(OscStudy.OSC,-1))
                  
              setBarFgColor(Color.green);
              if(
              vOsc.getValue(OscStudy.OSC)<vOsc.getValue(OscStudy.OSC,-1))
                  
              setBarFgColor(Color.red); 
              As to not being able to copy that happens if you are using the browser built into the eSignal application. If you use a stand alone browser you should be able to copy without any problems
              Alex

              Originally posted by bandraguy
              Can this file be downloaded?

              I can't copy / paste and create new file.

              Thanks for your help,

              bandraguy

              Comment


              • #8
                Alexis,

                Thank you for your quick response, everyday I learn something new.

                bandraguy

                Comment


                • #9
                  bandraguy
                  You are most welcome
                  Alex

                  Comment

                  Working...
                  X