Announcement

Collapse
No announcement yet.

how do i turn a simple calualtion into a series to pass to a builtin study

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

  • how do i turn a simple calualtion into a series to pass to a builtin study

    I am trying to turn the value of a calculation into a series object so i can run it through a built in study like a sma.

    Im not sure i got this right but going from examples i could use efsInternal () to do this or so i thought.

    lets say i have my calculation that is different every bar in var value when i use efsInternal in this capacity esignal hangs and runs to 100% cpu. Eventually it returns.

    Can efsInternal be used to create a series of ever changing values?

    Or is something bizare hapening here like its creating a new series for every value i pass in via value?

    PHP Code:
    var vSMA;

    function 
    main(){
    var 
    value 0;
     
      
    value = <some calc>

       
    vSMA sma6efsInternal"makeValueSeries"value ) );

      return 
    vSMA.getValue(0);
    }

    function 
    makeValueSeriessomevalue) {
       return( 
    somevalue);

    I have this working using efsExternal but id rather have it woring as a single encapsulated efs.

  • #2
    theperm
    The reason why you are pegging the cpu is because you are creating a new series object for each unique value that you are passing to efsInternal() or efsExternal()
    You need to run your calculation in a separate function or efs and then call that from main using efsInternal() or efsExternal(). That will create the series that you can then pass to the sma() (or any other) function (see the basic example enclosed below).
    You can find several examples on how to use efsInternal() and efsExternal() in this and this thread..
    Alex

    PHP Code:
    function myCalc(){
        var 
    myValue = <some calc>
        return 
    myValue;
    }
     
    function 
    main(){
        var 
    mySeries efsInternal("myCalc");
        var 
    mySMA sma(lengthmySeries);
        
    //alternatively var mySMA = sma(length, efsInternal("myCalc"));
        
    return mySMA.getValue(0)

    Comment


    • #3
      I can see my mistake and can fix it.

      Funny thing is i cant get myCalc to read a global variable.

      It gets set on the first call of main but when refering to it in myCalc it is always 0. Whats going on there?

      Comment


      • #4
        theperm

        It gets set on the first call of main but when refering to it in myCalc it is always 0. Whats going on there?
        This is because each function called by efsInternal() (or efs called by efsExternal()) gets a unique instance of all global variables. Hence, you need to assign the values for those variables within the called function (or efs) or pass them to the function (or efs) as parameters of efsInternal() (or efsExternal()).
        Alex.

        Comment

        Working...
        X