Announcement

Collapse
No announcement yet.

EFS Query on calling one EFS into another EFS

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

  • EFS Query on calling one EFS into another EFS

    Hi

    I previously used TS Easy Language but have decided to see what moving over to EFS is like -

    I have looked at a lot of the various examples studies provided in the forum and incorporated some of what was set out in some test EFSs

    I have written an EFS study “TEST-1” which plots OK up to a point

    However I have been trying to call “TEST-1”into another EFS “TEST-2” and calculate a moving average in “TEST-2” based on the “TEST-1” output

    I have encountered a couple of problems with using the data from “TEST-1” in “TEST-2”

    1. I believe this is because “TEST-1” data output is calculated only for selected bars (ie not all bars) so there are gaps /zeros in the data output generated by the study when compared against the underlying market price data –

    I would like to fill these gaps in the “TEST-1” output with the last price that was calculated in “TEST-1” (ie the last number that was generated that wasn’t null or zero -

    I understand that this will mean that the same price will be used to fill in data in extended gaps and there will therefore be flat line output by “TEST-2” for extended periods of time on the chart )

    2. I have noticed that while a moving average is calculated by “TEST-2” it is not based on the output of “TEST-1” but rather it appears to be based on the closing price of each bar (ie not the data from “TEST-1”) –

    I guess this may be because of the gaps in the “TEST-1” data output and that in some way EFS defaults to using the closing price when it doesn’t know what else to do

    3. Going back to point 2 above is there some way I can do calculations on the “TEST-1” output that generates results other than zero –

    ie how can I extract the last 3, 10 or 20 etc numbers greater than zero and do a calculation on them – for example a moving average –

    please note the frequency at which data is calculated/output by “TEST-1” that produces results other than zero is not regular

    The Studies “TEST-1”and “TEST-2” are below

    Study “Test-1”
    function preMain() {
    setPriceStudy(true);
    setComputeOnClose()
    setStudyTitle("FunctionParameter: TEST-1");
    setPlotType(PS_DASH);
    setCursorLabelName("Upper Env", 0);
    setCursorLabelName("Lower Env", 1);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarFgColor(Color.blue, 1);

    var fp1 = new FunctionParameter("Test", FunctionParameter.BOOLEAN);
    fp1.setName("Envelope");
    fp1.setPriceStudy(true);
    }

    function main(Test) {
    if ((sma(30) < sma(20)) && (sma(15) < sma(20))) {var FlagA = sma(20)}
    return (FlagA);
    }


    Study “Test-2”
    function preMain(){
    setPriceStudy(true);
    setStudyTitle("TEST-2");
    setCursorLabelName("myStudy",0);
    setCursorLabelName("myAvg",1);
    setCursorLabelName("myAvgTEST",2);
    setDefaultBarFgColor(Color.blue,0);
    setDefaultBarFgColor(Color.red,1);
    setDefaultBarFgColor(Color.green,2);
    setDefaultBarThickness(3, 0);
    setDefaultBarThickness(3, 1);
    setDefaultBarThickness(5, 2);
    setPlotType(PS_DASH,0);
    setPlotType(PS_DASH,1);
    setPlotType(PS_DASH,2);
    }
    function main(){
    //the following line calls the separate function and creates the series object
    var myStudy = efsExternal("TEST-1.efs");
    //the following line creates a simple moving average of length 3 using myStudy as the source
    var myStudyAvg = sma(3, "myStudy".getabsValue);
    //the following line was an attempt to pull out the previously calculated prices from myStudy and myStudyAvg
    var xyz = (myStudy[-1]/3+myStudy[-2]/3+myStudy[-3]/3);
    //var xyz1 = (myStudy(-1)/3+myStudy(-2)/3+myStudy(-3)/3);
    // var aaa = new Array (myStudy(-1)/3+myStudy(-2)/3+myStudy(-3)/3);
    return new Array (myStudy, myStudyAvg, xyz);
    }

    Lastly could you advise me how I can call a previously calculated value from “myStudy” or “myStudyAvg”above and use it in another calculation –

    By way of example I tried doing

    var bbb = (myStudy Avg(-10)/ myStudy (-3));
    or
    var bbb = myStudy Avg(-10)/ myStudy (-3);

    but this just resulted in all the data plotted by the Test-2 disappearing (even if I didn’t try to plot bbb) until I removed the bbb code

    As a more practical simple example if I could extract the last three values for “myStudy” I could then calculate the moving average generated by “myStudyAvg” and verify that the two ways of calculating matters corresponded

    var xyz = (myStudy (-1)/3+myStudy (-2)/3+myStudy (-3)/3);

    (ie this is just a simple test to see that I have managed to / can pull out the data but there are other things I would like to do with the data once I can extract it)

    I tried to address matters as follows

    var xyz = new Array(myStudy[1], myStudy[2], myStudy[3]);
    or
    var xyz = (myStudy (-1)/3+myStudy (-2)/3+myStudy (-3)/3);
    or
    var xyz1 = (myStudyAvg(-1)/3+myStudyAvg(-2)/3+myStudyAvg(-3)/3);

    The results of my attempts have varied from

    A. all the “TEST-2”plot data disappearing (not the market prices just the study data) if I include var “xyz1” to

    B. there being no data plotted for the two var “xyz” attempts though the other data for “myStudy” and “myStudyAvg” was plotted even though the var “xyz” data didn’t show

    In some earlier attempts at resolving this matter by creating an array I received a message saying no properties or length had been defined or were invalid (ie “Range error invalid array length”) for xyz if the array contained only one item or if it had more than one item nothing was plotted for xyz but the other items in the array were plotted

    Thanks for any help


    Robert

  • #2
    To be honest, I have no earthly idea what you're trying to do but, if you want script A to send data to script B, you can use the setGlobalValue() / getGlobalValue() pair of functions.

    If each script is loaded into the chart, you can guarantee the order in which they execute so that you can place A ahead of B in the chain (the same thread is running sequentially through each script you have loaded in a chart).

    If they're loaded into different charts, then you make script A not have setComputeOnClose() and then script B will have setComputeOnClose(). Then, at worst, your read of data with the getGlobalValue() in script B will be off by a tick or two of data which won't make any difference (i.e. in your ability to make money trading off of that information) in what you're doing.

    Comment


    • #3
      Hi Steve

      Thanks for the reply it was helpful – sorry if I haven’t been clear about what I am trying to do –

      I hope what I set out below is more helpful

      I want to make a calculation of a value from the price data when various random periodic parameters apply –

      by way of simple example this is what “TEST-1” does using average crossovers

      So “TEST-1” generates a value periodically but somewhat randomly (ie not at any predictable fixed time interval)

      This is plotted by my setting out

      return (FlagA);

      I want to fill in the gaps between the last FlagA with a value greater than zero and the next FlagA with a value greater than zero

      – ie this will be effectively a flat line value of the last value calculated greater than zero until it is superseded by the next value* greater than zero

      Lets call this output FlagB

      I then want to calculate an average based on FlagB

      I would also like to calculate an average based on just the values* generated by “TEST-1” / FlagA but given the gaps (zero values) between each value* it was not obvious to me how I would do that

      I concluded that if I extract the values* generated by “TEST-1”/ FlagA greater than zero over some fixed period of time and store them in an Array I should be able to access that Array and calculate an average

      The average number of points over say a 10 unit time period would vary depending on how many periodic / random values* were generated by “TEST-1” and at times no values* may be generated in a specific 10 point period.

      So in some way I need to also count the number of times within my length a value greater than zero is produced and use this to get the average of the sum of the values

      I haven’t really got a good idea how to address this matter and also seemed to be running into problems related to setting an array length and counting and storing the frequencies that a value* greater than zero was calculated so decided to focus on what seemed simpler which was producing that FlagB output

      However I was having problems generating any average of the FlagA output in “TEST-1” so I created “TEST-2” to receive the values* generated by “TEST-1” to see if I could progress matters that way and then come back to filling the data gaps

      What I found was that while “TEST-1” generated periodic / random values* which could also be called into and plotted by “TEST-2” (with gaps) the average generated in “TEST-2” was actually an average based on the closing price even though the sma referred to the value being produced by “TEST-1”

      This seemed strange as I could pull in the values from "Test-1" and plot them in "TEST-2"

      I guess this fits in with your comments on using setComputeOnClose() in “TEST-2” which make sense and I will update that in the code –

      however I have at the moment set all studies by default to setComputeOnClose() but will probably reverse that at some point so I should address this now to avoid problems later.

      I guess also that the setGlobalValue matter comes in here

      Could you explain a little more about using the setGlobalValue() / getGlobalValue() and how this differs from a Gobal Variable ?


      From what I have read “when one EFS computes a Global Value (set/getGlobalValue() functions) and another EFS uses the value. If the EFS computing the Global Value isn't executed first the second EFS will always be behind by one tick

      From what I now understand I will need to set “FlagA” which is the value* calculated by “TEST-1” to be a GlobalValue – and when FlagA is zero in some way make the GlobalValue the last value calculated by FlagA that is greater than zero (ie going back toFlagB)


      To see if I could pull in more data I also tried adding

      var FlagA = null;
      if (FlagA = null) return FlagA = Math.max(FlagA(), FlagA(-1),FlagA(-2),FlagA(-3),FlagA(-3),FlagA(-4),FlagA(-5),FlagA(-6),FlagA(-7),FlagA(-8));

      But nothing plotted except the original value for FlagA - I think that this may have something for do with needing to set the length of time I need to look back over

      As I think you can see I don’t really understand the part a GlobalValue will play or the way to set the length of time to look back over or how to count the number of times that a value was calculated within a given time frame for me to be able to do a more advanced average calculation so any comments on these matters would be helpful

      In the meantime I will keep plugging away

      Thanks

      Robert

      Comment

      Working...
      X