Announcement

Collapse
No announcement yet.

Same Formula used multiple times in EFS

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Same Formula used multiple times in EFS

    I have a piece of code / EFS that works fine.
    I use it 2 times on a chart first based on High.
    Then I edited it to be based on Low.

    How do I change the code to combine so that one EFS will do / plot both lines?

    setStudyTitle("Berts SELL");
    setCursorLabelName("LR-L Curve");

    and

    setStudyTitle("Berts Buy");
    setCursorLabelName("LR-H Curve");

    NEW would be combined ...

    setStudyTitle("Berts BUYnSELL");
    setCursorLabelName("LR-L Curve");
    setCursorLabelName("LR-H Curve");

    ------------------------------------------------------------
    Here is the original code.

    /************************************************** *****************
    * Description : This Indicator plots the Linear Regression Curve
    *
    ************************************************** ******************/

    //Global Variables


    var bInitialized = false;


    function preMain()
    {
    setPriceStudy(true);
    setStudyTitle("Berts SELL");
    setCursorLabelName("LR-L Curve");

    // Number of Bars before signal is cancelled
    var fp1 = new FunctionParameter( "frLength", FunctionParameter.NUMBER);
    fp1.setName( "Length" );
    fp1.setLowerLimit(0);
    fp1.setDefault(20);

    //Line thickness
    var fp2 = new FunctionParameter( "LineThickness", FunctionParameter.NUMBER);
    fp2.setName( "Line thickness" );
    fp2.setLowerLimit( 1 );
    fp2.setUpperLimit( 10 );
    fp2.setDefault( 2 );

    // Filter on Mean Swing Line
    var fp3 = new FunctionParameter("LineColor", FunctionParameter.COLOR);
    fp3.setName( "LineColor" );
    fp3.setDefault(Color.red);

    // end of formula paramaters

    }
    function main(frLength,LineThickness,LineColor)
    {
    var len = frLength;
    var vPrice = getValue("Low", 0, -len);
    var Num1 = 0.0;
    var Num2 = 0.0;
    var SumBars = len * (len - 1) * 0.5;
    var SumSqrBars = (len - 1) * len * (2 * len - 1) / 6;
    var SumY = 0.0;
    var Sum1 = 0.0;
    var Sum2 = 0.0;
    var Slope = 0.0;
    var Intercept = 0.0;
    var i = 0;

    //script is initializing
    if ( getBarState() == BARSTATE_ALLBARS ) {
    return null;
    }

    //initialize once-only paramaters
    if ( bInitialized == false ) {

    setDefaultBarFgColor( LineColor, 0 );
    setDefaultBarThickness( Math.round( LineThickness ), 0 );

    bInitialized = true;
    }

    for (i = 0; i < len; i++)
    {
    SumY += vPrice[i];
    Sum1 += i * vPrice[i];
    }
    Sum2 = SumBars * SumY;
    Num1 = len * Sum1 - Sum2;
    Num2 = SumBars * SumBars - len * SumSqrBars;
    if (Num2 != 0) Slope = Num1 / Num2;
    Intercept = (SumY - Slope * SumBars) / len;
    var LinearRegValue = Intercept + Slope * (len - 1 );
    return LinearRegValue;
    }
    OpaBert

  • #2
    See if this is close...

    I know, you knew, I couldn't resist...lol!

    CORRECTED!!

    PHP Code:
    /**************************** 

    * Description : This Indicator plots the Linear Regression Curve


    ******************/

    //Global Variables


    var bInitialized false;


    function 
    preMain()
    {
    setPriceStudy(true); 
    setStudyTitle("Berts SELL");
    setCursorLabelName("LR-L Curve",0);

    setCursorLabelName("LR-H Curve",1);

    // Number of Bars before signal is cancelled
    var fp1 = new FunctionParameter"frLength"FunctionParameter.NUMBER);
    fp1.setName"Length" );
    fp1.setLowerLimit(0);
    fp1.setDefault(20);

    //Line thickness
    var fp2 = new FunctionParameter"LineThickness"FunctionParameter.NUMBER); 
    fp2.setName"Line thickness" );
    fp2.setLowerLimit);
    fp2.setUpperLimit10 );
    fp2.setDefault);

    // Filter on Mean Swing Line
    var fp3 = new FunctionParameter("LineColor"FunctionParameter.COLOR);
    fp3.setName"LineColor" );
    fp3.setDefault(Color.red); 

    // end of formula paramaters 

    }
    function 
    main(frLength,LineThickness,LineColor)
    {
    var 
    len frLength;

    var 
    vPriceL getValue("Low"0, -len);

    var 
    vPriceH getValue("High"0, -len);


    var 
    Num1 0.0;
    var 
    Num2 0.0;

    var 
    Num1H 0.0;
    var 
    Num2H 0.0;

    var 
    SumBars len * (len 1) * 0.5;
    var 
    SumSqrBars = (len 1) * len * (len 1) / 6;
    var 
    SumY 0.0;
    var 
    Sum1 0.0;
    var 
    Sum2 0.0;

    var 
    SumYH 0.0;
    var 
    Sum1H 0.0;
    var 
    Sum2H 0.0;

    var 
    Slope 0.0;
    var 
    SlopeH 0.0;

    var 
    Intercept 0.0;
    var 
    InterceptH 0.0;
    var 
    0;
    var 
    0;

    //script is initializing
    if ( getBarState() == BARSTATE_ALLBARS ) {
    return 
    null;
    }

    //initialize once-only paramaters
    if ( bInitialized == false ) {

    setDefaultBarFgColorLineColor);
    setDefaultBarFgColorColor.blue);

    setDefaultBarThicknessMath.roundLineThickness ), );
    setDefaultBarThicknessMath.roundLineThickness ), );

    bInitialized true;


    // LOW PROCESSING

    for (0leni++)
    {
    SumY += vPriceL[i];
    Sum1 += vPriceL[i];
    }
    Sum2 SumBars SumY;
    Num1 len Sum1 Sum2;
    Num2 SumBars SumBars len SumSqrBars;
    if (
    Num2 != 0Slope Num1 Num2;
    Intercept = (SumY Slope SumBars) / len;
    var 
    LinearRegValueL Intercept Slope * (len ); 


    // HIGH PROCESSING

    for (0lenj++)
    {
    SumYH += vPriceH[j];
    Sum1H += vPriceH[j];
    }
    Sum2H SumBars SumYH;
    Num1H len Sum1H Sum2H;
    Num2H SumBars SumBars len SumSqrBars;
    if (
    Num2H != 0SlopeH Num1H Num2H;
    InterceptH = (SumYH SlopeH SumBars) / len;
    var 
    LinearRegValueH InterceptH SlopeH * (len ); 



    return new Array( 
    LinearRegValueL,LinearRegValueH ) ;

    Last edited by buzzhorton; 07-27-2006, 02:12 PM.

    Comment


    • #3
      I added a "BERT" button so you don't have to reload to change the parameters.

      EFS attached.
      Attached Files

      Comment


      • #4
        buzzhorton

        Originally posted by buzzhorton
        I added a "BERT" button so you don't have to reload to change the parameters.
        FWIW he would not need to reload the efs to change the parameters.
        All he would need to do is right click the chart, select Edit Studies and call the study from the dropdown list (or select the chart and then in the main menu click Chart Options->Edit Studies which is the same thing)
        Alex

        Comment


        • #5
          Squiggley Lines !

          Thanks Avery,

          They may be squiggley lines but you would be amazed at how accurate they are to consistently pull money out of the market when used properly.

          Now if I only had my Dynamic S/R ... LOL

          Bert.

          Originally posted by buzzhorton
          See if this is close...

          I know, you knew, I couldn't resist...lol!

          CORRECTED!!

          PHP Code:
          /**************************** 

          * Description : This Indicator plots the Linear Regression Curve


          ******************/

          //Global Variables


          var bInitialized false;


          function 
          preMain()
          {
          setPriceStudy(true); 
          setStudyTitle("Berts SELL");
          setCursorLabelName("LR-L Curve",0);

          setCursorLabelName("LR-H Curve",1);

          // Number of Bars before signal is cancelled
          var fp1 = new FunctionParameter"frLength"FunctionParameter.NUMBER);
          fp1.setName"Length" );
          fp1.setLowerLimit(0);
          fp1.setDefault(20);

          //Line thickness
          var fp2 = new FunctionParameter"LineThickness"FunctionParameter.NUMBER); 
          fp2.setName"Line thickness" );
          fp2.setLowerLimit);
          fp2.setUpperLimit10 );
          fp2.setDefault);

          // Filter on Mean Swing Line
          var fp3 = new FunctionParameter("LineColor"FunctionParameter.COLOR);
          fp3.setName"LineColor" );
          fp3.setDefault(Color.red); 

          // end of formula paramaters 

          }
          function 
          main(frLength,LineThickness,LineColor)
          {
          var 
          len frLength;

          var 
          vPriceL getValue("Low"0, -len);

          var 
          vPriceH getValue("High"0, -len);


          var 
          Num1 0.0;
          var 
          Num2 0.0;

          var 
          Num1H 0.0;
          var 
          Num2H 0.0;

          var 
          SumBars len * (len 1) * 0.5;
          var 
          SumSqrBars = (len 1) * len * (len 1) / 6;
          var 
          SumY 0.0;
          var 
          Sum1 0.0;
          var 
          Sum2 0.0;

          var 
          SumYH 0.0;
          var 
          Sum1H 0.0;
          var 
          Sum2H 0.0;

          var 
          Slope 0.0;
          var 
          SlopeH 0.0;

          var 
          Intercept 0.0;
          var 
          InterceptH 0.0;
          var 
          0;
          var 
          0;

          //script is initializing
          if ( getBarState() == BARSTATE_ALLBARS ) {
          return 
          null;
          }

          //initialize once-only paramaters
          if ( bInitialized == false ) {

          setDefaultBarFgColorLineColor);
          setDefaultBarFgColorColor.blue);

          setDefaultBarThicknessMath.roundLineThickness ), );
          setDefaultBarThicknessMath.roundLineThickness ), );

          bInitialized true;


          // LOW PROCESSING

          for (0leni++)
          {
          SumY += vPriceL[i];
          Sum1 += vPriceL[i];
          }
          Sum2 SumBars SumY;
          Num1 len Sum1 Sum2;
          Num2 SumBars SumBars len SumSqrBars;
          if (
          Num2 != 0Slope Num1 Num2;
          Intercept = (SumY Slope SumBars) / len;
          var 
          LinearRegValueL Intercept Slope * (len ); 


          // HIGH PROCESSING

          for (0lenj++)
          {
          SumYH += vPriceH[j];
          Sum1H += vPriceH[j];
          }
          Sum2H SumBars SumYH;
          Num1H len Sum1H Sum2H;
          Num2H SumBars SumBars len SumSqrBars;
          if (
          Num2H != 0SlopeH Num1H Num2H;
          InterceptH = (SumYH SlopeH SumBars) / len;
          var 
          LinearRegValueH InterceptH SlopeH * (len ); 



          return new Array( 
          LinearRegValueL,LinearRegValueH ) ;

          OpaBert

          Comment


          • #6
            Thanks.

            I had asked about this days ago!!

            But, that's still a bunch of clicking.



            Originally posted by Alexis C. Montenegro buzzhorton



            FWIW he would not need to reload the efs to change the parameters.
            All he would need to do is right click the chart, select Edit Studies and call the study from the dropdown list (or select the chart and then in the main menu click Chart Options->Edit Studies which is the same thing)
            Alex

            Comment


            • #7
              Re: Squiggley Lines !

              Ok, so then explain, in detail, how to use those squiggley lines.


              Originally posted by OpaBert
              Thanks Avery,

              They may be squiggley lines but you would be amazed at how accurate they are to consistently pull money out of the market when used properly.

              Now if I only had my Dynamic S/R ... LOL

              Bert.

              Comment


              • #8
                Bert:

                Here's a present for you... $BERT_RIBBON

                I created this to see if I can understand how your squiggley lines can make me money.

                But there is something weird going on with this code.

                var vaLRV = ( LinearRegValue, inv(xInterval) ) ;

                But, vaLRV is NOT equal LinearRegValue?!??!

                Maybe someone can figure it out.


                PHP Code:

                /**************************** 

                * Description : This Indicator plots the Linear Regression Curve


                ******************/

                var bInitialized false;

                function 
                preMain() {

                    
                setPriceStudy(false);
                    
                setStudyTitle("$BERT_Ribbon");

                    
                setCursorLabelName("Ind2"0);
                  
                    
                setDefaultBarFgColor(Color.red,0);
                 

                    
                setDefaultBarThickness(2,0);  

                    
                setPlotType(PLOTTYPE_LINE ,0); 

                }

                 
                askForInput();


                    var 
                iDebug = new FunctionParameter("iDebug"FunctionParameter.BOOLEAN);
                    
                iDebug.setDefaultfalse );

                    var 
                iAlert = new FunctionParameter("iAlert"FunctionParameter.BOOLEAN);
                    
                iAlert.setDefaultfalse );

                    var 
                frLength = new FunctionParameter("frLength"FunctionParameter.NUMBER);
                    
                frLength.setDefault05 );




                function 
                mainiAlert frLengthiDebug    ) {

                    if (
                close(-1)==null
                        return;
                       
                var 
                xInterval getInterval()  ;

                var 
                len frLength;
                var 
                vPrice getValue("High"0, -len);
                var 
                Num1 0.0;
                var 
                Num2 0.0;
                var 
                SumBars len * (len 1) * 0.5;
                var 
                SumSqrBars = (len 1) * len * (len 1) / 6;
                var 
                SumY 0.0;
                var 
                Sum1 0.0;
                var 
                Sum2 0.0;
                var 
                Slope 0.0;
                var 
                Intercept 0.0;
                var 
                0;





                 

                for (
                0leni++)
                {
                SumY += vPrice[i];
                Sum1 += vPrice[i];
                }

                Sum2 SumBars SumY;

                Num1 len Sum1 Sum2;

                Num2 SumBars SumBars len SumSqrBars;

                if (
                Num2 != 0Slope Num1 Num2;

                Intercept = (SumY Slope SumBars) / len;

                var 
                LinearRegValue Intercept Slope * (len ); 




                var 
                vaLRV = ( LinearRegValueinv(xInterval) ) ;

                var 
                xaLRV formatPriceNumbervaLRV  ) * 1   ;    

                var 
                xaLRV1 formatPriceNumbervaLRV.getValue(-1)  ) * 1   ;    

                var 
                xDiff1 xaLRV xaLRV1 ;


                var 
                Ind2 Ind2 ;

                 
                if( 
                xaLRV >= xaLRV1 
                        
                    
                setBarBgColorColor.cyan); 
                 
                else     
                setBarBgColorColor.magenta); 
                  
                 

                if(
                iDebug == true){

                debugPrint"--------------------------------"    "\n" );
                 
                debugPrint"xaLRV :    " + ( xaLRV  ) + "\n" ); 
                debugPrint"xaLRV1:    " + ( xaLRV1 ) + "\n" );

                debugPrintgetValue"Time" )      + "\n" );
                debugPrint"--- $BERT_Ribbon ---"    "\n" );

                }



                return ( 
                frLength ) ;

                Comment


                • #9
                  Using Squiggleys!

                  Duh, How easy can it be ... Attach File
                  Attached Files
                  OpaBert

                  Comment


                  • #10
                    Here's the info / what you should know about my "Squiggley Lines Method".

                    1. I trade the DAX Futures Index.
                    Every 1 point move is worth 25 Euros so call it 25 bucks.

                    2. I go for 2 or 2-1/2 point scalps and longer runs when the setup is right.

                    3. My total cost in and out (Round turn) is about $6.00 per unit.
                    So even if I exit with only a 1/2 point I still have a profitable trade.

                    4. I usually trade 1 unit unless the setup is very strong.
                    Then I might go with 2 or 3 units / contracts.

                    5. To trade 1 contract you need to have at least 5 to 6 K$ on account.

                    6. I'm NEVER holding over night.

                    7. DAX trades from 2 AM to 4 PM EDT and it would be very unusual if you couldn't do at least 2 trades per hour.
                    Making several 100 dollars gets easy once you get comfortable with the method.

                    (There are many other advantages to trading this way as well.)

                    8. You need 3 "Berts" on a chart. 20, 50 & 150 (Green = H, Red = L)

                    9. You also need an EMA(20) (Blue)

                    10. I add extra stuff, but it's not necessary.
                    For example in the AAPL chart in post "Using Squiggleys! - Posted: 07-27-2006 11:25 PM"
                    I added Avery's "TRO_TREND_LowerMin" to see how much confluence there would be.

                    11. I Day Trade trade using a 1 minute real time chart.
                    This method appears to work in any time frame and for any equity.

                    12. The entry is very simple.
                    You might even be able to program the buy and sell signals with a background color and audio clip.
                    (I use the Navy General Quarters announcement having spent 23 years in the service.)

                    For a BUY:
                    If prior close was below EMA(20) and now
                    IF Close is above EMA(20) and
                    Close is above any TWO Berts Green Lines then go Long.

                    Experience will give you a feel for the entry price between Close and EMA(20)

                    13. If you want to stay in / ride the trade a conservative exit would be
                    a close below the Berts Red Line immediately below the entry.
                    (with each new bar exit is adjusted)

                    14. Definately Bail if Close is below EMA(20) and Red line as described in 13 above.
                    When you are wrong, nothing is 100% in trading, you catch it quickly.
                    Knowing where my Dynamic S/R Zone is will help reduce wip-saw.

                    15. Short using the converse approach to EMA(20) and Berts Red Lines.

                    Feel free to PM me for more info, especially if you trade DAX.

                    I'd also be interested in working with a knowledgeable EFS programmer to develop an actual trading system
                    that identifies the trades with visual and audio ques plus test the automatic trading possibility.

                    Bert.
                    Last edited by OpaBert; 08-01-2006, 07:32 AM.
                    OpaBert

                    Comment


                    • #11
                      Bert:

                      Thanks for sharing.

                      Comment


                      • #12
                        My &quot;Squiggly Lines Method&quot;

                        Hi Avery,

                        NO SQUIGGLY LINES on the chart (that would make you happy! )
                        instead, for a BUY:
                        Draw a Horizontal Bright Green "Segment" from the "signal bar Close" 10 bars to the right and,
                        Draw another Horizontal Bright Green "Segment" from the "signal bar "
                        (Close minus ((Close minus EMA(20)) / 2))) 10 bars to the right.

                        This would represent the optimal buy zone.

                        For a Sell:
                        Draw a Horizontal Red "Segment" from the "signal bar Close" 10 bars to the right and,
                        Draw another Horizontal Red "Segment" from the "signal bar "
                        (Close plus ((EMA(20) minus Close) / 2)) 10 bars to the right.

                        This would represent the optimal sell zone.

                        And if you really are up for a challenge to impress us,

                        Make the background in the horizontal Buy Zone a pale green and the background in the horizontal Sell Zone a pale red.

                        Additionally, you might want to include the "Play Sound" feature when a Buy / Sell is triggered.
                        I use audio a lot so I don't have to stare at the screen.
                        That way I can be doing other things and just let the computer call me when a trade is possible.
                        Reference my attached "HeadsUp" audio file.

                        PM me if there are any questions. Thanks again.

                        Bert
                        Attached Files
                        Last edited by OpaBert; 08-01-2006, 03:11 PM.
                        OpaBert

                        Comment


                        • #13
                          Sample Buy / Sell Zones

                          Here's what the Buy / Sell Zones would look like WITH the "Squiggly Lines" on the chart.

                          Notice I made the 10 Bar Horizontal lines thick for better visability.
                          Attached Files
                          OpaBert

                          Comment


                          • #14
                            Buy / Sell Zones WITHOUT Squiggly Lines

                            Here's what the Buy / Sell Zones would look like WITHOUT the "Squiggly Lines".

                            Notice also that in all 5 trades identified, at LEAST 2 points were easily attainable. (Often more)

                            10 points = $250.00 between 12:30 and 14:30.

                            With audibles included you can snooze and trade!

                            The reason you would want to keep the "Squiggly Lines" on the chart is to help you stay in or get out of a trade.
                            Maybe that's where the Slot Machine comes in?
                            Attached Files
                            Last edited by OpaBert; 08-01-2006, 04:05 PM.
                            OpaBert

                            Comment


                            • #15
                              Sorry Avery, the code is way beyond me.
                              OpaBert

                              Comment

                              Working...
                              X