Announcement

Collapse
No announcement yet.

Smoothing an indicator in real time?

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

  • Smoothing an indicator in real time?

    I have some custom buy and sell indicators in my ATS that can change values in a range in real time that can cause many buys and sells in a short time when the trade first starts.

    Any ideas on the best way to smooth them out?

    I thought I could do something like a moving average of the last X trades using a series with efsInternal. I see esignal has moving average functions sma, ema, wma, and vwma. I'm not sure which to use or how to code it.

    Thanks for any help and ideas

  • #2
    Hello windswepttom,

    If the indicator your buy/sell conditions are based on is in the form of a series, then you can pass it as the source to one of the moving average functions. The key is that the source must be a series object. If you're not sure, try passing the variable name that you want to use as the source to debugPrintln(). If it is a series, you will see [object series] printed to the formula output window.

    If you post your code, I or someone may be able to provide more specific suggestions.
    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
      My indicators are not in a series but I was thinking I could make a series using efsInternal some how. The actual code for x and y is to long and complex but some dummy code goes something like this:
      function preMain() {
      var x=0;
      var y=0;
      var inaTrade = false;
      function main() {
      X = (open() + 2)/2;
      Y = (close() - 3)/2;
      if (((y - x) > 1) && !inaTrade)
      buy();
      if (((y - x) < 0.75) && inaTrade)
      sell();
      return; }
      function buy() {
      inaTrade = true;
      return; }
      function sell() {
      inaTrade = false;
      return; }

      So I need to smooth out x and y over the past few trades.

      Comment


      • #4
        Hello windswepttom,

        Here's the basics of how to convert a custom calculation into a series with efsInternal(). You should change the function names of your custom buy() and sell() functions as those conflict with the existing generic broker functions.

        PHP Code:
        // global vars for Series Objects
        var xSeries null;
        var 
        ySeries null;

        function 
        main() {
            
        // initialize Series objects, occurs only once.
            
        if (xSeries == nullefsInternal("calcX");
            if (
        ySeries == nullefsInternal("calcY");
            
            
        // assign current value of Series to local vars for conditions
            
        var xSeries.getValue(0);
            var 
        ySeries.getValue(0);
            if (
        == null || == null) return;  // validate local vars

            
        if (((x) > 1) && !inaTradebuyFunction();
            
            if (((
        x) < 0.75) && inaTradesellFunction();

            return; 
        }

        function 
        calcX() {
            return (
        open(0) + 2)/2;
        }

        function 
        calcY() {
            return (
        close(0) - 3)/2;

        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
          Next, to add the smoothing of the xSeries and ySeries you would do the following.

          PHP Code:
          // global vars for Series Objects
          var xSeries null;
          var 
          ySeries null;
          var 
          xMAofX null;
          var 
          xMAofY null;

          var 
          bInit false;  // initialization flag

          function main() {
              
          // initialize Series objects, occurs only once.
              
          if (bInit == false) {
                  
          xSeries efsInternal("calcX");
                  
          ySeries efsInternal("calcY");
                  
          xMAofX sma(3xSeries);
                  
          xMAofY sma(3ySeries);
                  
          bInit true;
              }
              
              
          // assign current value of Series to local vars for conditions
              
          var xMAofX.getValue(0);
              var 
          xMAofY.getValue(0);
              if (
          == null || == null) return;  // validate local vars


              
          if (((x) > 1) && !inaTradebuyFunction();
              
              if (((
          x) < 0.75) && inaTradesellFunction();

              return; 
          }

          function 
          calcX() {
              return (
          open(0) + 2)/2;
          }

          function 
          calcY() {
              return (
          close(0) - 3)/2;

          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


          • #6
            Thank You Jason very much!
            I like the way you did it in two parts, it makes it much easer to understand.

            Comment


            • #7
              You're most welcome.
              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

              Working...
              X