脚本: sSyncScroll - 页 2

 
事实上,当尝试向后滚动图表并查看历史记录时,当出现新的刻度线时,图表会返回到最开始的位置。在这种情况下,我为什么需要它呢?我已经知道,在 M1 上绘制最后一根蜡烛时,它也是所有其他 TF 的最后一根蜡烛。如果没有这个指标,所有窗口中的最后一根蜡烛都会自动重新绘制。
 
Дима Джумок #:
事实上,当尝试向后滚动图表并查看历史记录时,当出现新的刻度线时,图表会返回到最开始的位置。在这种情况下,我为什么需要它呢?我已经知道,在 M1 上绘制最后一根蜡烛时,它也是所有其他 TF 的最后一根蜡烛。如果没有这个指标,最后一根蜡烛会自动在所有窗口中重新绘制。

在下一次语言修改后,它就坏了,我这里还有一个,也坏了。查找更多,这里有可用的。

 
Dmitry Fedoseev #:

我这里还有一个,也坏了。寻找更多,这里有一些可用的。

德米特里,感谢您的回复。遗憾的是,谷歌只提供了您的开发链接。论坛也没有给我提供任何替代方案。Admiral Market 提供了这种功能,但只在他们的平台上,而且不是 MT5。亲爱的fxsaber 在 2017 年提供了他的MT5 - 技术指标和外汇市场分析 - MQL5 Algo-Traders Forum(最后一条评论中有指标文本)变体,但我不知道如何将其转换为 MT5 终端,因此我无法确定它是否是一个有效的变体。如果您不介意,请转换它,也许它是有效的。

//MQL4&5 代码
// 按正确的时间同步所有图表

sinput int TimerInterval = 1; // 以毫秒为单位的更新间隔

// 禁用所有图表的自动滚动和移动功能
bool AutoShiftOff( void )
{
  long handle = ChartFirst();

  while (handle != INVALID_HANDLE)
  {
    ChartSetInteger(handle, CHART_SHIFT, false);
    ChartSetInteger(handle, CHART_AUTOSCROLL, false);

    handle = ChartNext(handle);
  }

  return(true);
}

const bool Init = EventSetMillisecondTimer(TimerInterval) && AutoShiftOff();

void OnTimer()
{
  SyncCharts();
}

// 如果此时没有条形图,则返回 true("洞")。
bool IsHole( const string Symb, const ENUM_TIMEFRAMES TimeFrame, const datetime time )
{
  return(Bars(Symb, TimeFrame, SeriesInfoInteger(_Symbol, PERIOD_CURRENT, SERIES_FIRSTDATE), time) +
         Bars(Symb, TimeFrame, time, SeriesInfoInteger(_Symbol, PERIOD_CURRENT, SERIES_LASTBAR_DATE)) ==
         SeriesInfoInteger(_Symbol, PERIOD_CURRENT, SERIES_BARS_COUNT));
}

// 返回时间条
int iBarShift( const string Symb, const ENUM_TIMEFRAMES TimeFrame, datetime time )
{
  int Res = -1;
  datetime LastBar;

  time -= time % PeriodSeconds(TimeFrame);

  if (SeriesInfoInteger(Symb, TimeFrame, SERIES_LASTBAR_DATE, LastBar))
  {
    if (time > LastBar)
      Res = (int)((LastBar - time) / PeriodSeconds(TimeFrame));
    else
    {
      const int Shift = Bars(Symb, TimeFrame, time, LastBar);

      if (Shift > 0)
      {
        Res = Shift - 1;

        if (IsHole(Symb, TimeFrame, time))
          Res++;
      }
    }
  }

  return(Res);
}

// 返回酒吧时间
datetime iBarShift( const string Symb, const ENUM_TIMEFRAMES TimeFrame = PERIOD_CURRENT, const int Pos = 0 )
{
  datetime Tmp[1];

  CopyTime(Symb, TimeFrame, (Pos < 0) ? 0 : Pos, 1, Tmp);

  return(Tmp[0] - ((Pos < 0) ? Pos * PeriodSeconds(TimeFrame) : 0));
}

// 返回右侧图表条形图
int ChartBarRight( const long chartID = 0 )
{
  return((int)(ChartGetInteger(chartID, CHART_FIRST_VISIBLE_BAR) - ChartGetInteger(chartID, CHART_WIDTH_IN_BARS) + 1));
}

// 返回正确的图表时间
datetime GetChartTimeRight( const long chartID = 0 )
{
  return(iBarShift(ChartSymbol(chartID), ChartPeriod(chartID), ChartBarRight(chartID)));
}

// 设置正确的图表时间,返回设置的时间
datetime SetChartTimeRight( datetime time, const long chartID = 0, const ulong MaxTime = 1 e5 )
{
  const string Symb = ChartSymbol(chartID);
  const ENUM_TIMEFRAMES period = ChartPeriod(chartID);

  const int Pos = iBarShift(Symb, period, time);
  const int PrevPos = ChartBarRight(chartID);

  if ((Pos != PrevPos) && ChartNavigate(chartID, CHART_END, -1 - Pos))
  {
    const ulong StartTime = GetMicrosecondCount();
    int NewPos = ChartBarRight(chartID);

    while (((NewPos != Pos)|| (NewPos == PrevPos)) && (GetMicrosecondCount() - StartTime < MaxTime) && !IsStopped())
    {
      Sleep(0);
      
      NewPos = ChartBarRight(chartID);
    }
  }

  return(GetChartTimeRight(chartID));
}

// 在任意数组的末尾添加一个元素
template <typename T>
void AddArrayElement( T &Array[], const T Value, const int Reserve = 0 )
{
  const int Size = ArraySize(Array);

  ArrayResize(Array, Size + 1, Reserve);

  Array[Size] = Value;
}

// 获取每个图表右边条形图的时间
int GetChartsTimeRight( datetime &RightTime[], long &Handles[] )
{
  ArrayFree(RightTime);
  ArrayFree(Handles);

  long handle = ChartFirst();

  while (handle != INVALID_HANDLE)
  {
    AddArrayElement(RightTime, GetChartTimeRight(handle));
    AddArrayElement(Handles, handle);

    handle = ChartNext(handle);
  }

  return(ArraySize(RightTime));
}

// 为所有图表设置正确的时间
int SetChartsTimeRight( const datetime time, datetime &RightTime[], const long ExcludeHandle = 0 )
{
  ArrayFree(RightTime);

  long handle = ChartFirst();

  while (handle != INVALID_HANDLE)
  {
    AddArrayElement(RightTime, (ExcludeHandle == handle) ? GetChartTimeRight(handle) : SetChartTimeRight(time, handle));

    handle = ChartNext(handle);
  }

  return(ArraySize(RightTime));
}

// 返回右边条形图的时间发生变化的图表
long GetChangeChart( const datetime &PrevRightTime[])
{
  datetime Handles[];
  datetime RightTime[];

  long Res = ArraySize(PrevRightTime) ? 0 : ChartID();

  for (int i = MathMin(ArraySize(PrevRightTime), GetChartsTimeRight(RightTime, Handles)) - 1; i >= 0; i--)
    if (RightTime[i] != PrevRightTime[i])
    {
      Res = Handles[i];

      break;
    }

  return(Res);
}

// 按正确的时间同步所有图表,返回已同步图表的数量
int SyncCharts()
{
  static datetime PrevRightTime[];

  const long handle = GetChangeChart(PrevRightTime);

  return(handle ? SetChartsTimeRight(GetChartTimeRight(handle), PrevRightTime, handle) : 0);
}
fxsaber
fxsaber
  • 2023.01.17
  • www.mql5.com
Профиль трейдера
 
Дима Джумок #:

德米特里,感谢您的回复。遗憾的是,谷歌只提供了您的开发链接。论坛也没有给我提供任何替代方案。Admiral Market 提供了这样的功能,但仅限于他们的平台,而且不是 MT5。亲爱的fxsaber 在 2017 年提供了他的MT5 - 技术指标和外汇市场分析 - MQL5 Algo-Traders 论坛(最后一条评论中有指标文本)的变体,但我不知道如何将其转换为 MT5 终端,因此我无法确定它是否是一个有效的变体。如果您不介意,请转换它,也许它是有效的。

那最好还是自己解决吧。

我现在下载了我的版本,它能正常工作。有一个不便之处--如果不启用缩进功能,滚动图表上所需的条形图就会越过边缘,看不到线条。这一点必须纠正。

你有什么问题,怎么会不工作?脚本会在出现新的刻度线时禁用自动滚动。

附加脚本时,所有图表上的工具栏按钮都应自动按下:

 
炸弹真管用非常感谢