/////////////////////////////////////////////////////// // // SaherElm IT Center Momentum Oscillator // --------------------------------------------- // saherelm implementation of above oscillator ... // // Maintainer: // ------------ // Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com) // ////////////////////////////////////////////////////// // // Global Properties ... #property copyright "Copyright 2023, SaherElm IT Center" #property link "https://saherelm.ir" #property version "1.00" #property description "SaherElm Momentum Oscillator" #property strict // // START Inputs ... // input int length = 7; // Market Length // // END Inputs ... // // // START Global Definitions: Variables, Properties and etc ... // // #property indicator_separate_window // #property indicator_buffers 1 // #property indicator_level1 0.0 #property indicator_level2 100.0 #property indicator_levelcolor clrSilver #property indicator_levelstyle STYLE_DOT // // MOMENTUM ... #property indicator_width1 1 #property indicator_color1 clrLightBlue #property indicator_type1 DRAW_LINE #property indicator_style1 STYLE_SOLID // // Declare Buffers ... #define momentumBufferIndex 0 double momentumBuffer[]; // // END Global Definitions: Variables, Properties and etc ... // // // Start Event Handlers ... // // // Initialization ... int OnInit() { // // Initialize what we want ... // // Validating Input Parameters ... if (length < 0) { return INIT_PARAMETERS_INCORRECT; } // IndicatorBuffers(1); // SetIndexBuffer(momentumBufferIndex, momentumBuffer); SetIndexLabel(momentumBufferIndex, "Momentum"); SetIndexDrawBegin(momentumBufferIndex, length); // // initialization done ... return INIT_SUCCEEDED; } // // Do Calculation ... int OnCalculate( const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[] ) { // // this counts Available Bars ... int limit; // // because in some cases we may have more than one input for // calculation and we must prevent any calculation // untill we pass the biggest input length, here we get max Input length // and then wait until pass it ... int maxLength = MathMax(0, length); // // input variable, we return 0 means nothing passed ... if (rates_total < maxLength) { return 0; } // // found which candles calculated before ... limit = (prev_calculated == 0) ? rates_total - maxLength - 1 : rates_total - prev_calculated + 1; // // this is the main loop of calculations, for each bar index ... for (int i = limit - 1; i >= 0; i--) { // // Start Calculation here ... // i is bar_index ... // // Calculate Long TP ... CalculateBuffers( i, close ); } // return rates_total; } // // END Event Handlers ... // // // START Functions ... // void CalculateBuffers( const int bar_index, const double &close[] ) { // // Calculate Buffers ... double momentum = close[bar_index] * 100 / close[bar_index + length]; // momentumBuffer[bar_index] = momentum; } // // END Functions ... //