Announcement

Collapse
No announcement yet.

customMACD problem

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

  • customMACD problem

    Hallo

    I have saved a EFS with name customMACD15 in the EFS 2 Custom folder with settings 2,18,14 Int15.

    I then used this in the attached EFS study. The problem is that the study do not take this MACD into consideration when signals are produced.

    Can somebody please point out my error?

    I would appreciate the help

    Thank you

    Kobus
    Attached Files

  • #2
    Kobus
    There are several issues with the script you posted
    1. Although the efs() function is still available [for backwards compatibility] it has been replaced by the efsExternal() function which allows retrieving with a single call all the elements of an array returned by the called efs.
    The efs() function instead retrieves only the specific element defined by the seriesIndex parameter. This means that in your case
    PHP Code:
    var vMACD2_18  efs("/EFS 2 Custom/customMACD15.efs",0); 
    vMACD2_18 is returning only the first element (ie the MACD) of the array returned by the external efs.
    To retrieve the other elements returned by the called array using the efs() function you would need to do the following
    PHP Code:
    var vMACD2_18_MACD  efs("/EFS 2 Custom/customMACD15.efs",0);//this retrieves the MACD
    var vMACD2_18_SIGNAL  efs("/EFS 2 Custom/customMACD15.efs",1);//this retrieves the SIGNAL
    //etc 
    The better solution is to use the efsExternal() function. In that case you would first use
    PHP Code:
    var vMACD2_18  efsExternal("/EFS 2 Custom/customMACD15.efs"); 
    to call the external efs and retrieve all the elements of the array returned by that efs.
    Then you would extract the individual series objects using the getSeries() function
    PHP Code:
    var MACD2_18_MACD getSeries((vMACD2_18,0)
    var 
    MACD2_18_SIGNAL getSeries((vMACD2_18,1
    At that point using the getValue() method you can call the specific values from those series objects. For example
    PHP Code:
    vMACD2_18_MACD.getValue(0//retrieves the current value of the MACD series
    vMACD2_18_SIGNAL.getValue(0//retrieves the current value of the SIGNAL series 
    vMACD2_18_MACD.getValue(-1// retrieves the value of one bar ago of the MACD series
    //etc 
    2. The syntax you used to retrieve the values of the MACD and SIGNAL ie vMACD2_18.getValue(MACDStudy.MACD) and vMACD2_18.getValue(MACDStudy.SIGNAL) is invalid and only applicable to retrieve the values of the EFS1 MACD study. You need to use the syntax I showed in the examples above.
    3. If you are trying to run an external efs in the context of an interval that is different from the one of being charted you need to pass the inv() series as the last parameter of the efsExternal() call.
    This means that you will also need to pass all the other parameters the called efs is expecting (which are listed in the main() definition of the called efs).
    This in turn means that you will probably need to rearrange the parameters in the main definition of the called efs and possibly rewrite portions of the called efs.
    Before you proceed in modifying your efs I would suggest that you thoroughly read this thread as it provides detailed explanations and examples on how to use the efs() and efsExternal() functions.
    Alex

    Comment


    • #3
      Alex

      Thank you for the detailed reply, I appreciate your time and effort.

      I have tried to implement the code as best as I can understand, unfortuneately I still can not get it to work, obviously I did not understand correctly what to do. I tried different implementations, some plot the 15min MACD on my price pane, some plot nothing at all.

      No errors get plot in the Formula Output window, so I find it difficult to see where the problem is.

      I would appreciate if you can find the time to check the attached revised EFS for me and point my mistakes out.

      Thank you very much

      Kobus
      Attached Files

      Comment


      • #4
        Kobus
        Before trying to run the external efs in the context of a different interval (which as I explained in my prior reply means that you may need to rewrite parts of that efs) the first thing you need to ensure is that the efsExternal() call to your MACD efs is functioning correctly which it is not at this time regardless of whether you are passing an interval or not.
        Therefore I would suggest that you remove from your script every instance of the inv(15) parameter for the time being. When you have done that please read through my prior reply again and copy the examples as I provided them.
        Also remove the incorrect return new Array (...) statement in line 35. If you want to return the MACD plots to the chart then you need to use the return in line 60 to do that (you will also need to change the setPriceStudy() statement in preMain)
        Once you have made all the necessary changes and the script is working correctly you should read through the thread I indicated in my prior reply and experiment with the examples provided there so as to have a full understanding of what is required to call an external efs and run it in the context of a different interval.
        Alex

        Comment


        • #5
          Alex

          The study is now working as I wanted, namely giving signals only in the price pane.

          I do however still have problems getting the efsExternal() to work with the inv().

          I have used efs() instead for the time being with the settings and time frame saved in the name "customMACD15 " in the "EFS 2 Custom" folder.

          I would really appreciate it if you can change the code to make use of the efsExternal() combined with the inv() in the call line. It would help me a lot in getting a better understanding for the future. Unfortuneately my knowledge in programming is limited and I do put a lot of effort into studying and trying to understand things before I ask help.

          Your input is appreciated very much.

          Thank you

          Kobus
          Attached Files

          Comment


          • #6
            Kobus
            Rather than modifying your code I believe it would be best that I provide you with an explanation of the process so that you can then implement it with any script and not just this one. Also this way it may benefit anyone else who could be trying to accomplish the same (or similar) result.

            Given that you have elected to use the efs() function [instead of efsExternal() as suggested in my prior reply] I will be using that function in my examples. If you then want to replace efs() with efsExternal() in your code please refer to the examples in my prior reply and to the related article in the EFS KnowledgeBase
            In the following code sample you can see a schematic of the two scripts ie the calling efs that you posted and the called (or external) efs ie the customMACD.efs. In the code I am showing only those parts that have relevance to this explanation
            This is the basic setup that is required to call an external efs.
            PHP Code:
            //CALLING EFS
             
            //other code here
            function main(){
                var 
            MACD   efs("/EFS 2 Custom/customMACD.efs",0);
                var 
            SIGNAL efs("/EFS 2 Custom/customMACD.efs",1);
                
                
            //other code here
                
                
            return new Array (MACD.getValue(0), SIGNAL.getValue(0));

            Following is the called efs
            PHP Code:
            //CALLED EFS (customMACD.efs)
             
            //other code here
            function main(FastSlowSmoothingSourceSymbolIntervalParams){
             
                
            //other code here
                
                
            return new Array (getSeries(xMACD), getSeries(xMACDSig), getSeries(xMACDHist));

            Notice that in the main definition of the called efs there are several parameters.
            When calling the efs through efs() or efsExternal() you don't need to pass any parameters if you intend to use the called efs with its own defaults.
            If instead you want the called efs to use a different parameter (for example a different source) then you would need to pass that parameter. However once you pass one parameter then you need to pass ALL the parameters that the called efs is expecting. These must also be in the same order in which they are listed in the main definition of the called efs and in the same format that the called efs expects.
            Let us assume for example that we want to use (High+Low)/2 as the source of the MACD instead of Close.
            In this case the same sample code shown above will have to be written as follows
            PHP Code:
            //CALLING EFS
             
            //other code here
            function main(){
             
                var 
            MACD   efs("/EFS 2 Custom/customMACD.efs"012269"hl2"nullnulltrue);
                var 
            SIGNAL efs("/EFS 2 Custom/customMACD.efs"112269"hl2"nullnulltrue);
                
                
            //other code here
                
                
            return new Array (MACD.getValue(0),SIGNAL.getValue(0));

            Because I want to pass the parameter "hl2" I need to pass also all the other parameters the called efs is expecting.
            Note that in the example above some parameters are passed as null because in the called efs there is a condition that checks for those parameters to be null and in that case assigns a value.

            As explained in this thread in order to run an external efs (or separate function) in the context of a different interval or symbol two things need to happen
            1. you need to pass an interval or symbol series (using the inv() or sym() functions)
            2. this parameter needs to be the last one being passed
            This means that the efs() call now needs to be written in this way
            PHP Code:
            //CALLING EFS
             
            //other code here
            function main(){
             
                var 
            MACD   efs("/EFS 2 Custom/customMACD.efs"012269"close"nullnulltrueinv(15));
                var 
            SIGNAL efs("/EFS 2 Custom/customMACD.efs"112269"close"nullnulltrueinv(15));
                
                
            //other code here
                
                
            return new Array (MACDSIGNAL);//returning the series and not the value

            Notice that I have added inv(15) as the last parameter of each efs() call.
            However at this time the called efs is not set up to receive that additional parameter so we need to change the main definition of that efs to the following.
            PHP Code:
            //CALLED EFS (customMACD.efs)
             
            //other code here
            function main(FastSlowSmoothingSourceSymbolIntervalParamsmyInterval){
             
                
            //other code here
                
                
            return new Array (getSeries(xMACD), getSeries(xMACDSig), getSeries(xMACDHist));

            Notice that I now added a myInterval parameter at the end of the main definition. With this addition the called efs will recognize the parameter that is being passed and will run in the context of the interval defined by the efs() function located in the calling efs (note that it will also work without this parameter but it is good coding practice to add it).
            At this point you have all the information necessary to correctly modify both the calling and the called efs
            Alex

            Comment


            • #7
              Kobus
              Following up on my prior reply.
              Unless you have a specific reason (which I am not aware of) I am not sure I understand why you want to call a separate efs to compute the MACD and Signal on a different interval when all you would need to do is simply use the appropriate functions in your efs. These would be
              PHP Code:
              var MACD macd(12269inv(15));
              var 
              SIGNAL macdSignal(12269inv(15)); 
              The result is exactly the same as calling the external efs. Anyhow for more information on the MACD functions and the required syntax see this article in the EFS KnowledgeBase
              Also as it appears that you want to set conditions based on the state of a study which is being calculated on an external interval you may want to read this post which explains in detail the issues related to using multiple interval to generate signals.
              Alex

              Comment


              • #8
                Alex

                First of all thank you very much for your very detailed reply. I will study it and implement it and post it for your inspection (If you do not mind)

                To answer the question on calling an external efs, I was not aware that you can do it in the way you described. I was looking through different efs's and the customMACD had the option of using a different (longer) interval than the chart time frame. Other than that there was no reason.

                I will try both options for practice.

                Thank you again.

                Kobus

                Comment


                • #9
                  Kobus
                  You are most welcome.
                  FWIW all the EFS2 builtin studies have the option to be based on an external interval and/or symbol (ie an interval and/or symbol that are different from the one being plotted) through the use of the inv() or sym() functions (see the related link in my prior reply).
                  For more information on the EFS2 builtin studies and their required syntax you may want to see the EFS2 Function Reference-> Built-in Studies Functions in the EFS KnowledgeBase
                  Alex

                  Comment

                  Working...
                  X