Technical indicators

How to use technical indicators and arbitrary custom defined values in Exploration.

Example 8. Exploration: Technical indicators

      // -----------
      // Exploration
      // -----------
    
      // Show me some indicators values when Close is above its 20-days moving average.
        Filter = close > CalcMa( close, 20 ); 
    
        // ... and show me just most recent values.
        // (We are using a daily data so "more recent values" are from yesterday.)
    
        // Use this idiom if you want to use just the last bar.
        ThisIsLastBar = BarIndex() == LastValue( BarIndex() ); 
    
        // Add our "just most recent" condition to the Filter variable.
        Filter = Filter AND ThisIsLastBar;
    
    
        // Define Exploration columns
    
        // Show me *how much* is Close above its average
        AppendColumn( Close - CalcMa( Close, 20 ), "Close Up");
    
        // Show me following technical indicators values:
    
        AppendColumn( CalcMacd(), "MACD", 1.4 );
        AppendColumn( CalcMACDSignal(), "Signal", 1.4 );
        AppendColumn( CalcADX(), "ADX", 1.4 );
        AppendColumn( CalcRSI(), "RSI", 1.4 );
        AppendColumn( CalcROC( Close, 15 ), "ROC(15)", 1.4 );
    
      /*
        Comments
        --------
    
    	1) Recommended, more "ecologiccal" code which does not calculate "CalcMa( Close, 20 )" twice: 
    
           // Calculate and save moving average to the "myMA20" variable 
           myMA20 = CalcMa( close, 20 );
    
           // Use myMA20
           Filter = close > myMA20; 
    
           // Use myMA20
           AppendColumn( Close - myMA20, "Close Up");
        
        
      2) Barindex() is an array of ordinal bars numbers (starting from zero).
           Say we have 5 bars (days) in the database.
           Barindex() is the following array of values:  
           0 1 2 3 4
           
           LastValue( BarIndex() ) is 4
           
           When we compare an array and a number in Seetu, the number is converted to the array too.
           So the expression "BarIndex() == LastValue( BarIndex() )" compares following arrays:
    
           0 1 2 3 4  ... this is the BarIndex() array
           4 4 4 4 4  ... this is the number 4 converted to array
           
           The result is an array:
           0 0 0 0 1  ... just the last item is the same in both arrays 
    
           This array is stored to the ThisIsLastBar variable in our example.
           
           We use the ThisIsLastBar variable to convert all but last values in Filter to FALSE.
           
           Say the Filter variable content is: 
            1 0 1 1 1 
           after the "Filter = close > CalcMa( close, 20 );" command.
           
           The command "Filter = Filter AND ThisIsLastBar" means a logical AND of two arrays then:
           1 0 1 1 1    ... Filter before the command 
           0 0 0 0 1    ... ThisIsLastBar variable content
           0 0 0 0 1    ... the result. Assigned to the Filter variable.
           
           It means the Filter variable holds just the last value of the "close > CalcMa( close, 20 )" condition.
        
      */