/////////////////////////////////////////////////////// // // SaherElm IT Center Trend Power Indicator // --------------------------------------------- // saherelm implementation of above indicator ... // this indicator uses two ma line: // - fast ma; // - slow ma; // // 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 MA Indicator" #property strict // // START Inputs ... // input int marketLength = 7; // Market Length // // END Inputs ... // // // START Global Definitions: Variables, Properties and etc ... // #property indicator_separate_window // #property indicator_plots 3 #property indicator_buffers 3 #property indicator_minimum 0 #property indicator_maximum 100 // #property indicator_levelcolor clrGray #property indicator_levelstyle STYLE_DOT // // Start Define Indicator Buffer Styles ... // #property indicator_type1 DRAW_HISTOGRAM #property indicator_color1 clrLime #property indicator_style1 STYLE_DOT #property indicator_width1 1 // #property indicator_type2 DRAW_HISTOGRAM #property indicator_color2 clrRed #property indicator_style2 STYLE_DOT #property indicator_width2 1 // #property indicator_type3 DRAW_LINE #property indicator_color3 clrYellow #property indicator_style3 STYLE_DOT #property indicator_width3 1 // // End Define Indicator Buffer Styles ... // // // Buffers ... #define powerUpBufferIndex 0 #define powerDownBufferIndex 1 #define signalBufferIndex 2 double powerUpBuffer[]; double powerDownBuffer[]; double signalBuffer[]; // #include "../Libraries/x-saherelm.lib.mq4" // // END Global Definitions: Variables, Properties and etc ... // // // Start Event Handlers ... // // // Initialization ... int OnInit() { // // Initialize what we want ... if (marketLength <= 0) { return INIT_PARAMETERS_INCORRECT; } // SetLevelValue(0, 0.0); IndicatorSetString(INDICATOR_LEVELTEXT,0,""); // SetLevelValue(1, 20.0); IndicatorSetString(INDICATOR_LEVELTEXT,1,""); // SetLevelValue(2, 50); IndicatorSetString(INDICATOR_LEVELTEXT,2,""); // SetLevelValue(3, 100); IndicatorSetString(INDICATOR_LEVELTEXT,3,""); // string pUpLbl = StringConcatenate( "P Up (", marketLength, ")" ); SetIndexLabel(powerUpBufferIndex, pUpLbl); SetIndexBuffer(powerUpBufferIndex, powerUpBuffer); SetIndexDrawBegin(powerUpBufferIndex, marketLength + 1); // string pDownLbl = StringConcatenate( "P Down (", marketLength, ")" ); SetIndexLabel(powerDownBufferIndex, pDownLbl); SetIndexBuffer(powerDownBufferIndex, powerDownBuffer); SetIndexDrawBegin(powerDownBufferIndex, marketLength + 1); // string pSignalLbl = StringConcatenate( "P Signal (", marketLength, ")" ); SetIndexLabel(signalBufferIndex, pSignalLbl); SetIndexBuffer(signalBufferIndex, signalBuffer); SetIndexDrawBegin(signalBufferIndex, marketLength + 1); // // here we specify logging enabled or not ... enableLogging = true; // // this is a Tag which attached to our Logger ... logTag = "X_TPW_OSC"; // return INIT_SUCCEEDED; } // // Calculating what we want ... 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, marketLength); // // 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 Buffers ... CalculateBuffers(i); } // return rates_total; } // // END Event Handlers ... // // // START Functions ... // // // Calculating Ma ... void CalculateBuffers( const int &bar_index ) { // double powerUp = 0; double powerDown = 0; // int dailyCount = GetDailyCandleCount(); double dailyHH = GetMarketHighestHigh( bar_index, dailyCount ); double dailyLL = GetMarketLowestLow( bar_index, dailyCount ); double dailyDiff = dailyHH - dailyLL; double rate = dailyDiff / 100; // for (int i = bar_index; i < bar_index + marketLength; i++) { // XOHCL c = GetCandleModel(i); // double cRange = MathAbs(c.open - c.close) // MathAbs(c.high - c.low) ; bool isBullish = c.open < c.close; // if (isBullish) { powerUp += cRange; } else { powerDown += cRange; } } // powerUp = powerUp / rate; powerDown = powerDown / rate; // int doubleMarketLength = (marketLength * 2); double ema = GetMA( bar_index, doubleMarketLength, 0, MODE_EMA, PRICE_WEIGHTED ); // double emaRate = GetMarketHighestHigh(bar_index, doubleMarketLength) - GetMarketLowestLow(bar_index, doubleMarketLength) / 100; // double signal = (ema / 100) * rate; double signalAddition = MathMin(powerUp, powerDown); // powerUpBuffer[bar_index] = powerUp; powerDownBuffer[bar_index] = powerDown; signalBuffer[bar_index] = signal + signalAddition; } // // END Functions ... //