Announcement

Collapse
No announcement yet.

Ratio Spread

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

  • Ratio Spread

    Alexis Montenegro scripted a Ratio(spread) efs for the ACM Test group awhile ago. I'm trying to figure out how to apply it, or if the script will even work with the current version of 7.8. I put 2 symbols into the L and S input fields, but I see no results at all.

    Here's what I need to do: Chart (.33IBM + .33INTC + .33CSCO)/MSFT........as an example. I can chart the composite IBM+INTC+CSCO, but how can I divide this aggreagate value by another symbol with the tools available to us in 7.8?
    Attached Files

  • #2
    endert
    Enclosed in the php box below is the code modified to calculate the ratio you posted (in the image you can see the result plotted by this efs)
    Alex

    PHP Code:
    function preMain() {
        
    setCursorLabelName("Ratio");
        
    setStudyTitle("Ratio")
        }

    function 
    main(LS) {
        var 
    Long "0.33IBM + 0.33INTC + 0.33CSCO";
        if (
    == nullLong;
        var 
    Short "MSFT";
        if (
    == nullShort;
        var 
    vSymbol1 getValue("Close"0, -1L);
        var 
    vSymbol2 getValue("Close"0, -1S);
        var 
    vRatio vSymbol1 vSymbol2;

    return 
    vRatio;

    Comment


    • #3
      Got it..

      Thanks Alexis...

      What confused me was the lack of default inputs. I kept getting the value of "none".... I got it now....

      Comment


      • #4
        endert
        Thge enclosed revision of the formula will allow you to replace the symbols through Edit Studies instead of hard coding them into the script.
        Alex

        PHP Code:
        function preMain() {
            
        setCursorLabelName("Ratio");
            
        setStudyTitle("Ratio");
            
            var 
        fp1 = new FunctionParameter("Sym1"FunctionParameter.STRING);
            
        fp1.setName("Symbol1");
            
        fp1.setDefault("SPY");
            
            var 
        fp2 = new FunctionParameter("Sym2"FunctionParameter.STRING);
            
        fp2.setName("Symbol2");
            
        fp2.setDefault("QQQQ");
        }

        function 
        main(Sym1Sym2) {
            
            var 
        vSymbol1 getValue("Close"0, -1Sym1);
            var 
        vSymbol2 getValue("Close"0, -1Sym2);

            var 
        vRatio vSymbol1 vSymbol2;

            return 
        vRatio;

        Comment


        • #5
          Ratio Plot

          Alexis, thanks. Finally, how might I get this plot to 4 decimal places? The 2 decimal places isn't of much use to me. Any ideas? Thanks again.

          Comment


          • #6
            endert
            At this time efs has no way of controlling how many decimals are being displayed.
            To resolve this you have a couple of solutions
            a) replace the return statement with return vRatio*100;.
            This will display the value with more digits albeit with the decimals displaced (you can change the multiplier to 10 or 1000, etc)
            b) change the return to return new Array (vRatio,vRatio.toFixed(4));
            This will add a second return to the Cursor Window that will display 4 decimals
            In the image below you can see the results of both solutions
            Alex

            Comment

            Working...
            X