在MetaTrader 4中,15秒的tick数据可以用来生成一条K线。以下是一个简单的示例代码,演示了如何使用15秒的tick数据生成一条K线。
我们在做交易时,很多时候会用到其它级别的K线来分析行情,但是MT4里面只会5分钟和1小时的,最短也是1分钟的表图,那我们有没有办法用服务器的时间来生成自己的秒级表图的,方法是有的,下面附上代码给大家测试。更多代码关注我们 牛人量化程序兵器库『量化藏宝塔Max2024更新』
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
#property indicator_chart_window
datetime lastBarTime;
//+------------------------------------------------------------------+
//| 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 (rates_total < 2)
return 0;
int limit = rates_total - prev_calculated;
if (prev_calculated > 0)
limit++;
for (int i = 0; i < limit; i++)
{
datetime barTime = Time[i];
if (barTime - lastBarTime >= 15)
{
// 生成新的K线
double newOpen = open[i];
double newHigh = high[i];
double newLow = low[i];
double newClose = close[i];
// 在图表上绘制K线
// 请使用绘图函数绘制K线
lastBarTime = barTime;
}
}
return(rates_total);
}
//+------------------------------------------------------------------+
版权声明
本文仅代表作者观点,不代表牛人量化交易网立场。
本文系作者授权牛人量化交易网发表,未经许可,不得转载。
评论列表
发表评论