#property copyright "Copyright 2018-2020, Level Up Software" #property link "https://www.az-invest.eu" #property description "A timescale indicator for use on X Tick Chart." #property version "1.03" #property indicator_separate_window #property indicator_plots 0 #include RangeBarIndicator customChartIndicator; #define PREFIX_SEED "6D4E6" static long __chartId = ChartID(); static int __subWinId = ChartWindowFind(); enum ENUM_DISPLAY_FORMAT { DisplayFormat1 = 0, // 25 Jan 10:55 DisplayFormat2, // 25.01 10:55 }; input color InpTextColor = clrWhiteSmoke; // Font color input int InpFontSize = 9; // Font size input int InpSpacing = 3; // Date/Time spacing factor input ENUM_DISPLAY_FORMAT InpDispFormat = DisplayFormat1; // Display format int __spacing = InpSpacing; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping IndicatorSetString(INDICATOR_SHORTNAME,"\n"); IndicatorSetDouble(INDICATOR_MINIMUM,0); IndicatorSetDouble(INDICATOR_MAXIMUM, 9); IndicatorSetInteger(INDICATOR_HEIGHT,16); IndicatorSetInteger(INDICATOR_DIGITS,0); //--- customChartIndicator.SetGetTimeFlag(); RecalcSpacing(); return(INIT_SUCCEEDED); } void OnDeinit(const int r) { ObjectsDeleteAll(__chartId,PREFIX_SEED); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ 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[]) { if(!customChartIndicator.OnCalculate(rates_total,prev_calculated,time,close)) return(0); if(!customChartIndicator.BufferSynchronizationCheck(close)) return(0); int start = customChartIndicator.GetPrevCalculated() - 1; //--- correct position if(start<0) start=0; if((start == 0) || customChartIndicator.IsNewBar) { DrawTimeLine(0,customChartIndicator.GetRatesTotal(),time); } //--- return value of prev_calculated for next call return(rates_total); } bool RecalcSpacing() { static int __prevScale = 5; int __currentScale = (int)ChartGetInteger(0, CHART_SCALE); if(__prevScale == __currentScale) { return false; } switch(__currentScale) { case 5: __spacing = InpSpacing; break; case 4: __spacing = InpSpacing * 2; break; case 3: __spacing = InpSpacing * 4; break; case 2: __spacing = InpSpacing * 8; break; case 1: __spacing = InpSpacing * 16; break; case 0: __spacing = InpSpacing * 32; break; } __prevScale = __currentScale; return true; } //+------------------------------------------------------------------+ void DrawTimeLine(const int nPosition, const int nRatesCount, const datetime &canvasTime[]) { datetime curBarTime = 0; bool _start = false; int c = 0; ObjectsDeleteAll(__chartId,PREFIX_SEED); for(int i=nPosition; i