Announcement

Collapse
No announcement yet.

Data Transfer

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

  • Data Transfer

    Is it possible to transfer a single variable ( such as x=1 ) between two efs files when they are of different time frames? File A is a tick chart and file B is a minute chart. Are there examples of this available?

    Best regards,

    Alan

  • #2
    Hello Alan,

    You could use the Data Storage Functions, setGlobalValue(), getGlobalValue() and removeGlobalValue() to pass data between formulas.
    Jason K.
    Project Manager
    eSignal - an Interactive Data company

    EFS KnowledgeBase
    JavaScript for EFS Video Series
    EFS Beginner Tutorial Series
    EFS Glossary
    Custom EFS Development Policy

    New User Orientation

    Comment


    • #3
      Code Problems

      Jason,

      Thank you for the suggestion. I applied this to an existing efs to try and get it up and running. The attache code is for a 31 period tick ecma (vreturn), a constant line at 10808 (xsx), and a logic variance ( MB83). It executes in the first file with out errors but the data does not get to the second file. Your comments on the code to correct it would be greatly appreciated.

      Both files are the same except for the ending section for reading and writing the global variables.

      Best regards,

      Alan


      This file passes MB83 out as a global variable.

      START
      PHP Code:
      var vMA1 null;
      var 
      vCntr 0;
      var 
      xsx 0;
      var 
      MB83 0;
      var 
      vValue getGlobalValue"punt" );



      function 
      preMain() {

          
      setPriceStudy(true);
          
      setStudyTitle("PassOut");
          
      setCursorLabelName("MA"0);
          
      setDefaultBarStyle(PS_SOLID0);
          
      setDefaultBarFgColor(Color.red0);
          
      setDefaultBarThickness(30);
          
      setPlotType(PLOTTYPE_LINE0);
          
      setGlobalValue ("punt",0);
          
      setComputeOnClose(true);
             
          
          var 
      fp1 = new FunctionParameter("MA1Length"FunctionParameter.NUMBER);
          
      fp1.setLowerLimit(1);        
          
      fp1.setDefault(31); //Edit this value to set a new default
          
          
      var fp2 = new FunctionParameter("MA1Offset"FunctionParameter.NUMBER);
          
      fp2.setDefault(0); //Edit this value to set a new default
          
          
      var fp3 = new FunctionParameter("MA1Source"FunctionParameter.STRING);
          
      fp3.setName("MA1Source");
          
      fp3.addOption("Close");
          
      fp3.addOption("High");
          
      fp3.addOption("Low");
          
      fp3.addOption("Open");
          
      fp3.addOption("HL/2");
          
      fp3.addOption("HLC/3");
          
      fp3.addOption("OHLC/4");
          
      fp3.setDefault("Close"); //Edit this value to set a new default     
          
          
      var fp4 = new FunctionParameter("MA1Type"FunctionParameter.STRING);
          
      fp4.setName("MA1Type");
          
      fp4.addOption("MAStudy.SIMPLE");
          
      fp4.addOption("MAStudy.EXPONENTIAL");
          
      fp4.addOption("MAStudy.WEIGHTED");
          
      fp4.addOption("MAStudy.VOLUMEWEIGHTED");
          
      fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
          
          
      var fp5 = new FunctionParameter("Centered"FunctionParameter.STRING);
          
      fp5.addOption("Yes");
          
      fp5.addOption("No");
          
      fp5.setDefault("No");
          
      }

      function 
      main(MA1Length,MA1Offset,MA1Source,MA1Type,Centered) {

          if(
      getBarState()==BARSTATE_NEWBAR){
          
      vCntr +=1;
          }
          if(
      vCntr<MA1Length*2)
          return;
          
          if(
      Centered=="Yes"){    
          var 
      MA1Offset Math.ceil(MA1Length/2)*(-1);
          }

          if (
      vMA1 == nullvMA1 = new MAStudy(MA1LengthMA1OffsetMA1Source, eval(MA1Type));
          
       
              
      /******************************************
      Insert your code following this text block 
      Use vMA1.getValue(MAStudy.MA) for your code
      *******************************************/
          
          
      if(getBarState() == BARSTATE_NEWBAR){
              var 
      nNum 1;
          }else{
              var 
      nNum 0;
          }
          
          var 
      vReturn vMA1.getValue(MAStudy.MA,MA1Offset);
          if (
      vReturn == null) return;

          if(
      MA1Offset<0){
              if(
      getBuildNumber() > 636){
                  
      setBar(Bar.Value,MA1Offset+nNum,0,vReturn);
                  
      vReturn=null;
              }else{
                  
      setBar(Bar.Value,MA1Offset+nNum,vMA1.getValue(MAStudy.MA,MA1Offset));
                  
      vReturn=null;
              }
          }
          
        
      xsx 10804
        
       if(
      vReturn >= xsx) {
                  
      MB83 = ( xsx 4);
              } else if(
      vReturn xsx) {
                  
      MB83 = ( xsx -);
          }
       
       
      vValue MB83;


      if (
      vValue != null) {

       
      setGlobalValue"punt"vValue );



      else {

       
      setGlobalValue"punt"MB83 );

      }


      return new Array ( 
      vReturnxsxMB83 );
         

      END

      This file reads in the global variable

      START
      PHP Code:
      var vMA1 null;
      var 
      vCntr 0;
      var 
      xsx 0;
      var 
      MB83 0;
      var 
      vValue getGlobalValue"punt" );



      function 
      preMain() {

          
      setPriceStudy(true);
          
      setStudyTitle("PassIn");
          
      setCursorLabelName("MA"0);
          
      setDefaultBarStyle(PS_SOLID0);
          
      setDefaultBarFgColor(Color.red0);
          
      setDefaultBarThickness(30);
          
      setPlotType(PLOTTYPE_LINE0);
          
      setGlobalValue ("punt",0);
          
      setComputeOnClose(true);
             
          
          var 
      fp1 = new FunctionParameter("MA1Length"FunctionParameter.NUMBER);
          
      fp1.setLowerLimit(1);        
          
      fp1.setDefault(31); //Edit this value to set a new default
          
          
      var fp2 = new FunctionParameter("MA1Offset"FunctionParameter.NUMBER);
          
      fp2.setDefault(0); //Edit this value to set a new default
          
          
      var fp3 = new FunctionParameter("MA1Source"FunctionParameter.STRING);
          
      fp3.setName("MA1Source");
          
      fp3.addOption("Close");
          
      fp3.addOption("High");
          
      fp3.addOption("Low");
          
      fp3.addOption("Open");
          
      fp3.addOption("HL/2");
          
      fp3.addOption("HLC/3");
          
      fp3.addOption("OHLC/4");
          
      fp3.setDefault("Close"); //Edit this value to set a new default     
          
          
      var fp4 = new FunctionParameter("MA1Type"FunctionParameter.STRING);
          
      fp4.setName("MA1Type");
          
      fp4.addOption("MAStudy.SIMPLE");
          
      fp4.addOption("MAStudy.EXPONENTIAL");
          
      fp4.addOption("MAStudy.WEIGHTED");
          
      fp4.addOption("MAStudy.VOLUMEWEIGHTED");
          
      fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default
          
          
      var fp5 = new FunctionParameter("Centered"FunctionParameter.STRING);
          
      fp5.addOption("Yes");
          
      fp5.addOption("No");
          
      fp5.setDefault("No");
          
      }

      function 
      main(MA1Length,MA1Offset,MA1Source,MA1Type,Centered) {

          if(
      getBarState()==BARSTATE_NEWBAR){
          
      vCntr +=1;
          }
          if(
      vCntr<MA1Length*2)
          return;
          
          if(
      Centered=="Yes"){    
          var 
      MA1Offset Math.ceil(MA1Length/2)*(-1);
          }

          if (
      vMA1 == nullvMA1 = new MAStudy(MA1LengthMA1OffsetMA1Source, eval(MA1Type));
          
       
              
      /******************************************
      Insert your code following this text block 
      Use vMA1.getValue(MAStudy.MA) for your code
      *******************************************/
          
          
      if(getBarState() == BARSTATE_NEWBAR){
              var 
      nNum 1;
          }else{
              var 
      nNum 0;
          }
          
          var 
      vReturn vMA1.getValue(MAStudy.MA,MA1Offset);
          if (
      vReturn == null) return;

          if(
      MA1Offset<0){
              if(
      getBuildNumber() > 636){
                  
      setBar(Bar.Value,MA1Offset+nNum,0,vReturn);
                  
      vReturn=null;
              }else{
                  
      setBar(Bar.Value,MA1Offset+nNum,vMA1.getValue(MAStudy.MA,MA1Offset));
                  
      vReturn=null;
              }
          }
          
       
       
       


      if (
      vValue != null) {

       
      setGlobalValue"punt"vValue );



      else {

       
      setGlobalValue"punt"vValue );

      }


      return new Array ( 
      vReturnxsxvValue );
         

      END

      Comment


      • #4
        Hello Alan,

        The passin formula needs to do a getGlobalValue("punt") inside main, not in the global scope. Also, you have a setGlobalValue() in the passin formula for the same "punt" variable. That will create some logic conflicts as the passin study will overwrite the value from the passout study. I would suggest removing the setGlobalValue() routine from the passin study and replace it with a getGlobalValue() routine.
        Jason K.
        Project Manager
        eSignal - an Interactive Data company

        EFS KnowledgeBase
        JavaScript for EFS Video Series
        EFS Beginner Tutorial Series
        EFS Glossary
        Custom EFS Development Policy

        New User Orientation

        Comment


        • #5
          Global Data Transfer

          Jason,

          Thank you for the suggestions. I changed nothing in the PassOut efs. In the PassIn efs I moved the "get" command from the variable deffinitions section to the main section. Also I changed the "set" to "get" commands in the routine at the bottom of the PassIn efs. I must be missing the forest or the trees because I still can not get it to work. I do not get any error messages. There is just no transferred data plotted in the PassIn chart. Your help is greatly appreciated.

          Best Regards,

          Alan


          PassOut efs - no changes.

          var vMA1 = null;
          var vCntr = 0;
          var xsx = 0;
          var MB83 = 0;
          var vValue = getGlobalValue( "punt" );



          function preMain() {

          setPriceStudy(true);
          setStudyTitle("PassOut");
          setCursorLabelName("MA", 0);
          setDefaultBarStyle(PS_SOLID, 0);
          setDefaultBarFgColor(Color.red, 0);
          setDefaultBarThickness(3, 0);
          setPlotType(PLOTTYPE_LINE, 0);
          setGlobalValue ("punt",0);
          setComputeOnClose(true);


          var fp1 = new FunctionParameter("MA1Length", FunctionParameter.NUMBER);
          fp1.setLowerLimit(1);
          fp1.setDefault(31); //Edit this value to set a new default

          var fp2 = new FunctionParameter("MA1Offset", FunctionParameter.NUMBER);
          fp2.setDefault(0); //Edit this value to set a new default

          var fp3 = new FunctionParameter("MA1Source", FunctionParameter.STRING);
          fp3.setName("MA1Source");
          fp3.addOption("Close");
          fp3.addOption("High");
          fp3.addOption("Low");
          fp3.addOption("Open");
          fp3.addOption("HL/2");
          fp3.addOption("HLC/3");
          fp3.addOption("OHLC/4");
          fp3.setDefault("Close"); //Edit this value to set a new default

          var fp4 = new FunctionParameter("MA1Type", FunctionParameter.STRING);
          fp4.setName("MA1Type");
          fp4.addOption("MAStudy.SIMPLE");
          fp4.addOption("MAStudy.EXPONENTIAL");
          fp4.addOption("MAStudy.WEIGHTED");
          fp4.addOption("MAStudy.VOLUMEWEIGHTED");
          fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default

          var fp5 = new FunctionParameter("Centered", FunctionParameter.STRING);
          fp5.addOption("Yes");
          fp5.addOption("No");
          fp5.setDefault("No");

          }

          function main(MA1Length,MA1Offset,MA1Source,MA1Type,Centere d) {

          if(getBarState()==BARSTATE_NEWBAR){
          vCntr +=1;
          }
          if(vCntr<MA1Length*2)
          return;

          if(Centered=="Yes"){
          var MA1Offset = Math.ceil(MA1Length/2)*(-1);
          }

          if (vMA1 == null) vMA1 = new MAStudy(MA1Length, MA1Offset, MA1Source, eval(MA1Type));



          /******************************************
          Insert your code following this text block
          Use vMA1.getValue(MAStudy.MA) for your code
          *******************************************/

          if(getBarState() == BARSTATE_NEWBAR){
          var nNum = 1;
          }else{
          var nNum = 0;
          }

          var vReturn = vMA1.getValue(MAStudy.MA,MA1Offset);
          if (vReturn == null) return;

          if(MA1Offset<0){
          if(getBuildNumber() > 636){
          setBar(Bar.Value,MA1Offset+nNum,0,vReturn);
          vReturn=null;
          }else{
          setBar(Bar.Value,MA1Offset+nNum,vMA1.getValue(MASt udy.MA,MA1Offset));
          vReturn=null;
          }
          }

          xsx = 10798;

          if(vReturn >= xsx) {
          MB83 = ( xsx + 4);
          } else if(vReturn < xsx) {
          MB83 = ( xsx -4 );
          }

          vValue = xsx;


          if (vValue != null) {

          setGlobalValue( "punt", vValue + 1 );

          }

          else {

          setGlobalValue( "punt", vValue );

          }


          return new Array ( MB83, vReturn, xsx );

          }




          PassIn efs includes the changes.

          var vMA1 = null;
          var vCntr = 0;
          var xsx = 0;
          var MB83 = 0;




          function preMain() {

          setPriceStudy(true);
          setStudyTitle("PassIn");
          setCursorLabelName("MA", 0);
          setDefaultBarStyle(PS_SOLID, 0);
          setDefaultBarFgColor(Color.red, 0);
          setDefaultBarThickness(3, 0);
          setPlotType(PLOTTYPE_LINE, 0);
          setGlobalValue ("punt",0);
          setComputeOnClose(true);


          var fp1 = new FunctionParameter("MA1Length", FunctionParameter.NUMBER);
          fp1.setLowerLimit(1);
          fp1.setDefault(31); //Edit this value to set a new default

          var fp2 = new FunctionParameter("MA1Offset", FunctionParameter.NUMBER);
          fp2.setDefault(0); //Edit this value to set a new default

          var fp3 = new FunctionParameter("MA1Source", FunctionParameter.STRING);
          fp3.setName("MA1Source");
          fp3.addOption("Close");
          fp3.addOption("High");
          fp3.addOption("Low");
          fp3.addOption("Open");
          fp3.addOption("HL/2");
          fp3.addOption("HLC/3");
          fp3.addOption("OHLC/4");
          fp3.setDefault("Close"); //Edit this value to set a new default

          var fp4 = new FunctionParameter("MA1Type", FunctionParameter.STRING);
          fp4.setName("MA1Type");
          fp4.addOption("MAStudy.SIMPLE");
          fp4.addOption("MAStudy.EXPONENTIAL");
          fp4.addOption("MAStudy.WEIGHTED");
          fp4.addOption("MAStudy.VOLUMEWEIGHTED");
          fp4.setDefault("MAStudy.SIMPLE"); //Edit this value to set a new default

          var fp5 = new FunctionParameter("Centered", FunctionParameter.STRING);
          fp5.addOption("Yes");
          fp5.addOption("No");
          fp5.setDefault("No");

          }

          function main(MA1Length,MA1Offset,MA1Source,MA1Type,Centere d) {

          if(getBarState()==BARSTATE_NEWBAR){
          vCntr +=1;
          }
          if(vCntr<MA1Length*2)
          return;

          if(Centered=="Yes"){
          var MA1Offset = Math.ceil(MA1Length/2)*(-1);
          }

          if (vMA1 == null) vMA1 = new MAStudy(MA1Length, MA1Offset, MA1Source, eval(MA1Type));

          vValue = getGlobalValue( "punt" );


          /******************************************
          Insert your code following this text block
          Use vMA1.getValue(MAStudy.MA) for your code
          *******************************************/

          if(getBarState() == BARSTATE_NEWBAR){
          var nNum = 1;
          }else{
          var nNum = 0;
          }

          var vReturn = vMA1.getValue(MAStudy.MA,MA1Offset);
          if (vReturn == null) return;

          if(MA1Offset<0){
          if(getBuildNumber() > 636){
          setBar(Bar.Value,MA1Offset+nNum,0,vReturn);
          vReturn=null;
          }else{
          setBar(Bar.Value,MA1Offset+nNum,vMA1.getValue(MASt udy.MA,MA1Offset));
          vReturn=null;
          }
          }






          if (vValue != null) {

          getGlobalValue( "punt", vValue + 2 );

          }

          else {

          getGlobalValue( "punt", vValue );

          }


          return vValue;

          }

          Comment


          • #6
            Hello Alan,

            You need to pass the result of getGlobalValue() to a variable and then return that to your chart.

            myVar = getGlobalValue("punt")

            However, this method is only useful for passing information between two formula in real time. This will allow you to "collect" and display information going forward but it cannot be used to plot a history after the initial loading of the formulas. This is because the formulas do not load in a synchronous manner based on bar time stamps during the initialization process. Creating multiple time frame studies to plot a history on load is not a very easy task currently. We will have some new functionality in the next version that will help make this type of study easier to develop, which is due out in a couple of months. If you need something developed before then, please contact one of our EFS Consultants.
            Jason K.
            Project Manager
            eSignal - an Interactive Data company

            EFS KnowledgeBase
            JavaScript for EFS Video Series
            EFS Beginner Tutorial Series
            EFS Glossary
            Custom EFS Development Policy

            New User Orientation

            Comment


            • #7
              Global Data Transfer

              Jason,

              I have simplified the efs files to allow better clarity. The passout file plots varialbe vValue on the chart at 10830 and passes this out as a global variable.

              Passin reads in vValue as a global variable adds 10700 to the read value and plots 10700 on the chart. This implies it is reading in 0 for the global variable.

              This variable will be used as an if/then logic device in the passin file and will not be plotted on the chart. Only the last passed in value will be used. Am I correct that if a 10 minute efs file calculates a value, this will be read into a 1 minute efs file every 1 minute?

              Please advise how to correct the files to allow the data to transfer properly. Your help is greatly apprecited.

              Best regards,

              Alan

              /************************************************** *******
              Pass a single variable out
              ************************************************** ********/

              var vMA1 = null;
              var vCntr = 0;
              var xsx = 0;
              var MB83 = 0;
              var vValue = getGlobalValue( "punt" );



              function preMain() {

              setPriceStudy(true);
              setStudyTitle("PassOut11g");
              setCursorLabelName("MA", 0);
              setDefaultBarStyle(PS_SOLID, 0);
              setDefaultBarFgColor(Color.red, 0);
              setDefaultBarThickness(3, 0);
              setPlotType(PLOTTYPE_LINE, 0);
              setGlobalValue ("punt",0);
              setComputeOnClose(true);



              }

              function main(MA1Length,MA1Offset,MA1Source,MA1Type,Centere d) {





              /******************************************
              Insert code
              *******************************************/

              xsx = 10830;

              vValue = xsx;


              return xsx;

              }

              if (vValue != null) {

              getGlobalValue( "punt", vValue + 2 );

              }

              else {

              getGlobalValue( "punt", vValue );

              }



              /************************************************** *******
              Pass in a single variable in
              ************************************************** ********/

              var vMA1 = null;
              var vCntr = 0;
              var xsx = 0;
              var MB83 = 0;
              var vValue = 0;


              function preMain() {

              setPriceStudy(true);
              setStudyTitle("PassIn11d");
              setCursorLabelName("MA", 0);
              setDefaultBarStyle(PS_SOLID, 0);
              setDefaultBarFgColor(Color.red, 0);
              setDefaultBarThickness(3, 0);
              setPlotType(PLOTTYPE_LINE, 0);
              setGlobalValue ("punt",0);
              setComputeOnClose(true);




              }

              function main(MA1Length,MA1Offset,MA1Source,MA1Type,Centere d) {



              vValue = getGlobalValue( "punt" );

              MB83 = vValue +10700


              /******************************************
              Insert code
              *******************************************/





              return MB83;

              }

              Comment


              • #8
                Alan
                You are using getGlobalValue() in both efs. The "passout" efs must be setGlobalValue()
                Below are two sample efs(s) one to set the value and the other to retrieve it.
                Alex

                PHP Code:
                function preMain(){
                    
                setStudyTitle("setValue");
                }

                function 
                main(){

                var 
                1080.50

                if(x!=null)
                setGlobalValue("test",x);

                return 
                x;

                PHP Code:
                function preMain(){
                    
                setStudyTitle("getValue");
                }

                function 
                main(){

                var 
                getGlobalValue("test");

                return 
                x;

                Comment


                • #9
                  Data Transfer

                  Alex,

                  You have been most kind to respond and your suggestion solved the problem. The transfer works great. Thank you for the help and have a great day ! ! !

                  Best Regards,

                  Alan

                  Comment

                  Working...
                  X