Welcome to 4XLab.NET : Forex Lab Community Server Sign in | Join | Faq

Indicators

Started by asimon at 07-25-2006 4:52 PM. Topic has 0 replies.

Print Search
Sort Posts:    
   07-25-2006, 4:52 PM
asimon is not online. Last active: 1/23/2010 8:15:16 PM asimon

Top 10 Posts
Joined on 03-07-2006
Posts 140
Sample Indicator

public class iStub
{
   int tickcount;
   int periods;


   //
   // declare basic indicators here
   //


   public iStub(int pPeriods)
   {
      periods = pPeriods;
      tickcount = 0;
      // instantiate any basic indicators here
   }


   public void ReceiveTick(double Val)
   {
      tickcount++;
      if (tickcount == (3*periods))
      {
         tickcount = (2*periods);
// avoid overflow (large->0) when indicator is primed
      }
      // perform indicator calculations here or send ticks to other indicators
   }


   public double Value()
   {
      double v=0;
      // compute indicator value here (note that this function might get called multiple times
      // so do not set flags or do time specific behavior
      if (isPrimed())
      {
         // perform computation of output value
         v = 1;
      }
      return v;
   }


   // returns true when indicator has seen enough values to compute a result
   // it will never return true if initialization parameters are incorrect
   // this will cause indicator to silently fail and not give results
   // on optimization runs where parameter combination is invalid.
   public bool isPrimed()
   { 
      bool v = false;
      // change this to the appropriate criteria
      if ((tickcount >= periods) && (periods>0))
      {
         v =
true;
      }
      return v;
   }


}


   Report 
4XLab.NET : For... » 4XLab.NET » Indicators » Sample Indicator

Powered by Community Server, by Telligent Systems