/////////////////////////////////////////////////////// // // SaherElm IT Center ADX 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 ADX Oscillator" #property strict // // START Inputs ... // input int length = 7; // Averaging Length // // END Inputs ... // // // START Global Definitions: Variables, Properties and etc ... // // #property indicator_chart_window // // #property indicator_buffers 3 // // Declare Buffers ... // datetime startTime; double lHigh; double lLow; // datetime highTimes[]; // datetime lowTimes[]; // // 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; } // // 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); } // return rates_total; } // // END Event Handlers ... // // // START Functions ... // void CalculateBuffers( const int bar_index ) { // // Calculate Buffers ... // int startBarIndex = iBarShift( _Symbol, _Period, startTime ); // datetime barTime = iTime( _Symbol, _Period, bar_index ); // if (startTime == 0) { // startTime = barTime; return; } // if ( startTime > 0 && startBarIndex - bar_index == length ) { // int hhIdx = iHighest( _Symbol, _Period, MODE_HIGH, length, bar_index ); datetime hhTime = iTime( _Symbol, _Period, hhIdx ); double hh = iHigh( _Symbol, _Period, hhIdx ); // int hhSize = ArraySize(highTimes); datetime tempTimes[]; ArrayResize( tempTimes, hhSize ); ArrayCopy( tempTimes, highTimes ); ArrayResize( highTimes, hhSize + 1 ); highTimes[0] = hhTime; ArrayCopy( highTimes, tempTimes, 1 ); // int llIdx = iLowest( _Symbol, _Period, MODE_LOW, length, bar_index ); datetime llTime = iTime( _Symbol, _Period, llIdx ); double ll = iLow( _Symbol, _Period, llIdx ); // int llSize = ArraySize(lowTimes); ArrayFree(tempTimes); ArrayResize( tempTimes, llSize ); ArrayCopy( tempTimes, lowTimes ); ArrayResize( lowTimes, llSize + 1 ); lowTimes[0] = llTime; ArrayCopy( lowTimes, tempTimes, 1 ); // startTime = 0; ArrayFree(tempTimes); } } // // END Functions ... //