Announcement

Collapse
No announcement yet.

Help with EFS indicator.

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

  • Help with EFS indicator.

    Hi,

    Could someone help me construct this price band indicator that uses the Upper and Lower Standard Error Bands. The following is the logic for the price bands. I hope it is clear. If it is not don’t hesitate to ask me for more clarification. I use a 5 length look back, a 2 deviant, and 3 smooth for the Standard Error Bands.

    Thank you in advance for your help.

    Logic for upper price band.

    For Bar = Len to BarCount –1 do
    Begin

    MaxHigh = max( High( Bar ), High( Bar –1) );

    If (Upper Standard Error Band ( Bar ) >= High( Bar ) then

    If (Upper Standard Error Band ( Bar ) <= MaxHigh then

    MaxHigh = min( Upper Standard Error Band ( Bar ), UpPriceBand_float );

    UpPriceBand_float = MaxHigh;

    Upper Price Band = SetSeriesValue( Bar, MaxHigh );

    End;

    Logic for lower price band.

    For Bar = Len to BarCount –1 do
    Begin

    MinLow = min( Low( Bar ), Low( Bar – 1) );

    If Lower Standard Error Band( Bar ) <= Low( Bar ) then

    If Lower Standard Error Band >= MinLow then

    MinLow = max(Lower Standard Error Band( Bar ), LoPriceBand_float );

    LoPriceBand_float = MinLow;

    Lower Price Band = SetSeriesValue( Bar, MinLow );

    End;

  • #2
    How do I?

    How do I get the results of this EFS file (Standard Error Bands.efs) into my EFS file (Price Bands.efs)?

    Thank you for your help.

    I’m sorry but I cannot attached both files.
    Attached Files
    Last edited by Earthling; 06-16-2006, 09:39 AM.

    Comment


    • #3
      Other file

      Here is the Standard Error Bands.efs file.
      Attached Files

      Comment


      • #4
        Earthling
        You can do that using the efsExternal() function. See the link for the required syntax.
        You can also find detailed information and examples in this thread which is specifically dedicated to the efsExternal() and efsInternal() functions and in this thread which includes some examples of studies on studies that use the efsExternal() function.
        Alex

        Comment


        • #5
          What am I missing here?

          What am I doing wrong? I cannot access the Standard Error Values. I cannot find Tutorial 5.

          Thank you for your help.

          In the next tutorial, Introductory Tutorial 5 – Accessing Chart Data, we will introduce you to the available data series in the Advanced Chart and the EFS functions used for requesting this data.


          function main() {

          var Symbol = null;
          var Interval = null;

          if(Symbol == null) Symbol = getSymbol();
          if(Interval == null) Interval = getInterval();
          var vSymbol = Symbol+","+Interval;

          var UpSEB = null;
          var myVar = efsExternal("Standard Error Bands.efs",sym(vSymbol));
          debugPrintln("Symbol: " + getSymbol());
          debugPrintln("Interval: " + getInterval());
          debugPrintln("CurrentBar: " + getCurrentBarIndex());
          debugPrintln("myVar: " + getSeries(myVar));

          Comment


          • #6
            Earthling
            As far as I know Tutorial 5 is not yet available
            With regards to your code example the following line is incorrect
            PHP Code:
            var myVar efsExternal("Standard Error Bands.efs",sym(vSymbol)); 
            This is because if you pass a parameter ie sym(vSymbol) you need to also pass all the parameters that the called efs is expecting in the same order in which they are listed in the main definition of the called efs.
            Remove the sym() parameter in your example and you will see that the script will return the series
            Also since you do not define any path in the efs name parameter make sure that the calling efs is saved in the same folder of the called efs. If it is in a different folder you will need to specifiy the path.
            Secondly you need to define which series you want to retrieve since the Standard Error Bands.efs returns an array. You do that using the getSeries(returnVal, series index) function. Examples of this are shown in the threads I indicated in my prior reply.
            Lastly the following line of code
            PHP Code:
            debugPrintln("myVar: " getSeries(myVar)); 
            will not return a value but will display [object series] in the Formula Output Window. The reason why and the steps you need to take to retrieve a value are explained in this post.
            Alex

            Comment


            • #7
              Thank you Alexis for responding to my post. Your help is indeed appreciated.

              “This is because if you pass a parameter ie sym(vSymbol) you need to also pass all the parameters that the called efs is expecting in the same order in which they are listed in the main definition of the called efs.”

              I did not know that I needed to pass all the parameters to make it work. I did want to pass a look back of 5 instead of using the default value of 10. Could you point to an example on how to do that.

              “Also since you do not define any path in the efs name parameter make sure that the calling efs is saved in the same folder of the called efs. If it is in a different folder you will need to specifiy the path.”

              At present it is in the same folder. When I enter C:\eSignal\Formulas\myEFS I get syntax error messages. I have not been able to locate any examples how to input the file path.

              Yes, as you suggested, the following works.

              function main() {

              var Symbol = null;
              var Interval = null;

              if(Symbol == null) Symbol = getSymbol();
              if(Interval == null) Interval = getInterval();
              var vSymbol = Symbol+","+Interval;

              var UpSEB = null;
              var myVar = efsExternal("Standard Error Bands.efs");
              debugPrintln("Symbol: " + getSymbol());
              debugPrintln("Interval: " + getInterval());
              debugPrintln("CurrentBar: " + getCurrentBarIndex());
              debugPrintln(" myVar1: " + getSeries(myVar,0), " myVar2: " + getSeries(myVar,1));

              Comment


              • #8
                Earthling

                I did not know that I needed to pass all the parameters to make it work. I did want to pass a look back of 5 instead of using the default value of 10. Could you point to an example on how to do that.
                You have two options. One is to set the default length value to 5 in the Standard Error Bands efs. In this case you would not need to pass any parameters when calling the external efs as you would be using its default settings.
                The other is to call the efs and pass all the parameters as I indicated in my previous reply eg.
                var myVar = efsExternal("Standard Error Bands.efs", 5, 3, "close", null, null, false);
                In this example some of the parameters that are being passed (ie. Symbol and Interval) are null because there is a check for null in the Standard Error Bands efs. In fact if the value is null it is set to the chart's symbol and interval using getSymbol() and getInterval()

                At present it is in the same folder. When I enter C:\eSignal\Formulas\myEFS I get syntax error messages. I have not been able to locate any examples how to input the file path.
                See this thread on the same subject. For your information I found it by searching for the keyword path
                Alex

                Comment


                • #9
                  Thank you again Alexis. I still need some help with some additional programming concepts. The following is the code for my price band indicator I have created so far. My first sticking point is in the “ if, then, else” statements. I want to reference a previous value of the new array or indicator that I am making. I’m not sure how to accomplish this but it may work out by knowing how to overcome my next sticking point. I think I need to initiate a loop for calculate my new array. How would I do this.

                  Thank you for your help.

                  PHP Code:
                  /*
                  function preMain(){
                      setPriceStudy(true);
                      setStudyTitle("Price Bands");
                      setCursorLabelName("PBHi",0);
                      setCursorLabelName("PBLo",1);
                      setDefaultBarFgColor(Color.blue,0);
                      setDefaultBarFgColor(Color.red,1);
                      setPlotType(PLOTTYPE_LINE,0);
                      setPlotType(PLOTTYPE_LINE,1);
                      setDefaultBarThickness(1,0);
                      setDefaultBarThickness(1,1);
                  }
                  */



                  function main() {

                  var 
                  nPriceBand null;
                  var 
                  SEB efsExternal("/Downloads/Standard Error Bands.efs"53"close"nullnullfalse);
                  var 
                  UpSEB getSeries(SEB,0);
                  var 
                  BarHi getValue("High");
                  var 
                  n2BarHi Math.max(BarHigetValue("High", -1)); 
                  var 
                  PBHi null;
                  var 
                  PreviousPBHi getSeries(nPriceBand,0)(-1);
                  var 
                  LoSEB getSeriesSEB,1);
                  var 
                  BarLo getValue("Low");
                  var 
                  n2BarLo Math.min(BarLogetValue("Low", -1));
                  var 
                  PBLo null;
                  var 
                  PreviousPBLo getSeries(nPriceBand,1)(-1);
                   

                  /* Logic for upper price band is as follows.
                     If BarHi > UpSEB then
                      PbHi = n2BarHi
                     else
                       If UpSEB > n2BarHi then
                        PbHi = n2BarHi
                       else
                        If UpSEB > PbHi(-1) then
                         PbHi = PbHi(-1)
                        else
                         PbHi = UpSEB;   */

                  if (BarHi UpSEB) { then
                      PbHi 
                  n2BarHi
                  } else {
                      if (
                  UpSEB n2BarHi) { then
                          PbHi 
                  n2BarHi
                      
                  } else {
                          if (
                  UpSEB PreviousPBHi) { then
                              PbHi 
                  PreviousPBHi
                          
                  } else {
                              
                  PbHi UpSEB }}};

                  nPriceBand PBHi;

                  /* Logic for lower price band is as follows.
                     If BarLo < LoSEB then
                      PbLo = n2BarLo
                     else
                       If LoSEB < n2BarLo then
                        PbLo = n2BarLo
                       else
                         If LoSEB < PbLo(Bar -1) then
                          PbLo = PbL(Bar -1)
                         else
                           PbLo = LoSEB;   */

                  if (BarLo LoSEB) { then
                      PbLo 
                  n2BarLo
                  } else {
                      if (
                  LoSEB n2BarLo) { then
                          PbLo 
                  n2BarLo
                      
                  } else {
                          if (
                  LoSEB PreviousPBLo) { then
                              PbLo 
                  PreviousPBLo
                          
                  } else {
                              
                  PbLo LoSEB }}};

                  nPriceBand PBLo;

                  debugPrintln("Symbol: " getSymbol());
                  debugPrintln("Interval: " getInterval());
                  debugPrintln("CurrentBar: " getCurrentBarIndex());
                  debugPrintln(" UpSEB " getSeries(SEB,0), "LoSEB: " getSeriesSEB,1));

                  //return new Array (getSeries(nPriceBand,0), getSeries(nPriceBand,1))

                  Last edited by Earthling; 06-25-2006, 05:53 PM.

                  Comment


                  • #10
                    Earthling
                    To retrieve prior values of UpSEB (and LoSEB) you need to use the .getValue(n) method where n represents the bar index of the value you wish to retrieve eg
                    PHP Code:
                    var SEB efsExternal("/Downloads/Standard Error Bands.efs"53"close"nullnullfalse);
                    var 
                    UpSEB getSeries(SEB,0);//retrieve the specific series
                    //once you have the series you can access the values 
                    //UpSEB.getValue(0) is the current value of UpSEB
                    //UpSEB.getValue(-1); is the value of UpSEB at the prior bar
                    //UpSEB.,getValue(-2);//is the value of UpSEB two bars ago
                    //etc etc
                    //same for LoSEB 
                    With regards to referencing historical values of a custom variable (that is not a series) there are several ways you can do it.
                    If the variable is in your return statement you could use the ref() function. If not then you have two methods.
                    If you only want two or three values back then the easiest method is to declare your variables [for example myVar_0, myVar_1, etc] as global variables [ie outside of main and preMain] and then as the first thing in main() write
                    PHP Code:
                    if(getBarState()==BARSTATE_NEWBAR){//at every new bar
                        
                    myVar_2 myVar_1;//transfer the value of myVar_1 to myVar_2
                        
                    myVar_1 myVar_0;//transfer the value of myVar_0 to myVar_1

                    At that point myVar_1 is the value of myVar_0 one bar back and myVar_2 is the value of myVar_0 two bars back.
                    If instead you have to retrieve historical values beyond two or three bars back then you may want to look at creating an array to store the historical values. For information on arrays see this article in the EFS KnowledgeBase
                    Alex

                    Comment


                    • #11
                      Alex,

                      Thank you again for your very valued assistance. I have posted my latest code version. However, I still have a problem yet because sometimes the PBHi value is <None>. There always appear to be a value for PBLo and I still need to verify the results yet. But for now time is running out. I just wanted to get this note of thanks out to you and call it quits for now and ask you if you would calculate this indicator this way?

                      PHP Code:
                      function preMain(){
                          
                      setPriceStudy(true);
                          
                      setStudyTitle("Price Bands");
                          
                      setCursorLabelName("PBHi",0);
                          
                      setCursorLabelName("PBLo",1);
                          
                      setDefaultBarFgColor(Color.blue,0);
                          
                      setDefaultBarFgColor(Color.red,1);
                          
                      setPlotType(PLOTTYPE_LINE,0);
                          
                      setPlotType(PLOTTYPE_LINE,1);
                          
                      setDefaultBarThickness(1,0);
                          
                      setDefaultBarThickness(1,1);
                          
                          var 
                      PreviousPBHi null;
                          var 
                      PreviousPBLo null;
                      }

                      function 
                      main() {

                      var 
                      nPriceBand null;
                      var 
                      SEB efsExternal("/Downloads/Standard Error Bands.efs"53"close"nullnullfalse);
                      var 
                      UpSEB getSeries(SEB,0);
                      var 
                      BarHi getValue("High");
                      var 
                      n2BarHi Math.max(BarHigetValue("High", -1)); 
                      var 
                      PBHi null;
                      var 
                      PrevPbHi getGlobalValue("PreviousPBHi");
                      var 
                      LoSEB getSeriesSEB,1);
                      var 
                      BarLo getValue("Low");
                      var 
                      n2BarLo Math.min(BarLogetValue("Low", -1));
                      var 
                      PBLo null;
                      var 
                      PrevPbLo getGlobalValue("PreviousPBLo");

                      /* Logic for upper price band is as follows.
                         If BarHi >= UpSEB then
                          PbHi = n2BarHi
                         else
                           If UpSEB > n2BarHi then
                            PbHi = n2BarHi
                           else
                            If UpSEB > PbHi(-1) then
                             PbHi = PbHi(-1)
                            else
                             PbHi = UpSEB;   */


                      if (BarHi >= UpSEB){
                          
                      PbHi n2BarHi;
                      } else if (
                      UpSEB n2BarHi){
                          
                      PbHi n2BarHi;
                      } else if (
                      UpSEB PrevPbHi){
                          
                      PbHi PrevPbHi;
                      } else {
                          
                      PbHi UpSEB };

                      setGlobalValue"PreviousPBHi"PbHi ); 

                      /* Logic for lower price band is as follows.
                         If BarLo < LoSEB then
                          PbLo = n2BarLo
                         else
                           If LoSEB < n2BarLo then
                            PbLo = n2BarLo
                           else
                             If LoSEB < PbLo(Bar -1) then
                              PbLo = PbL(Bar -1)
                             else
                               PbLo = LoSEB;   */

                      if (BarLo <= LoSEB){
                          
                      PbLo n2BarLo;    
                      } else if (
                      LoSEB n2BarLo){
                          
                      PbLo n2BarLo;
                      } else if (
                      LoSEB PrevPbLo){
                          
                      PbLo PrevPbLo;
                          } else {
                          
                      PbLo LoSEB};

                      setGlobalValue"PreviousPBLo"PbLo ); 

                      //debugPrintln("Symbol: " + getSymbol());
                      //debugPrintln("Interval: " + getInterval());
                      //debugPrintln("CurrentBar: " + getCurrentBarIndex());
                      //debugPrintln(" UpSEB " + getSeries(SEB,0), "LoSEB: " + getSeries( SEB,1));
                      //debugPrintln("  PreviousPBHi: " + getGlobalValue("PrevPbHi"), "  PreviousPBLo: " + getGlobalValue("PrevPbLo"),"  Place: " + getGlobalValue("Place"), "CurrentBar: " + getCurrentBarIndex());
                      //debugPrintln();

                      return new Array (PbHiPbLo);

                      Last edited by Earthling; 07-02-2006, 09:41 PM.

                      Comment


                      • #12
                        Alex,

                        Ok! I have my indicator all work out and repasted the corrected code in my previous post. All values are there and appear to be correct. The way I used the global values is that the correct way? Do you have any recommendations for optimizing the code? Thank you very much for help.

                        Comment

                        Working...
                        X