Use Case 1

Goal

A user wants to implement a new technical analysis indicator defined as follow:
  For each price bar
    if( today open > yesterday close )
       newIndicator = (today open + yesterday close)/2;
    else
       newIndicator = yesterday newIndicator;
The output of the new indicator is expected to start only at the first occurrence of today's open being greater than yesterday's close.

Solution

Define the new indicator in C#:

class MyIndicator : FunctionBase
{
   Input  open, close;
   Output result;

   public override void Pre()
   {
      // Map to the time series variable names.
      open   = MapTo( "Open" );
      close  = MapTo( "Close" );
      result = MapTo( "TheOutputName" );
   }

   public override void Iter()
   {
      if( open > close.Prev )
         result.Data = (open + close.Prev)/2.0;
      else
         result.Data = result.Prev;
   }
}

Example of usage of the new indicator in C#:

// Get Microsoft market data.
Timeseries ts1 = db.get("US.NASDAQ.STOCK", "MSFT");

// Use ts1 as input and ts2 will refer to the output.
MyIndicator indicator = new MyIndicator();
Timeseries ts2 = indicator.Exec(ts1);

// Display the output.
for( int i=0; i < ts2.Length; i++ )
{
   Console.WriteLine( ts2["TheOutputName"][i] );
}
 

WARNING: Work in progress.