C#:
| ... public DateTime CheckForLatestBuySignal() { // Get intraday 1 minute data for the security to be traded. Timeseries data_1min = ...; // Get intraday 1 minute Dow Jones data. Timeseries dj_1min = ...; // Create a dow jones time series with 3 minutes price bars. Timeseries dj_3min = dj_1min.ConvertBarPeriod( Per3Min ); // Do the calculation... data_1min["Rsi"] = dj_3min.Rsi(5); Variable a = data_1min.Sma(3); Variable b = data_1min.Sma(8); data_1min["CrossAbove"] = a.CrossAbove( b ); // Take note that the RSI is automatically expanded and // synchronized when added to data_1min. // Find the latest buy signal, starting from the end // of the timeseries. for( int i=data_1min.Length-1; i >= 0 ; i-- ) { if( (data_1min["Rsi"][i] > 70) && (data_1min["CrossAbove"][i] == 1) ) { return data_1min.Timestamps[i]; } } return null; // No buy signal trig yet. } |
WARNING: Work in progress.