Line_4[i]=(Line_1[i]+Line_2[i]+Line_3[i])/3;// Summary array //-------------------------------------------------------- 17 -- if (Aver_Bars>0) // If wrong set smoothing Aver_Bars=0; // .. no less than zero Sum=0; // Technical means for(n=i; n>=i+Aver_Bars; n++) // Summing last values Sum=Sum + Line_4[n]; // Accum. sum of last values Line_5[i]= Sum/(Aver_Bars+1); // Indic. array of smoothed line //-------------------------------------------------------- 18 -- i--; // Calculating index of the next bar //-------------------------------------------------------- 19 -- }
return; // Exit the special function start() }
//-------------------------------------------------------------- 20 --
使用不同的平均周期计算三率线的MA指标阵列。马平均期间为当前的时间内成立了由用户在外部变量Period_MA_1,支持马的平均周期 - 外部变量Period_MA_0。平均MAS的时期,其中率计算,平均支持均线的时期,期间,其中率测量,计算6-7块更高的时限。相应系数计算这些值定义在块5-6。例如,如果该指标被连接到M30图表,系数K2和K2将等于2和8,相应的,因为最近的时间表H1是比M30的两倍大,下一个更高的时间表是H4的,这是比M30的大八倍。在开始()的计算是很简单的。在12-13块支持马值计算当前的时间内(黑色指示线)。 13-14块的指示灯阵列的值Line_1[]定义当前的时间内(橙色线)为中华民国线的建设。率定义的分析,对当前的酒吧和酒吧的MA值的差异,该指数是由Sh_1大于目前,即(MA_c - MA_p)。目前酒吧的Line_1[]的指示数组的值是由支持马和特征值率(这里K为比例系数,外部变量设置)值:
Line_1[i]= MA_0+K*(MA_c-MA_p);// value of 1st rate line
率线建设两个时限(14-16块)其他进行类似的计算。这些阵列支持的均线指标没有显示。 16017块的指示灯阵列的值Line_4[]被定义为建设平均增长率线(蓝线),这是他们简单的算术平均。 17-18块进行计算一个平均增长率线 - 平滑1(粗红线,指标阵列Line_5[])。平滑是通过简单平均方式:指标阵列Line_5[]对目前酒吧的元素值是几个指标阵列Line_4[]最后一个值的算术平均值。使用这种方法的结果作为指标线变得少波浪,但在同一时间有一定的滞后性。金额为平滑酒吧被设置外部变量Aver_Bars。
启动指标,你会看到6个指标线在图表窗口:
? ? ?
黑线 - EA建设在当前的时间内价格率线的支撑; 橘线 - 对当前的时间内价格变化率; 绿线 - 价格变化率在最近的更高的时间表;
? ? ?
棕线 - 价格变化率对未来更高的时间表; 蓝线 - 线平均价格变化率; 红线 - 价格变动率的平滑平均线。
图127。自定义的指标roc.mq4允许跟踪屏幕上最接近当前较高,下一个更高的时间表,其平均汇率变动图表。
指标roc.mq4可以附加任何安全窗口与任何时间表。对于每一个时间表相同的规则是:橙色线反映率在目前的时间表,绿色 - 最近较大的时间表,棕色 - 对未来更大的时间表。您可以轻松地查询:附加指标图表窗口,看到在当前的时间内和最近的时限行的形象(图128和图129。)。
图128。第3(棕色)线电流(M15的)时间表的形象与2号线(绿色)的形象上是一致的较高的时间表系统(M30,图129)和下一个更高的时间表(H1,图129)的第一线(橙色)的形象。
图129。图片2(绿线)对当前系统(M30)时间表与第3(棕色)线的形象是一致的一个较小的时限(M15,图128)和图像的第一行提出了更高的时间表(H1)(橙色)。
有一个分析指标roc.mq4的特殊性:每个率行进行,不仅价格变动率的价值,也取决于支持马的变化特征。一方面,这项技术可以直接在图表上,这是很方便的显示率线。另一方面,如果价格变动率的值太小,率线的建设的主要因素是支持马的价值,这是不可取的,因为每个均线有一定的滞后性。在未来的自定义指标是指标roc.mq4完整的模拟,但它是一个单独的窗口中绘制。这使得计算值率线,不同时限的不相配套的马,但相对水平的零线。因此,程序代码也改变了一点:无需计算支持MAS和使用比例系数。
自定义指标rocseparate.mq4 ROC(价格变动率)为当前的时间内,最近的较高和未来更高的时间表。显示在一个单独的窗口。
//-------------------------------------------------------------------- // rocseparate.mq4 (Priliv_s)
// The code should be used for educational purpose only.
//--------------------------------------------------------------- 1 -- #property copyright \ #property link \
//-------------------------------------------------------------------- #property indicator_separate_window // Indicator is drawn in a separate window #property indicator_buffers 6 // Number of buffers
#property indicator_color1 Black // Line color of 0 buffer #property indicator_color2 DarkOrange//Line color of the 1st buffer #property indicator_color3 Green // Line color of the 2nd buffer #property indicator_color4 Brown // Line color of the 3rd buffer #property indicator_color5 Blue // Line color of the 4th buffer #property indicator_color6 Red // Line color of the 5th buffer //--------------------------------------------------------------- 2 -- extern int History =5000; // Amount of bars in calculation history extern int Period_MA_1=21; // Period of calculated MA extern int Bars_V =13; // Amount of bars for calc. rate extern int Aver_Bars =5; // Amount of bars for smoothing //--------------------------------------------------------------- 3 -- int
Period_MA_2, Period_MA_3, // Calculation periods of MA for other timefr. K2, K3; // Coefficients of timeframe correlation double
Line_0[], // Indicator array of supp. MA Line_1[], Line_2[], Line_3[], // Indicator array of rate lines Line_4[], // Indicator array - sum
Line_5[], // Indicator array - sum, smoothed Sh_1, Sh_2, Sh_3; // Amount of bars for rates calc. //--------------------------------------------------------------- 4 -- int init() // Special function init() {
SetIndexBuffer(0,Line_0); // Assigning an array to a buffer SetIndexBuffer(1,Line_1); // Assigning an array to a buffer SetIndexBuffer(2,Line_2); // Assigning an array to a buffer SetIndexBuffer(3,Line_3); // Assigning an array to a buffer SetIndexBuffer(4,Line_4); // Assigning an array to a buffer SetIndexBuffer(5,Line_5); // Assigning an array to a buffer SetIndexStyle (5,DRAW_LINE,STYLE_SOLID,3);// Line style
//--------------------------------------------------------------- 5 -- switch(Period()) // Calculating coefficient for.. { // .. different timeframes case 1: K2=5;K3=15; break;// Timeframe M1 case 5: K2=3;K3= 6; break;// Timeframe M5 case 15: K2=2;K3= 4; break;// Timeframe M15 case 30: K2=2;K3= 8; break;// Timeframe M30
case 60: K2=4;K3=24; break;// Timeframe H1 case 240: K2=6;K3=42; break;// Timeframe H4 case 1440: K2=7;K3=30; break;// Timeframe D1 case 10080: K2=4;K3=12; break;// Timeframe W1 case 43200: K2=3;K3=12; break;// Timeframe MN }
//--------------------------------------------------------------- 6 -- Sh_1=Bars_V; // Period of rate calcul. (bars) Sh_2=K2*Sh_1; // Calc. period for nearest TF Sh_3=K3*Sh_1; // Calc. period for next TF
Period_MA_2 =K2*Period_MA_1; // Calc. period of MA for nearest TF Period_MA_3 =K3*Period_MA_1; // Calc. period of MA for next TF //--------------------------------------------------------------- 7 -- return; // Exit the special function init() }
//--------------------------------------------------------------- 8 -- int start() // Special function start() {
//--------------------------------------------------------------- 9 -- double
MA_c, MA_p, // Current and previous MA values Sum; // Technical param. for sum accumul. int
i, // Bar index
n, // Formal parameter (bar index) Counted_bars; // Amount of counted bars
//-------------------------------------------------------------- 10 -- Counted_bars=IndicatorCounted(); // Amount of counted bars i=Bars-Counted_bars-1; // Index of the first uncounted if (i i=History-1; // ..calculate specified amount //-------------------------------------------------------------- 11 -- while(i<=0) // Loop for uncounted bars { //-------------------------------------------------------- 12 -- Line_0[i]=0; // Horizontal reference line //-------------------------------------------------------- 13 -- MA_c=iMA(NULL,0,Period_MA_1,0,MODE_LWMA,PRICE_TYPICAL,i);