/////////////////////////////////////////////////////// // // SaherElm IT Center XMKT Indicator // --------------------------------------------- // retrieve market base info ... // // 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 XMKT Indicator" #property strict // // START Inputs ... // // // Market Specifications ... input int marketLength = 7; // Market Length // input bool showHighestHigh = true; // Show Market Highest High input bool showHighestLow = true; // Show Market Highest Low input bool showHighestOpen = true; // Show Market Highest Open input bool showHighestClose = true; // Show Market Highest Close input bool showLowestHigh = true; // Show Market Lowest High input bool showLowestLow = true; // Show Market Lowest Low input bool showLowestOpen = true; // Show Market Lowest Open input bool showLowestClose = true; // Show Market Lowest Close // input color highestHighColor = clrDeepPink; // Market Highest High Color input color highestLowColor = clrDarkOrange; // Market Highest Low Color input color highestOpenColor = clrDodgerBlue; // Market Highest Open Color input color highestCloseColor = clrOrchid; // Market Highest Close Color input color lowestHighColor = clrHotPink; // Market Lowest High Color input color lowestLowColor = clrOrange; // Market Lowest Low Color input color lowestOpenColor = clrPowderBlue; // Market Lowest Open Color input color lowestCloseColor = clrMediumOrchid; // Market Lowest Close Color // input ENUM_LINE_STYLE highestHighStyle = STYLE_DOT; // Market Highest High Line Style input ENUM_LINE_STYLE highestLowStyle = STYLE_DOT; // Market Highest Low Line Style input ENUM_LINE_STYLE highestOpenStyle = STYLE_DOT; // Market Highest Open Line Style input ENUM_LINE_STYLE highestCloseStyle = STYLE_DOT; // Market Highest Close Line Style input ENUM_LINE_STYLE lowestHighStyle = STYLE_DOT; // Market Lowest High Line Style input ENUM_LINE_STYLE lowestLowStyle = STYLE_DOT; // Market Lowest Low Line Style input ENUM_LINE_STYLE lowestOpenStyle = STYLE_DOT; // Market Lowest Open Line Style input ENUM_LINE_STYLE lowestCloseStyle = STYLE_DOT; // Market Lowest Close Line Style // // END Inputs ... // // // START Global Definitions: Variables, Properties and etc ... // #property indicator_chart_window // // define indicator buffers ... #property indicator_buffers 8 #property indicator_plots 8 // // Declare Buffers ... #define marketHighestHighBufferIndex 0 #define marketHighestLowBufferIndex 1 #define marketHighestOpenBufferIndex 2 #define marketHighestCloseBufferIndex 3 #define marketLowestHighBufferIndex 4 #define marketLowestLowBufferIndex 5 #define marketLowestOpenBufferIndex 6 #define marketLowestCloseBufferIndex 7 // double marketHighestHighBuffer[]; double marketHighestLowBuffer[]; double marketHighestOpenBuffer[]; double marketHighestCloseBuffer[]; double marketLowestHighBuffer[]; double marketLowestLowBuffer[]; double marketLowestOpenBuffer[]; double marketLowestCloseBuffer[]; // // Includes our shared library ... #include "../Libraries/x-saherelm.lib.mq4" // // END Global Definitions: Variables, Properties and etc ... // // // Start Event Handlers ... // // // Initialization ... int OnInit() { // // Initialize what we want ... // // Validating Input Parameters ... if (marketLength <= 0) { return INIT_PARAMETERS_INCORRECT; } // // here we specify logging enabled or not ... enableLogging = true; // // this is a Tag which attached to our Logger ... logTag = "XST_XMKT"; // // Highest High ... string highestHighLbl = StringConcatenate("HH(", marketLength,")"); SetIndexLabel(marketHighestHighBufferIndex, highestHighLbl); SetIndexBuffer(marketHighestHighBufferIndex, marketHighestHighBuffer); SetIndexStyle( marketHighestHighBufferIndex, showHighestHigh ? DRAW_LINE : DRAW_NONE, highestHighStyle, 1, showHighestHigh ? highestHighColor : clrNONE ); // // Highest Low ... string highestLowLbl = StringConcatenate("HL(", marketLength,")"); SetIndexLabel(marketHighestLowBufferIndex, highestLowLbl); SetIndexBuffer(marketHighestLowBufferIndex, marketHighestLowBuffer); SetIndexStyle( marketHighestLowBufferIndex, showHighestLow ? DRAW_LINE : DRAW_NONE, highestLowStyle, 1, showHighestLow ? highestLowColor : clrNONE ); // // Highest Open ... string highestOpenLbl = StringConcatenate("HO(", marketLength,")"); SetIndexLabel(marketHighestOpenBufferIndex, highestOpenLbl); SetIndexBuffer(marketHighestOpenBufferIndex, marketHighestOpenBuffer); SetIndexStyle( marketHighestOpenBufferIndex, showHighestOpen ? DRAW_LINE : DRAW_NONE, highestOpenStyle, 1, showHighestOpen ? highestOpenColor : clrNONE ); // // Highest Close ... string highestCloseLbl = StringConcatenate("HC(", marketLength,")"); SetIndexLabel(marketHighestCloseBufferIndex, highestCloseLbl); SetIndexBuffer(marketHighestCloseBufferIndex, marketHighestCloseBuffer); SetIndexStyle( marketHighestCloseBufferIndex, showHighestClose ? DRAW_LINE : DRAW_NONE, highestCloseStyle, 1, showHighestClose ? highestCloseColor : clrNONE ); // // Lowest High ... string lowestHighLbl = StringConcatenate("LH(", marketLength,")"); SetIndexLabel(marketLowestHighBufferIndex, lowestHighLbl); SetIndexBuffer(marketLowestHighBufferIndex, marketLowestHighBuffer); SetIndexStyle( marketLowestHighBufferIndex, showLowestHigh ? DRAW_LINE : DRAW_NONE, lowestHighStyle, 1, showLowestHigh ? lowestHighColor : clrNONE ); // // Lowest Low ... string lowestLowLbl = StringConcatenate("LL(", marketLength,")"); SetIndexLabel(marketLowestLowBufferIndex, lowestLowLbl); SetIndexBuffer(marketLowestLowBufferIndex, marketLowestLowBuffer); SetIndexStyle( marketLowestLowBufferIndex, showLowestLow ? DRAW_LINE : DRAW_NONE, lowestLowStyle, 1, showLowestLow ? lowestLowColor : clrNONE ); // // Lowest Open ... string lowestOpenLbl = StringConcatenate("LO(", marketLength,")"); SetIndexLabel(marketLowestOpenBufferIndex, lowestOpenLbl); SetIndexBuffer(marketLowestOpenBufferIndex, marketLowestOpenBuffer); SetIndexStyle( marketLowestOpenBufferIndex, showLowestOpen ? DRAW_LINE : DRAW_NONE, lowestOpenStyle, 1, showLowestOpen ? lowestOpenColor : clrNONE ); // // Lowest Close ... string lowestCloseLbl = StringConcatenate("LC(", marketLength,")"); SetIndexLabel(marketLowestCloseBufferIndex, lowestCloseLbl); SetIndexBuffer(marketLowestCloseBufferIndex, marketLowestCloseBuffer); SetIndexStyle( marketLowestCloseBufferIndex, showLowestClose ? DRAW_LINE : DRAW_NONE, lowestCloseStyle, 1, showLowestClose ? lowestCloseColor : clrNONE ); // // initialization done ... return(INIT_SUCCEEDED); } // // DeInitialization ... void OnDeinit(const int reason) { // RemoveDraws(logTag); } // // 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(marketLength, 3); // // 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 Short Cycle ... CalculateBuffers(i); } // return rates_total; } // // END Event Handlers ... // // // START Functions ... // // // Calculate Short Cycle ... void CalculateBuffers( const int bar_index ) { // // Highest High ... double highestHighValue = GetMarketHighestHigh( bar_index, marketLength ); marketHighestHighBuffer[bar_index] = highestHighValue; // // Highest Low ... double highestLowValue = GetMarketHighestLow( bar_index, marketLength ); marketHighestLowBuffer[bar_index] = highestLowValue; // // Highest Open ... double highestOpenValue = GetMarketHighestOpen( bar_index, marketLength ); marketHighestOpenBuffer[bar_index] = highestOpenValue; // // Highest Close ... double highestCloseValue = GetMarketHighestClose( bar_index, marketLength ); marketHighestCloseBuffer[bar_index] = highestCloseValue; // // Lowest High ... double lowestHighValue = GetMarketLowestHigh( bar_index, marketLength ); marketLowestHighBuffer[bar_index] = lowestHighValue; // // Lowest Low ... double lowestLowValue = GetMarketLowestLow( bar_index, marketLength ); marketLowestLowBuffer[bar_index] = lowestLowValue; // // Lowest Open ... double lowestOpenValue = GetMarketLowestOpen( bar_index, marketLength ); marketLowestOpenBuffer[bar_index] = lowestOpenValue; // // Lowest Close ... double lowestCloseValue = GetMarketLowestClose( bar_index, marketLength ); marketLowestCloseBuffer[bar_index] = lowestCloseValue; } // // END Functions ... //