Kagi 制图指标·进阶篇
Kagi 指标的前端声明与输入枚举
在 MT5 自定义指标里,图形缓冲区的前几个编号常被预留给其他图层,这里从编号 5 开始挂 Kagi 相关绘制:第 5 号缓冲区画红色实心直方图(宽度 2),标签为 Yang;第 6、7、8 号均为红色实线(宽度 2),分别对应 Yang1、Yang2、Yang3 三条线。 为了让参数面板更直观,作者用 enum 把几类选项封装成下拉框:kagi_type_enum 区分 classic(0) 与 modified(1) 两种 Kagi 画法;price_type_enum 把构建用的价格限定为收/开/高/低(0~3);type_doorstep_enum 决定反转阈值是按点数还是百分比计算。 levels_type_enum 控制水平线布局是拐角式(cor)还是等距式(equ),levels_change_color_enum 则仅在拐角模式下生效,决定颜色随涨跌还是阴阳切换、或不切换。 输入区给出了可立刻改来验的硬参数:计算周期默认 PERIOD_CURRENT,重绘周期锁在 M1,图表起点写死为 2013.07.10 00:00:00;反转类型默认按 point 计算。外汇与贵金属波动剧烈,这类固定起点与重绘频率组合在高波动时段可能带来频繁重算,实盘前务必在策略测试器里跑一遍。
class="macro">#class="kw">property indicator_label5 "Yang" class="macro">#class="kw">property indicator_type5 DRAW_HISTOGRAM2 class="macro">#class="kw">property indicator_color5 clrRed class="macro">#class="kw">property indicator_style5 STYLE_SOLID class="macro">#class="kw">property indicator_width5 class="num">2 class=class="str">"cmt">//--- plot Yang1 class="macro">#class="kw">property indicator_label6 "Yang1" class="macro">#class="kw">property indicator_type6 DRAW_LINE class="macro">#class="kw">property indicator_color6 clrRed class="macro">#class="kw">property indicator_style6 STYLE_SOLID class="macro">#class="kw">property indicator_width6 class="num">2 class=class="str">"cmt">//--- plot Yang2 class="macro">#class="kw">property indicator_label7 "Yang2" class="macro">#class="kw">property indicator_type7 DRAW_LINE class="macro">#class="kw">property indicator_color7 clrRed class="macro">#class="kw">property indicator_style7 STYLE_SOLID class="macro">#class="kw">property indicator_width7 class="num">2 class=class="str">"cmt">//--- plot Yang3 class="macro">#class="kw">property indicator_label8 "Yang3" class="macro">#class="kw">property indicator_type8 DRAW_LINE class="macro">#class="kw">property indicator_color8 clrRed class="macro">#class="kw">property indicator_style8 STYLE_SOLID class="macro">#class="kw">property indicator_width8 class="num">2 class=class="str">"cmt">//--- Enumerations as class="kw">input data(for more attractive setting) class=class="str">"cmt">//--- Kagi charting type enum kagi_type_enum { classic=class="num">0, class=class="str">"cmt">// Classic modified=class="num">1, class=class="str">"cmt">// Modified }; class=class="str">"cmt">//--- Type of the price used for construction enum price_type_enum { c=class="num">0, class=class="str">"cmt">// Close o=class="num">1, class=class="str">"cmt">// Open h=class="num">2, class=class="str">"cmt">// High l=class="num">3, class=class="str">"cmt">// Low }; class=class="str">"cmt">//--- Type of the used reversal enum type_doorstep_enum { point=class="num">0, class=class="str">"cmt">// Point procent=class="num">1, class=class="str">"cmt">// Percent }; class=class="str">"cmt">//--- Type of levels location enum levels_type_enum { cor=class="num">0, class=class="str">"cmt">// Cornering equ=class="num">1, class=class="str">"cmt">// Equal distance }; class=class="str">"cmt">//--- Level colors change type(works when "Type of levels location"="Cornering") enum levels_change_color_enum { up_down=class="num">0, class=class="str">"cmt">// Up & Down yin_yang=class="num">1, class=class="str">"cmt">// Yin & Yang no=class="num">2, class=class="str">"cmt">// Don&class="macro">#x27;t change }; class=class="str">"cmt">//--- class="kw">input parameters class="kw">input ENUM_TIMEFRAMES period=PERIOD_CURRENT; class=class="str">"cmt">// Calculation period to build the chart class="kw">input ENUM_TIMEFRAMES period_to_redraw=PERIOD_M1; class=class="str">"cmt">// Refresh period chart class="kw">input class="type">class="kw">datetime start_data=D&class="macro">#x27;class="num">2013.07.class="num">10 class="num">00:class="num">00:class="num">00&class="macro">#x27;; class=class="str">"cmt">// Start time to build the chart class="kw">input kagi_type_enum kagi_type=classic; class=class="str">"cmt">// The type to build Kagi chart class="kw">input price_type_enum price_type=c; class=class="str">"cmt">// Price used to build chart class="kw">input type_doorstep_enum type_doorstep=point; class=class="str">"cmt">// Type calculate doorstep
◍ 反转阈值与绘制层的输入参数
这个指标把「门阶反转」的触发距离做成可调输入,默认 doorstep=25 点。意思是价格从极值回拉达到 25 点时,才在副图判定为一根阴阳反转线,交易者可以把它当成噪音过滤器,避免微小折返不断重绘。 副图线的颜色与粗细分开控制:阴线 color_yin 与阳线 color_yang 默认都是 clrRed,但 width_yin=1、width_yang=2,阳线画粗一点便于肉眼区分动能方向。若你做黄金 XAUUSD,点值小、波动大,把 doorstep 提到 40~60 才可能明显减少假信号,外汇直盘则可保留 25 试算。 层级绘制默认关闭(levels_on_off=false),打开后按 levels_type 决定画法、levels_number=6 条、配色用 levels_first_color=clrBeige 与 levels_second_color=clrCoral 做涨跌切换。价格标签在主图与副图各有一组开关,label_1_number=10 控制副图最多挂 10 个价位注记。 时间线反转 time_line_draw 默认开,会在主图标出每次反转发生的竖线。把这些 input 直接拷进 MT5 指标源码头部,编译后从属性框调参,就能立刻看历史K线上门阶反转的分布密度。
class="kw">input class="type">class="kw">double doorstep=class="num">25; class=class="str">"cmt">// Doorstep reversal class="kw">input class="type">color color_yin=clrRed; class=class="str">"cmt">// Color Yin line(indicator window) class="kw">input class="type">color color_yang=clrRed; class=class="str">"cmt">// Color Yang line(indicator window) class="kw">input class="type">char width_yin=class="num">1; class=class="str">"cmt">// Width Yin line(indicator window) class="kw">input class="type">char width_yang=class="num">2; class=class="str">"cmt">// Width Yang line(indicator window) class="kw">input class="type">bool levels_on_off=false; class=class="str">"cmt">// Draw level(indicator window) class="kw">input levels_type_enum levels_type=cor; class=class="str">"cmt">// Type of drawing levels(indicator window) class="kw">input class="type">uint levels_number=class="num">6; class=class="str">"cmt">// Number of levels(indicator window) class="kw">input levels_change_color_enum levels_change_color=up_down; class=class="str">"cmt">// Type change class="type">color of levels(indicator window) class="kw">input class="type">color levels_first_color=clrBeige; class=class="str">"cmt">// The first class="type">color of level(indicator window) class="kw">input class="type">color levels_second_color=clrCoral; class=class="str">"cmt">// The second class="type">color of level(indicator window) class="kw">input class="type">bool label_1=true; class=class="str">"cmt">// Draw price label on(indicator window) class="kw">input class="type">uint label_1_number=class="num">10; class=class="str">"cmt">// The number of labels(indicator window) class="kw">input class="type">color label_1_color=clrGreenYellow; class=class="str">"cmt">// The class="type">color of labels(indicator window) class="kw">input class="type">bool label_2=true; class=class="str">"cmt">// Draw price label on(main chart) class="kw">input class="type">color label_2_color=clrGreenYellow; class=class="str">"cmt">// The class="type">color of labels(main chart) class="kw">input class="type">bool time_line_draw=true; class=class="str">"cmt">// Draw a timeline reversal(main chart)
「Kagi 指标的参数与缓冲区布局」
把 Kagi 线画在主图还是独立窗口,先由输入参数定调。time_separate_windows 默认 false,意味着时间轴反转标记直接叠在主图;kagi_main_chart 默认 true,阴阳线本身也渲染在主图,不想干扰价格判读时可改 false 切到指标子窗口。 阴阳线的视觉区分靠几个 color / char 输入:color_yin_main 与 color_yang_main 原文都设为 clrRed,若不开 time_line_change_color,涨跌方向在颜色上完全无差;该开关默认 true 才启用 time_first_color(clrRed) 与 time_second_color(clrGreenYellow) 做时间轴双色区分。线宽上 yang 给 2、yin 给 1,阳线略粗便于一眼分辨。 magic_numb 取 65758473787389 这种大随机数,作用是给指标创建的对象打标签,避免和你手动画的横线、趋势线在 OBJ_FIND 时撞名。实盘里若同时挂多个 Kagi 变体,各自魔数必须不同。 指标内部开了 10 个 double 缓冲区:YinBuffer1/2、Yin1/2/3 与对称的 Yang 系列,分别承接阴阳线的不同绘制层。Price[] 和 Time[] 负责从图表拷贝原始序列,stop_data、bars_copied 等变量跟踪拷贝进度,copy_history / copy_time 记录当次 CopyBuffer 是否成功——任一为 false 时后续绘图会断棒。 time_change[] 存方向翻转的发生时刻,time_line[] 用 0/1 标记彼时是阴还是阳主导。这两个数组是时间轴双色渲染的数据源,调试时可在 OnCalculate 末尾 Print(time_change[0], time_line[0]) 看最新一次翻转。外汇与贵金属波动大,Kagi 反转阈值请结合品种点差实测,高风险品种勿直接套用默认视觉参数。
class="kw">input class="type">bool time_separate_windows=false; class=class="str">"cmt">// Draw a timeline reversal on indicator window class="kw">input class="type">bool time_line_change_color=true; class=class="str">"cmt">// Different class="type">color timeline on the Yin and Yang lines(main chart) class="kw">input class="type">color time_first_color=clrRed; class=class="str">"cmt">// The first class="type">color of timeline(main chart) class="kw">input class="type">color time_second_color=clrGreenYellow; class=class="str">"cmt">// The second class="type">color of timeline(main chart) class="kw">input class="type">bool kagi_main_chart=true; class=class="str">"cmt">// Draw Kagi on main chart(main chart) class="kw">input class="type">color color_yin_main=clrRed; class=class="str">"cmt">// Color Yin line(main chart) class="kw">input class="type">color color_yang_main=clrRed; class=class="str">"cmt">// Color Yang line(main chart) class="kw">input class="type">char width_yin_main=class="num">1; class=class="str">"cmt">// Width Yin line(main chart) class="kw">input class="type">char width_yang_main=class="num">2; class=class="str">"cmt">// Width Yang line(main chart) class="kw">input class="type">long magic_numb=class="num">65758473787389; class=class="str">"cmt">// The magic number for drawing objects class=class="str">"cmt">//--- indicator buffers class="type">class="kw">double YinBuffer1[]; class="type">class="kw">double YinBuffer2[]; class="type">class="kw">double Yin1Buffer[]; class="type">class="kw">double Yin2Buffer[]; class="type">class="kw">double Yin3Buffer[]; class="type">class="kw">double YangBuffer1[]; class="type">class="kw">double YangBuffer2[]; class="type">class="kw">double Yang1Buffer[]; class="type">class="kw">double Yang2Buffer[]; class="type">class="kw">double Yang3Buffer[]; class=class="str">"cmt">//--- additional variables class="type">class="kw">double Price[]; class=class="str">"cmt">// Buffer for storing the copied price data class="type">class="kw">double Time[]; class=class="str">"cmt">// Buffer for storing the copied time data class=class="str">"cmt">//--- class="type">class="kw">datetime stop_data; class=class="str">"cmt">// Current time class="type">int bars_copied=class="num">0; class=class="str">"cmt">// Number of the already copied bars from the initial date class="type">int bars_copied_time; class=class="str">"cmt">// Number of the already copied bars having the initial date class="type">bool copy_history=false; class=class="str">"cmt">// Price history copying result class="type">bool copy_time=false; class=class="str">"cmt">// Time history copying result class=class="str">"cmt">//--- class="type">class="kw">datetime time_change[]; class=class="str">"cmt">// Array for writing the time when the chart movement started changing(up or down) class="type">char time_line[]; class=class="str">"cmt">// Array for storing the data on what line(Yin=class="num">0 or Yang=class="num">1) direction has changed
阴阳段缓冲区的初始化接管
做阴阳段(Yin/Yang)类自定义指标时,MT5 要求先把所有绘图缓冲显式绑定,否则运行时只会拿到空数组或报错。上面这段 OnInit 把 0~9 号共 10 个 INDICATOR_DATA 缓冲分别映射给 YinBuffer1/2、Yin1~3Buffer、YangBuffer1/2、Yang1~3Buffer,并用 ArraySetAsSeries(...,true) 统一改成时间倒序,方便按 K 线序号直接取最新值。
- 号和 11 号缓冲被设为 INDICATOR_CALCULATIONS,不画图,只用来暂存收盘价与开棒时间,给后续段划分逻辑提供原料。循环里对前 8 个绘图索引调用 PlotIndexSetDouble(x,PLOT_EMPTY_VALUE,-1),等于告诉终端:-1 是「不画」的哨兵值,能避免把初始化期的 0 误渲染成水平线。
IndicatorSetString 里的短名拼了 magic_numb 变量,意味着同一图表挂多个实例时靠这个魔法数区分;PlotIndexSetString 把 0~4 标 Yin、4 标 Yang,是后续图例着色的基础。开 MT5 新建指标时,照这套缓冲编号抄一遍,能省掉大半调试时间。
class="type">class="kw">double time_change_price[]; class=class="str">"cmt">// Array for writing the chart movement change price class="type">class="kw">double time_central_price[]; class=class="str">"cmt">// Array for writing the average price during the chart movement change class="type">uint a=class="num">0; class=class="str">"cmt">// Variable for building the chart, number of chart reversals is fixed class=class="str">"cmt">//+------------------------------------------------------------------+ class=class="str">"cmt">//| Custom indicator initialization function | class=class="str">"cmt">//+------------------------------------------------------------------+ class="type">int OnInit() { class=class="str">"cmt">//--- indicator buffers mapping SetIndexBuffer(class="num">0,YinBuffer1,INDICATOR_DATA); ArraySetAsSeries(YinBuffer1,true); SetIndexBuffer(class="num">1,YinBuffer2,INDICATOR_DATA); ArraySetAsSeries(YinBuffer2,true); SetIndexBuffer(class="num">2,Yin1Buffer,INDICATOR_DATA); ArraySetAsSeries(Yin1Buffer,true); SetIndexBuffer(class="num">3,Yin2Buffer,INDICATOR_DATA); ArraySetAsSeries(Yin2Buffer,true); SetIndexBuffer(class="num">4,Yin3Buffer,INDICATOR_DATA); ArraySetAsSeries(Yin3Buffer,true); class=class="str">"cmt">//--- SetIndexBuffer(class="num">5,YangBuffer1,INDICATOR_DATA); ArraySetAsSeries(YangBuffer1,true); SetIndexBuffer(class="num">6,YangBuffer2,INDICATOR_DATA); ArraySetAsSeries(YangBuffer2,true); SetIndexBuffer(class="num">7,Yang1Buffer,INDICATOR_DATA); ArraySetAsSeries(Yang1Buffer,true); SetIndexBuffer(class="num">8,Yang2Buffer,INDICATOR_DATA); ArraySetAsSeries(Yang2Buffer,true); SetIndexBuffer(class="num">9,Yang3Buffer,INDICATOR_DATA); ArraySetAsSeries(Yang3Buffer,true); class=class="str">"cmt">//--- add the buffer for copying data on prices for calculation SetIndexBuffer(class="num">10,Price,INDICATOR_CALCULATIONS); class=class="str">"cmt">//--- add the buffer for copying data on bar open time for construction SetIndexBuffer(class="num">11,Time,INDICATOR_CALCULATIONS); class=class="str">"cmt">//--- set what values are not to be drawn for(class="type">char x=class="num">0; x<class="num">8; x++) { PlotIndexSetDouble(x,PLOT_EMPTY_VALUE,-class="num">1); } class=class="str">"cmt">//--- set the indicator&class="macro">#x27;s look IndicatorSetString(INDICATOR_SHORTNAME,"BKCV "+IntegerToString(magic_numb)); class=class="str">"cmt">// Indicator name IndicatorSetInteger(INDICATOR_DIGITS,_Digits); class=class="str">"cmt">// Display accuracy class=class="str">"cmt">//--- assign names to graphical constructions PlotIndexSetString(class="num">0,PLOT_LABEL,"Yin"); PlotIndexSetString(class="num">1,PLOT_LABEL,"Yin"); PlotIndexSetString(class="num">2,PLOT_LABEL,"Yin"); PlotIndexSetString(class="num">3,PLOT_LABEL,"Yin"); PlotIndexSetString(class="num">4,PLOT_LABEL,"Yang");
◍ 阴阳线绘制的属性收尾与历史拷贝入口
在指标初始化收口阶段,把 5~7 号绘图缓冲的标签统一设为 "Yang",让 MT5 数据窗口里这三根阳线相关缓冲归到同一组名下,避免默认缓冲名刷出一堆 Plot0、Plot1 干扰排查。 紧接着用 PlotIndexSetInteger 把 0~7 号缓冲的 PLOT_SHOW_DATA 全部置为 false,即禁止在状态栏显示这些图形构造的实时数值——阴阳线本身靠视觉读形,数值面板留空能减少视觉噪点。 颜色与线宽按阴阳分组:0~3 号套 color_yin / width_yin,4~7 号套 color_yang / width_yang,分组连续且索引不交叉,改色时直接调变量即可。最后用 IndicatorSetInteger(INDICATOR_LEVELS, levels_number) 设定副图水平线数量,返回 INIT_SUCCEEDED 结束 init。 初始化之后紧接的是 func_copy_history,它接收 result_array 引用与 data_start、data_stop 两个时间边界,负责把指定区间的历史数据拷进缓冲供后续阴阳判定使用。开 MT5 把 levels_number 设成 0 对比设成 4,能直接看到副图基准线层的增减差异。
PlotIndexSetString(class="num">5,PLOT_LABEL,"Yang"); PlotIndexSetString(class="num">6,PLOT_LABEL,"Yang"); PlotIndexSetString(class="num">7,PLOT_LABEL,"Yang"); class=class="str">"cmt">//--- prohibit display of the results of the current values for graphical constructions PlotIndexSetInteger(class="num">0,PLOT_SHOW_DATA,false); PlotIndexSetInteger(class="num">1,PLOT_SHOW_DATA,false); PlotIndexSetInteger(class="num">2,PLOT_SHOW_DATA,false); PlotIndexSetInteger(class="num">3,PLOT_SHOW_DATA,false); PlotIndexSetInteger(class="num">4,PLOT_SHOW_DATA,false); PlotIndexSetInteger(class="num">5,PLOT_SHOW_DATA,false); PlotIndexSetInteger(class="num">6,PLOT_SHOW_DATA,false); PlotIndexSetInteger(class="num">7,PLOT_SHOW_DATA,false); class=class="str">"cmt">//--- set class="type">color for Yin line PlotIndexSetInteger(class="num">0,PLOT_LINE_COLOR,color_yin); PlotIndexSetInteger(class="num">1,PLOT_LINE_COLOR,color_yin); PlotIndexSetInteger(class="num">2,PLOT_LINE_COLOR,color_yin); PlotIndexSetInteger(class="num">3,PLOT_LINE_COLOR,color_yin); class=class="str">"cmt">//--- set class="type">color for Yang line PlotIndexSetInteger(class="num">4,PLOT_LINE_COLOR,color_yang); PlotIndexSetInteger(class="num">5,PLOT_LINE_COLOR,color_yang); PlotIndexSetInteger(class="num">6,PLOT_LINE_COLOR,color_yang); PlotIndexSetInteger(class="num">7,PLOT_LINE_COLOR,color_yang); class=class="str">"cmt">//--- set Yin line width PlotIndexSetInteger(class="num">0,PLOT_LINE_WIDTH,width_yin); PlotIndexSetInteger(class="num">1,PLOT_LINE_WIDTH,width_yin); PlotIndexSetInteger(class="num">2,PLOT_LINE_WIDTH,width_yin); PlotIndexSetInteger(class="num">3,PLOT_LINE_WIDTH,width_yin); class=class="str">"cmt">//--- set Yang line width PlotIndexSetInteger(class="num">4,PLOT_LINE_WIDTH,width_yang); PlotIndexSetInteger(class="num">5,PLOT_LINE_WIDTH,width_yang); PlotIndexSetInteger(class="num">6,PLOT_LINE_WIDTH,width_yang); PlotIndexSetInteger(class="num">7,PLOT_LINE_WIDTH,width_yang); class=class="str">"cmt">//--- set the number of levels in the indicator window IndicatorSetInteger(INDICATOR_LEVELS,levels_number); class=class="str">"cmt">//--- class="kw">return(INIT_SUCCEEDED); } class=class="str">"cmt">//+------------------------------------------------------------------+ class=class="str">"cmt">//| Func Copy History | class=class="str">"cmt">//+------------------------------------------------------------------+ class="type">bool func_copy_history(class="type">class="kw">double &result_array[], class="type">class="kw">datetime data_start, class="type">class="kw">datetime data_stop) { class=class="str">"cmt">//---
「分批拷贝行情数据的容错写法」
在 MT5 里用 CopyClose / CopyOpen 这类函数一次性拉历史数据,遇到品种切换或服务器重连时可能丢几根 bar。上面这段把拷贝拆成「中间数组 + 主数组」两步,先算还差多少根没拷,再按 price_type 分支取 Close、Open、High、Low。 关键在 bars_copied 的自减与 bars_to_copy 的自增:若不是首次拷贝(bars_copied!=0),先 bars_copied-- 再 bars_to_copy++,等于把上回最后一根重叠 bar 让出来,避免重复写入。ArrayResize 按待拷数量扩中间数组,拷成功后用 ArrayCopy 从偏移 bars_copied 处接进主数组,bars_copied 累加 result_copy。 func_copy_time 那半截只写到算 bars_to_copy_time = Bars(_Symbol,period,data_start,data_stop),还没贴后续拷贝逻辑。你在 EA 里照这个骨架补完,把 data_start/data_stop 换成自己要回测的起止时间,跑一遍就能看出重叠 bar 是不是清零了。外汇与贵金属杠杆高,回测通过不代表实盘同向概率高。
class="type">int x=false; class=class="str">"cmt">// Variable for answer class="type">int result_copy=-class="num">1; class=class="str">"cmt">// Number of copied data class="kw">static class="type">class="kw">double price_interim[]; class=class="str">"cmt">// Temporary dynamic array for storing copied data class="kw">static class="type">int bars_to_copy; class=class="str">"cmt">// Number of bars for copying bars_to_copy=Bars(_Symbol,period,data_start,data_stop); class=class="str">"cmt">// Find out the current number of bars on the time interval bars_to_copy-=bars_copied; class=class="str">"cmt">// Calculate the number of bars to be copied if(bars_copied!=class="num">0) class=class="str">"cmt">// If it is not the first time the data has been copied { bars_copied--; bars_to_copy++; } ArrayResize(price_interim,bars_to_copy); class=class="str">"cmt">// Change the size of the receiving array class="kw">switch(price_type) { case class="num">0: result_copy=CopyClose(_Symbol,period,class="num">0,bars_to_copy,price_interim); break; case class="num">1: result_copy=CopyOpen(_Symbol,period,class="num">0,bars_to_copy,price_interim); break; case class="num">2: result_copy=CopyHigh(_Symbol,period,class="num">0,bars_to_copy,price_interim); break; case class="num">3: result_copy=CopyLow(_Symbol,period,class="num">0,bars_to_copy,price_interim); break; } if(result_copy!=-class="num">1) class=class="str">"cmt">// If copying to the intermediate array is successful { ArrayCopy(result_array,price_interim,bars_copied,class="num">0,WHOLE_ARRAY); class=class="str">"cmt">// Copy the data from the temporary array to the main one x=true; class=class="str">"cmt">// assign the positive answer to the function bars_copied+=result_copy; class=class="str">"cmt">// Increase the value of the processed data } class=class="str">"cmt">//--- class="kw">return(x); } class=class="str">"cmt">//+------------------------------------------------------------------+ class=class="str">"cmt">//| Func Copy Time | class=class="str">"cmt">//+------------------------------------------------------------------+ class="type">bool func_copy_time(class="type">class="kw">double &result_array[], class="type">class="kw">datetime data_start, class="type">class="kw">datetime data_stop) { class=class="str">"cmt">//--- class="type">int x=false; class=class="str">"cmt">// Variable for answer class="type">int result_copy=-class="num">1; class=class="str">"cmt">// Number of copied data class="kw">static class="type">class="kw">datetime time_interim[]; class=class="str">"cmt">// Temporary dynamic array for storing copied data class="kw">static class="type">int bars_to_copy_time; class=class="str">"cmt">// Number of bars for copying bars_to_copy_time=Bars(_Symbol,period,data_start,data_stop); class=class="str">"cmt">// Find out the current number of bars on the time interval