初学者的问题 MQL5 MT5 MetaTrader 5 - 页 919 1...912913914915916917918919920921922923924925926...1503 新评论 Igor Makanu 2018.09.04 20:04 #9181 Artyom Trishkin:你的指标计算 是从开始到结束(从最近的历史数据到最近的当前数据)。这是在时间序列中索引的一种表现。所以数组必须有相应的索引,这就是你的情况。 它有什么问题?它的工作方式与我从MQL4移植到MQL5中的方式相同,但我看到代码很难看,因为ArraySetAsSeries(),这就是为什么我问道 这里有两个代码 教我如何为MT5写这个指标!- 我的代码不是很好,句号!))) ZSZ不记得如何为MT5写指标,坐下来用帮助重写了40分钟,但结果......。我认为,不是那么好((! 附加的文件: PTL.mq4 8 kb PTL.mq5 13 kb Artyom Trishkin 2018.09.04 20:20 #9182 Igor Makanu:是的,一切都与我从MQL4移植到MQL5中的工作完全一样,但我看到代码很难看,因为ArraySetAsSeries(),所以我问道 这里有两个代码 教我如何为MT5写这个指标!- 我的代码不是很好,句号!)))当你反转循环时,你必须使数组成为时间序列,否则循环中缓冲区的索引将与所需数据的索引不一致--指标缓冲区数组中的循环索引将从开始到结束,而在open[]、high[]、low[]、close[]和其他中--从结束到开始。或者,你可以反转循环,使其与数组 open[]、high[]、low[]、close[]的索引 相匹配,其余的与缓冲区的索引相匹配,这就比较复杂了。 如果你想用一个寓言故事来说明问题,这里有一个寓言故事给你。 你站在铁轨上,看着两辆火车。它们要么是单向的--都是从左到右(ArraySetAsSeries(array,true)--第一列,以及从极限到0的循环--第二列)。 或者说,他们是相互走动的--(ArraySetAsSeries(array,false)--从右到左--第一列车,而从极限到0的循环--从左到右--第二列车)。 而且,是的:我没有翻看代码--我不想下载、保存(论坛上已经有很多不必要的代码),相互比较...... 把它们放在信息中的代码中会更容易一些--一个和第二个--那么它就会立刻看到什么是什么。 Igor Makanu 2018.09.04 20:28 #9183 Artyom Trishkin:或者翻转循环以匹配其对数组 open[]、high[]、low[]、close[]和其他部分的索引,这更难。我今天整晚都在倒车,我的耐心已经用完了(()。 就我对这个问题的理解而言。 - 在MT5中,分配给指标缓冲区的数组默认是从左到右索引的。 - 在MT5时间序列中,OnCalculate()中 的open[], high[], low[], close[] 总是从右到左传递索引。 - 即在步骤1和2的基础上,为了计算从历史结束到零条的指标 a)或重新分配缓冲区数组的索引 b) 或者做一个循环,其中数组元素将从左到右重新计算,在另一个循环中从右到左重新计算。 for(i=limit;i>=0;i--) { BufBarsBuffer1[limit - i] = open[i]; ... } 也就是说,我的问题没有漂亮的解决方案? 选项a)--在我的资料中已经实现了,选项b)--我看不出做额外计算的意义。 资源。 MT5。 //+------------------------------------------------------------------+ //| Perfect_Trend_Lines.mq5 | //| IgorM | //| | //+------------------------------------------------------------------+ #property version "1.00" #property indicator_chart_window #property indicator_buffers 9 #property indicator_plots 5 //--- plot BufBars #property indicator_label1 "BufBars" #property indicator_type1 DRAW_COLOR_BARS #property indicator_color1 clrRed,clrAqua,clrNONE #property indicator_style1 STYLE_SOLID #property indicator_width1 3 //--- plot BufASELL #property indicator_label2 "BufASELL" #property indicator_type2 DRAW_ARROW #property indicator_color2 clrBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 5 //--- plot BufABUY #property indicator_label3 "BufABUY" #property indicator_type3 DRAW_ARROW #property indicator_color3 clrRed #property indicator_style3 STYLE_SOLID #property indicator_width3 5 //--- plot BufLSELL #property indicator_label4 "BufLSELL" #property indicator_type4 DRAW_LINE #property indicator_color4 clrBlue #property indicator_style4 STYLE_SOLID #property indicator_width4 2 //--- plot BufLBUY #property indicator_label5 "BufLBUY" #property indicator_type5 DRAW_LINE #property indicator_color5 clrRed #property indicator_style5 STYLE_SOLID #property indicator_width5 2 //--- input parameters input int SlowLength = 7; //Slow length input int SlowPipDisplace = 0; //Slow pip displace input int FastLength = 3; //Fast length input int FastPipDisplace = 0; //Fast pip displace //--- indicator buffers double BufBarsBuffer1[]; double BufBarsBuffer2[]; double BufBarsBuffer3[]; double BufBarsBuffer4[]; double BufBarsColors[]; double BufASELLBuffer[]; double BufABUYBuffer[]; double BufLSELLBuffer[]; double BufLBUYBuffer[]; static int trend=0; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- indicator buffers mapping SetIndexBuffer(0,BufBarsBuffer1,INDICATOR_DATA); SetIndexBuffer(1,BufBarsBuffer2,INDICATOR_DATA); SetIndexBuffer(2,BufBarsBuffer3,INDICATOR_DATA); SetIndexBuffer(3,BufBarsBuffer4,INDICATOR_DATA); SetIndexBuffer(4,BufBarsColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(5,BufASELLBuffer,INDICATOR_DATA); SetIndexBuffer(6,BufABUYBuffer,INDICATOR_DATA); SetIndexBuffer(7,BufLSELLBuffer,INDICATOR_DATA); SetIndexBuffer(8,BufLBUYBuffer,INDICATOR_DATA); for(int i=0;i<9;i++) { PlotIndexSetInteger(i,PLOT_DRAW_BEGIN,FastLength+1); PlotIndexSetDouble(i,PLOT_EMPTY_VALUE,0.0); } ArraySetAsSeries(BufBarsBuffer1,true); ArraySetAsSeries(BufBarsBuffer2,true); ArraySetAsSeries(BufBarsBuffer3,true); ArraySetAsSeries(BufBarsBuffer4,true); ArraySetAsSeries(BufBarsColors,true); ArraySetAsSeries(BufABUYBuffer,true); ArraySetAsSeries(BufASELLBuffer,true); ArraySetAsSeries(BufLBUYBuffer,true); ArraySetAsSeries(BufLSELLBuffer,true); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(1,PLOT_ARROW,234); PlotIndexSetInteger(2,PLOT_ARROW,233); PlotIndexSetInteger(1,PLOT_ARROW_SHIFT,-20); PlotIndexSetInteger(2,PLOT_ARROW_SHIFT,20); trend=0; //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { //--- int i,limit; double thigh1,tlow1,thigh2,tlow2,trendUp,trendDn; ArraySetAsSeries(open,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); if(prev_calculated==0) { limit=rates_total-1; BufLSELLBuffer[limit]=high[limit]; BufLBUYBuffer[limit]=low[limit]; limit--; } else limit=rates_total-prev_calculated+1; for(i=limit;i>=0;i--) { thigh1= high[iHighest(NULL,0,MODE_HIGH,SlowLength,i)]+SlowPipDisplace * _Point; tlow1 = low[iLowest(NULL,0,MODE_LOW,SlowLength,i)]-SlowPipDisplace * _Point; thigh2= high[iHighest(NULL,0,MODE_HIGH,FastLength,i)]+FastPipDisplace * _Point; tlow2 = low[iLowest(NULL,0,MODE_LOW,FastLength,i)]-FastPipDisplace * _Point; if(close[i]>BufLBUYBuffer[i+1]) trendUp=tlow1; else trendUp=thigh1; if(close[i]>BufLSELLBuffer[i+1]) trendDn=tlow2; else trendDn=thigh2; BufLSELLBuffer[i]= trendDn; BufLBUYBuffer[i] = trendUp; BufBarsBuffer1[i] = 0.0; BufBarsBuffer2[i] = 0.0; BufBarsBuffer3[i] = 0.0; BufBarsBuffer4[i] = 0.0; BufBarsColors[i] = 2; if(close[i]<trendUp && close[i]<trendDn) { BufBarsBuffer1[i] = open[i]; BufBarsBuffer2[i] = high[i]; BufBarsBuffer3[i] = low[i]; BufBarsBuffer4[i] = close[i]; BufBarsColors[i] = 0; } if(close[i]>trendUp && close[i]>trendDn) { BufBarsBuffer1[i] = open[i]; BufBarsBuffer2[i] = high[i]; BufBarsBuffer3[i] = low[i]; BufBarsBuffer4[i] = close[i]; BufBarsColors[i] = 1; } if(close[i]>trendUp && close[i]>trendDn && trend!=1) { BufABUYBuffer[i]=trendDn; BufASELLBuffer[i]=0.0; trend=1; } if(close[i]<trendUp && close[i]<trendDn && trend!=2) { BufASELLBuffer[i]=trendUp; BufABUYBuffer[i]=0.0; trend=2; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+MT4。 //+------------------------------------------------------------------+ //| PerfecTrend Lines.mq4 | //| Copyright © 2005-2007, MetaQuotes Software Corp. | //+------------------------------------------------------------------+ #property copyright "Copyright © 2007, MetaQuotes Software Corp." #property indicator_chart_window #property indicator_buffers 6 #property indicator_color1 Red #property indicator_color2 Blue #property indicator_color3 Red #property indicator_color4 Aqua #property indicator_color5 Blue #property indicator_color6 Red extern int SlowLength = 7; // Slow length extern int SlowPipDisplace = 0; // Slow pip displace extern int FastLength = 3; // Fast length extern int FastPipDisplace = 0; // Fast pip displace double Buf_NTLine1[],Buf_NTLine2[],Buf_NTBar1[],Buf_NTBar2[],Buf_NTSig1[],Buf_NTSig2[]; static int trend=0; //+------------------------------------------------------------------+ int init() { IndicatorBuffers(6); IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)); SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2); SetIndexBuffer(0,Buf_NTLine1); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,2); SetIndexBuffer(1,Buf_NTLine2); SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2); SetIndexBuffer(2,Buf_NTBar1); SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_SOLID,2); SetIndexBuffer(3,Buf_NTBar2); SetIndexStyle(4,DRAW_ARROW,STYLE_DASH,3); SetIndexArrow(4,108); SetIndexBuffer(4,Buf_NTSig1); SetIndexStyle(5,DRAW_ARROW,STYLE_DASH,3); SetIndexArrow(5,108); SetIndexBuffer(5,Buf_NTSig2); IndicatorShortName("NeuroTrend"); SetIndexLabel(0,"NTLine1"); SetIndexLabel(1,"NTLine2"); SetIndexLabel(2,"NTBar1"); SetIndexLabel(3,"NTBar2"); SetIndexLabel(4,"NTSig1"); SetIndexLabel(5,"NTSig2"); SetIndexDrawBegin(0,FastLength+1); SetIndexDrawBegin(1,FastLength+1); SetIndexDrawBegin(2,FastLength+1); SetIndexDrawBegin(3,FastLength+1); SetIndexDrawBegin(4,FastLength+1); SetIndexDrawBegin(5,FastLength+1); trend=0; return (0); } //+------------------------------------------------------------------+ int deinit() { return (0); } //+------------------------------------------------------------------+ int start() { int i,limit; double thigh1,tlow1,thigh2,tlow2,trendA,trendB,trendUP,trendDN; if(Bars <= FastLength) return (0); if(IndicatorCounted()==0) limit=Bars-1; if(IndicatorCounted()>0) limit=Bars-IndicatorCounted()-1; for(i=limit;i>=0;i--) { thigh1= High[iHighest(NULL,0,MODE_HIGH,SlowLength,i)]+SlowPipDisplace * Point; tlow1 = Low[iLowest(NULL,0,MODE_LOW,SlowLength,i)]-SlowPipDisplace * Point; thigh2= High[iHighest(NULL,0,MODE_HIGH,FastLength,i)]+FastPipDisplace * Point; tlow2 = Low[iLowest(NULL,0,MODE_LOW,FastLength,i)]-FastPipDisplace * Point; if(Close[i] > Buf_NTLine1[i+1]) trendA = tlow1; else trendA = thigh1; if(Close[i] > Buf_NTLine2[i+1]) trendB = tlow2; else trendB = thigh2; Buf_NTLine1[i] = trendA; Buf_NTLine2[i] = trendB; trendUP = 0.0; trendDN = 0.0; if(Close[i] < trendA && Close[i] < trendB) { trendUP = High[i]; trendDN = Low[i]; } if(Close[i] > trendA && Close[i] > trendB) { trendUP = Low[i]; trendDN = High[i];} Buf_NTBar1[i] = trendUP; Buf_NTBar2[i] = trendDN; if(Close[i] > trendB && Close[i] > trendA && trend != 1) { Buf_NTSig1[i] = trendB; Buf_NTSig2[i] = EMPTY_VALUE; trend = 1; } if(Close[i] < trendB && Close[i] < trendA && trend != 2) { Buf_NTSig2[i] = trendB; Buf_NTSig1[i] = EMPTY_VALUE; trend = 2; } } return (0); } //+------------------------------------------------------------------+ Artyom Trishkin 2018.09.04 20:36 #9184 Igor Makanu:我今晚翻了一晚上,但我的耐心已经用完了(()。 就我对问题的理解而言。 - 在MT5中,分配给指标缓冲区的数组默认是从左到右索引的。 - 在MT5时间序列中,OnCalculate()中 的open[], high[], low[], close[] 总是从右到左传递索引。 - 即在步骤1和2的基础上,为了计算从历史结束到零条的指标 a)或重新分配缓冲区数组的索引 b) 或者做一个循环,其中数组元素将从左到右重新计算,在另一个循环中从右到左重新计算。 也就是说,我的问题没有漂亮的解决方案? 变体a)--在我的资料中已经实现,变体b)--我不认为有必要做额外的计算。所有数组的索引都是从右到左。因此,为了完全遵守从左到右的循环(而且是从左到右--从极限到0),你需要将所有使用的数组设置为所需的索引:缓冲区 在OnInit(),使用的时间服务器--在OnCalculate()。 或者,做从0到极限的循环,当从mql4移植到mql5时,这并不容易做到。 因此,在这种情况下,ArraySetAsSeries()选项更好。 Igor Makanu 2018.09.04 20:48 #9185 Artyom Trishkin:所有数组的索引都是从右到左。因此,为了完全遵守从左到右的循环(而且是从左到右从极限到0),你需要将所有使用的数组设置为所需的索引: 在OnInit()中的缓冲区,使用的时间服务器--在OnCalculate()中。 或者,你必须做从0到极限的循环,当mql4被移植到mql5时,这并不容易做到。 这就是为什么在这种情况下,ArraySetAsSeries()方法效果更好。看,从你的代码中删除所有ArraySetAsSeries()(上面Init()和 OnCalculate()中的第一行),并纠正了循环。 for(i=0;i<limit;i++)理论上说,所有的东西都应该合在一起!但是没有!图表的结果是不同的--这是我不能理解的地方。 附加的文件: 1.jpg 747 kb Artyom Trishkin 2018.09.04 20:57 #9186 Igor Makanu:看,我把所有ArraySetAsSeries() 从我的代码中删除了(在Init()的顶部和 OnCalculate()的第一行中),并修复了这个循环。 for(i=0;i<limit;i++)从理论上讲,所有的东西都应该合在一起!但是没有!图表的结果是不同的,而这正是我无法理解的地方!"。我告诉你--它比这更复杂。你必须改变逻辑。仅仅反转循环是不够的。 这里有一个小例子:在代码中,有 Buf_NTLine1[i+1]) 当数组的索引 不同时,i+1的索引将去哪里? 而且有很多这样的情况。IHighest() - 开始和数字。一个指数化的起点在哪里,另一个指数化的起点在哪里? 以此类推......。 Igor Makanu 2018.09.04 21:09 #9187 Artyom Trishkin: 而且有很多。在一个索引和另一个索引中,它从哪里开始?哦,伙计!这是正确的!做得好!!是的,这是棘手的部分!!!。 是啊...MT5有很多不同之处,在程序员的头上有很多检查和各种预防措施... 前段时间我看到这条消息,在MT5中,似乎并不是所有的东西都能在Init() 中正确初始化,似乎Init()可能在时间段还没有准备好的时候就结束了。 我昨天看到一个bug:如果这个指标在MT5中切换时间段,有时指标缓冲区 可能不是空的--似乎旧的值仍然存在,如果不在OnCalculate()中给指标数组中的每个元素分配一个特定的值,我试着把 ArrayInitialize(arr, 0.0)放在Init() 中--它也能工作,然后不... 就我的理解而言,是正确的。 - 在MT5中,在Init()初始化时,指标缓冲区没有自动初始化?(在MT4中,我不记得有什么东西留在缓冲区内。) - 在MT5的Init()中,如果没有加载历史记录,缓冲区数组的大小可能是未知的,这就是为什么ArrayInitialize(arr, 0.0)也不总是正确地初始化缓冲区? Artyom Trishkin 2018.09.04 22:18 #9188 Igor Makanu:该死的!这就对了!做得很好!是的,这才是有趣的部分!!!。 是啊...MT5有很多不同之处,有很多检查和各种预防措施在程序员的头上... 前段时间我看到这条消息,在MT5中,似乎并不是所有的东西都能在Init() 中正确初始化,似乎Init()可能在时间段还没有准备好的时候就结束了。 我昨天看到一个bug:如果这个指标在MT5中切换时间段,有时指标缓冲区 可能不是空的--似乎旧的值仍然存在,如果不在OnCalculate()中给指标数组中的每个元素分配一个特定的值,我试着把 ArrayInitialize(arr, 0.0)放在Init() 中--它也能工作,然后不... 就我的理解而言,是正确的。 - 在MT5中,在Init()初始化时,指标缓冲区没有自动初始化?(在MT4中,我不记得有什么东西留在缓冲区内。) - 在MT5的Init()中,如果没有加载历史记录,缓冲区数组的大小可能是未知的,这就是为什么ArrayInitialize(arr, 0.0)也不总是正确地初始化缓冲区?//+------------------------------------------------------------------+ //| PerfecTrend Lines.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://mql5.com/ru/users/artmedia70 | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://mql5.com/ru/users/artmedia70" #property version "1.00" #property indicator_chart_window #property indicator_buffers 9 #property indicator_plots 5 //--- plot Top #property indicator_label1 "Top" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Bottom #property indicator_label2 "Bottom" #property indicator_type2 DRAW_LINE #property indicator_color2 clrBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot Candles #property indicator_label3 "Open;High;Low;Close" #property indicator_type3 DRAW_COLOR_CANDLES #property indicator_color3 clrDodgerBlue,clrOrangeRed,clrDarkGray #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- plot ArrowUP #property indicator_label4 "ArrowUP" #property indicator_type4 DRAW_ARROW #property indicator_color4 clrRed #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- plot ArrowDN #property indicator_label5 "ArrowDN" #property indicator_type5 DRAW_ARROW #property indicator_color5 clrBlue #property indicator_style5 STYLE_SOLID #property indicator_width5 1 //--- input parameters input uint InpPeriodSlow = 7; // Slow length input uint InpDistanceSlow = 0; // Slow pip displace input uint InpPeriodFast = 3; // Fast length input uint InpDistanceFast = 0; // Fast pip displace //--- indicator buffers double BufferTop[]; double BufferBottom[]; double BufferCandlesOpen[]; double BufferCandlesHigh[]; double BufferCandlesLow[]; double BufferCandlesClose[]; double BufferColors[]; double BufferArrowUP[]; double BufferArrowDN[]; //--- global variables int period_slow; int period_fast; int period_max; double distance_slow; double distance_fast; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- set global variables period_fast=int(InpPeriodFast<1 ? 1 : InpPeriodFast); period_slow=int(InpPeriodSlow<1 ? 1 : InpPeriodSlow); period_max=fmax(period_fast,period_slow); distance_fast=InpDistanceFast*Point(); distance_slow=InpDistanceSlow*Point(); //--- indicator buffers mapping SetIndexBuffer(0,BufferTop,INDICATOR_DATA); SetIndexBuffer(1,BufferBottom,INDICATOR_DATA); SetIndexBuffer(2,BufferCandlesOpen,INDICATOR_DATA); SetIndexBuffer(3,BufferCandlesHigh,INDICATOR_DATA); SetIndexBuffer(4,BufferCandlesLow,INDICATOR_DATA); SetIndexBuffer(5,BufferCandlesClose,INDICATOR_DATA); SetIndexBuffer(6,BufferColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(7,BufferArrowUP,INDICATOR_DATA); SetIndexBuffer(8,BufferArrowDN,INDICATOR_DATA); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(3,PLOT_ARROW,108); PlotIndexSetInteger(4,PLOT_ARROW,108); //--- setting indicator parameters IndicatorSetString(INDICATOR_SHORTNAME,"NeuroTrend"); IndicatorSetInteger(INDICATOR_DIGITS,Digits()); //--- setting buffer arrays as timeseries ArraySetAsSeries(BufferTop,true); ArraySetAsSeries(BufferBottom,true); ArraySetAsSeries(BufferCandlesOpen,true); ArraySetAsSeries(BufferCandlesHigh,true); ArraySetAsSeries(BufferCandlesLow,true); ArraySetAsSeries(BufferCandlesClose,true); ArraySetAsSeries(BufferColors,true); ArraySetAsSeries(BufferArrowUP,true); ArraySetAsSeries(BufferArrowDN,true); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { //--- Установка массивов буферов как таймсерий ArraySetAsSeries(open,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); //--- Проверка и расчёт количества просчитываемых баров if(rates_total<fmax(period_max,4)) return 0; int limit=rates_total-prev_calculated; if(limit>1) { limit=rates_total-period_max-1; ArrayInitialize(BufferTop,EMPTY_VALUE); ArrayInitialize(BufferBottom,EMPTY_VALUE); ArrayInitialize(BufferCandlesOpen,EMPTY_VALUE); ArrayInitialize(BufferCandlesHigh,EMPTY_VALUE); ArrayInitialize(BufferCandlesLow,EMPTY_VALUE); ArrayInitialize(BufferCandlesClose,EMPTY_VALUE); ArrayInitialize(BufferArrowUP,EMPTY_VALUE); ArrayInitialize(BufferArrowDN,EMPTY_VALUE); } //--- for(int i=limit; i>=0 && !IsStopped(); i--) { int bhs=Highest(period_slow,i); int bls=Lowest(period_slow,i); int bhf=Highest(period_fast,i); int blf=Lowest(period_fast,i); if(bhs==WRONG_VALUE || bls==WRONG_VALUE || bhf==WRONG_VALUE || blf==WRONG_VALUE) continue; double thigh1=high[bhs]+distance_slow; double tlow1=low[bls]-distance_slow; double thigh2=high[bhf]+distance_fast; double tlow2=low[blf]-distance_fast; double trendA=(close[i]>BufferTop[i+1] ? tlow1 : thigh1); double trendB=(close[i]>BufferBottom[i+1] ? tlow2 : thigh2); BufferTop[i]=trendA; BufferBottom[i]=trendB; double trendUP=0; double trendDN=0; BufferCandlesOpen[i]=open[i]; BufferCandlesHigh[i]=high[i]; BufferCandlesLow[i]=low[i]; BufferCandlesClose[i]=close[i]; BufferColors[i]=2; if(close[i]<trendA && close[i]<trendB) { BufferColors[i]=1; trendUP=high[i]; trendDN=low[i]; } else if(close[i]>trendA && close[i]>trendB) { BufferColors[i]=0; trendUP=low[i]; trendDN=high[i]; } else { BufferCandlesOpen[i]=EMPTY_VALUE; BufferCandlesHigh[i]=EMPTY_VALUE; BufferCandlesLow[i]=EMPTY_VALUE; BufferCandlesClose[i]=EMPTY_VALUE; } static int trend=0; BufferArrowUP[i]=BufferArrowDN[i]=EMPTY_VALUE; if(close[i]>trendB && close[i]>trendA && trend!=1) { BufferArrowDN[i]=trendB; BufferArrowUP[i]=EMPTY_VALUE; trend=1; } if(close[i]<trendB && close[i]<trendA && trend!=2) { BufferArrowUP[i]=trendB; BufferArrowDN[i]=EMPTY_VALUE; trend=2; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Возвращает индекс максимального значения таймсерии High | //+------------------------------------------------------------------+ int Highest(const int count,const int start,const bool as_series=true) { double array[]; ArraySetAsSeries(array,as_series); return(CopyHigh(NULL,PERIOD_CURRENT,start,count,array)==count ? ArrayMaximum(array)+start : WRONG_VALUE); } //+------------------------------------------------------------------+ //| Возвращает индекс минимального значения таймсерии Low | //+------------------------------------------------------------------+ int Lowest(const int count,const int start,const bool as_series=true) { double array[]; ArraySetAsSeries(array,as_series); return(CopyLow(NULL,PERIOD_CURRENT,start,count,array)==count ? ArrayMinimum(array)+start : WRONG_VALUE); } //+------------------------------------------------------------------+ 没有真正进入它的逻辑。 Artyom Trishkin 2018.09.04 22:35 #9189 Artyom Trishkin: 没有真正进入它的逻辑。这是正确的方法:不要把进场点放在最大/最小的价格上--最好放在开盘价 上。 //+------------------------------------------------------------------+ //| PerfecTrend Lines.mq5 | //| Copyright 2018, MetaQuotes Software Corp. | //| https://mql5.com/ru/users/artmedia70 | //+------------------------------------------------------------------+ #property copyright "Copyright 2018, MetaQuotes Software Corp." #property link "https://mql5.com/ru/users/artmedia70" #property version "1.00" #property indicator_chart_window #property indicator_buffers 9 #property indicator_plots 5 //--- plot Top #property indicator_label1 "Top" #property indicator_type1 DRAW_LINE #property indicator_color1 clrRed #property indicator_style1 STYLE_SOLID #property indicator_width1 1 //--- plot Bottom #property indicator_label2 "Bottom" #property indicator_type2 DRAW_LINE #property indicator_color2 clrBlue #property indicator_style2 STYLE_SOLID #property indicator_width2 1 //--- plot Candles #property indicator_label3 "Open;High;Low;Close" #property indicator_type3 DRAW_COLOR_CANDLES #property indicator_color3 clrDodgerBlue,clrOrangeRed,clrDarkGray #property indicator_style3 STYLE_SOLID #property indicator_width3 1 //--- plot ArrowUP #property indicator_label4 "ArrowUP" #property indicator_type4 DRAW_ARROW #property indicator_color4 clrRed #property indicator_style4 STYLE_SOLID #property indicator_width4 1 //--- plot ArrowDN #property indicator_label5 "ArrowDN" #property indicator_type5 DRAW_ARROW #property indicator_color5 clrBlue #property indicator_style5 STYLE_SOLID #property indicator_width5 1 //--- input parameters input uint InpPeriodSlow = 7; // Slow length input uint InpDistanceSlow = 0; // Slow pip displace input uint InpPeriodFast = 3; // Fast length input uint InpDistanceFast = 0; // Fast pip displace //--- indicator buffers double BufferTop[]; double BufferBottom[]; double BufferCandlesOpen[]; double BufferCandlesHigh[]; double BufferCandlesLow[]; double BufferCandlesClose[]; double BufferColors[]; double BufferArrowUP[]; double BufferArrowDN[]; //--- global variables int period_slow; int period_fast; int period_max; double distance_slow; double distance_fast; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- set global variables period_fast=int(InpPeriodFast<1 ? 1 : InpPeriodFast); period_slow=int(InpPeriodSlow<1 ? 1 : InpPeriodSlow); period_max=fmax(period_fast,period_slow); distance_fast=InpDistanceFast*Point(); distance_slow=InpDistanceSlow*Point(); //--- indicator buffers mapping SetIndexBuffer(0,BufferTop,INDICATOR_DATA); SetIndexBuffer(1,BufferBottom,INDICATOR_DATA); SetIndexBuffer(2,BufferCandlesOpen,INDICATOR_DATA); SetIndexBuffer(3,BufferCandlesHigh,INDICATOR_DATA); SetIndexBuffer(4,BufferCandlesLow,INDICATOR_DATA); SetIndexBuffer(5,BufferCandlesClose,INDICATOR_DATA); SetIndexBuffer(6,BufferColors,INDICATOR_COLOR_INDEX); SetIndexBuffer(7,BufferArrowUP,INDICATOR_DATA); SetIndexBuffer(8,BufferArrowDN,INDICATOR_DATA); //--- setting a code from the Wingdings charset as the property of PLOT_ARROW PlotIndexSetInteger(3,PLOT_ARROW,108); PlotIndexSetInteger(4,PLOT_ARROW,108); //--- setting indicator parameters IndicatorSetString(INDICATOR_SHORTNAME,"NeuroTrend"); IndicatorSetInteger(INDICATOR_DIGITS,Digits()); //--- setting buffer arrays as timeseries ArraySetAsSeries(BufferTop,true); ArraySetAsSeries(BufferBottom,true); ArraySetAsSeries(BufferCandlesOpen,true); ArraySetAsSeries(BufferCandlesHigh,true); ArraySetAsSeries(BufferCandlesLow,true); ArraySetAsSeries(BufferCandlesClose,true); ArraySetAsSeries(BufferColors,true); ArraySetAsSeries(BufferArrowUP,true); ArraySetAsSeries(BufferArrowDN,true); //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| 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[]) { //--- Установка массивов буферов как таймсерий ArraySetAsSeries(open,true); ArraySetAsSeries(high,true); ArraySetAsSeries(low,true); ArraySetAsSeries(close,true); //--- Проверка и расчёт количества просчитываемых баров if(rates_total<fmax(period_max,4)) return 0; int limit=rates_total-prev_calculated; if(limit>1) { limit=rates_total-period_max-1; ArrayInitialize(BufferTop,EMPTY_VALUE); ArrayInitialize(BufferBottom,EMPTY_VALUE); ArrayInitialize(BufferCandlesOpen,EMPTY_VALUE); ArrayInitialize(BufferCandlesHigh,EMPTY_VALUE); ArrayInitialize(BufferCandlesLow,EMPTY_VALUE); ArrayInitialize(BufferCandlesClose,EMPTY_VALUE); ArrayInitialize(BufferArrowUP,EMPTY_VALUE); ArrayInitialize(BufferArrowDN,EMPTY_VALUE); } //--- for(int i=limit; i>=0 && !IsStopped(); i--) { int bhs=Highest(period_slow,i); int bls=Lowest(period_slow,i); int bhf=Highest(period_fast,i); int blf=Lowest(period_fast,i); if(bhs==WRONG_VALUE || bls==WRONG_VALUE || bhf==WRONG_VALUE || blf==WRONG_VALUE) continue; double thigh1=high[bhs]+distance_slow; double tlow1=low[bls]-distance_slow; double thigh2=high[bhf]+distance_fast; double tlow2=low[blf]-distance_fast; double trendA=(close[i]>BufferTop[i+1] ? tlow1 : thigh1); double trendB=(close[i]>BufferBottom[i+1] ? tlow2 : thigh2); BufferTop[i]=trendA; BufferBottom[i]=trendB; BufferCandlesOpen[i]=open[i]; BufferCandlesHigh[i]=high[i]; BufferCandlesLow[i]=low[i]; BufferCandlesClose[i]=close[i]; BufferColors[i]=2; if(close[i]<trendA && close[i]<trendB) BufferColors[i]=1; else if(close[i]>trendA && close[i]>trendB) BufferColors[i]=0; else { BufferCandlesOpen[i]=EMPTY_VALUE; BufferCandlesHigh[i]=EMPTY_VALUE; BufferCandlesLow[i]=EMPTY_VALUE; BufferCandlesClose[i]=EMPTY_VALUE; } static int trend=0; BufferArrowUP[i]=BufferArrowDN[i]=EMPTY_VALUE; if(close[i]>trendB && close[i]>trendA && trend!=1) { BufferArrowDN[i]=open[i]; BufferArrowUP[i]=EMPTY_VALUE; trend=1; } if(close[i]<trendB && close[i]<trendA && trend!=2) { BufferArrowUP[i]=open[i]; BufferArrowDN[i]=EMPTY_VALUE; trend=2; } } //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Возвращает индекс максимального значения таймсерии High | //+------------------------------------------------------------------+ int Highest(const int count,const int start,const bool as_series=true) { double array[]; ArraySetAsSeries(array,as_series); return(CopyHigh(NULL,PERIOD_CURRENT,start,count,array)==count ? ArrayMaximum(array)+start : WRONG_VALUE); } //+------------------------------------------------------------------+ //| Возвращает индекс минимального значения таймсерии Low | //+------------------------------------------------------------------+ int Lowest(const int count,const int start,const bool as_series=true) { double array[]; ArraySetAsSeries(array,as_series); return(CopyLow(NULL,PERIOD_CURRENT,start,count,array)==count ? ArrayMinimum(array)+start : WRONG_VALUE); } //+------------------------------------------------------------------+ 而且这些线应该被删除--它们在图表上是为了什么?如果只是为了拖住他们? Juer 2018.09.06 07:36 #9190 无类型的声明 如果我编译一个include文件,就不会有错误。如果我编译包含这个include文件的主程序文件,就会出现一个没有类型的声明错误。它没有看到include文件中声明的对象,protected CSomeClass *object。该包含文件有#include "SomeClass.mqh "指令。而在主文件中,创建了一个 包含文件的类的对象,并调用了其中的一个方法。 1...912913914915916917918919920921922923924925926...1503 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
你的指标计算 是从开始到结束(从最近的历史数据到最近的当前数据)。这是在时间序列中索引的一种表现。所以数组必须有相应的索引,这就是你的情况。
它有什么问题?
它的工作方式与我从MQL4移植到MQL5中的方式相同,但我看到代码很难看,因为ArraySetAsSeries(),这就是为什么我问道
这里有两个代码
教我如何为MT5写这个指标!- 我的代码不是很好,句号!)))
ZSZ不记得如何为MT5写指标,坐下来用帮助重写了40分钟,但结果......。我认为,不是那么好((!
是的,一切都与我从MQL4移植到MQL5中的工作完全一样,但我看到代码很难看,因为ArraySetAsSeries(),所以我问道
这里有两个代码
教我如何为MT5写这个指标!- 我的代码不是很好,句号!)))
当你反转循环时,你必须使数组成为时间序列,否则循环中缓冲区的索引将与所需数据的索引不一致--指标缓冲区数组中的循环索引将从开始到结束,而在open[]、high[]、low[]、close[]和其他中--从结束到开始。或者,你可以反转循环,使其与数组 open[]、high[]、low[]、close[]的索引 相匹配,其余的与缓冲区的索引相匹配,这就比较复杂了。
如果你想用一个寓言故事来说明问题,这里有一个寓言故事给你。
你站在铁轨上,看着两辆火车。它们要么是单向的--都是从左到右(ArraySetAsSeries(array,true)--第一列,以及从极限到0的循环--第二列)。
或者说,他们是相互走动的--(ArraySetAsSeries(array,false)--从右到左--第一列车,而从极限到0的循环--从左到右--第二列车)。
而且,是的:我没有翻看代码--我不想下载、保存(论坛上已经有很多不必要的代码),相互比较......
把它们放在信息中的代码中会更容易一些--一个和第二个--那么它就会立刻看到什么是什么。
或者翻转循环以匹配其对数组 open[]、high[]、low[]、close[]和其他部分的索引,这更难。
我今天整晚都在倒车,我的耐心已经用完了(()。
就我对这个问题的理解而言。
- 在MT5中,分配给指标缓冲区的数组默认是从左到右索引的。
- 在MT5时间序列中,OnCalculate()中 的open[], high[], low[], close[] 总是从右到左传递索引。
- 即在步骤1和2的基础上,为了计算从历史结束到零条的指标
a)或重新分配缓冲区数组的索引
b) 或者做一个循环,其中数组元素将从左到右重新计算,在另一个循环中从右到左重新计算。
也就是说,我的问题没有漂亮的解决方案? 选项a)--在我的资料中已经实现了,选项b)--我看不出做额外计算的意义。
资源。
MT5。
MT4。
我今晚翻了一晚上,但我的耐心已经用完了(()。
就我对问题的理解而言。
- 在MT5中,分配给指标缓冲区的数组默认是从左到右索引的。
- 在MT5时间序列中,OnCalculate()中 的open[], high[], low[], close[] 总是从右到左传递索引。
- 即在步骤1和2的基础上,为了计算从历史结束到零条的指标
a)或重新分配缓冲区数组的索引
b) 或者做一个循环,其中数组元素将从左到右重新计算,在另一个循环中从右到左重新计算。
也就是说,我的问题没有漂亮的解决方案? 变体a)--在我的资料中已经实现,变体b)--我不认为有必要做额外的计算。
所有数组的索引都是从右到左。因此,为了完全遵守从左到右的循环(而且是从左到右--从极限到0),你需要将所有使用的数组设置为所需的索引:缓冲区 在OnInit(),使用的时间服务器--在OnCalculate()。
或者,做从0到极限的循环,当从mql4移植到mql5时,这并不容易做到。
因此,在这种情况下,ArraySetAsSeries()选项更好。
所有数组的索引都是从右到左。因此,为了完全遵守从左到右的循环(而且是从左到右从极限到0),你需要将所有使用的数组设置为所需的索引: 在OnInit()中的缓冲区,使用的时间服务器--在OnCalculate()中。
或者,你必须做从0到极限的循环,当mql4被移植到mql5时,这并不容易做到。
这就是为什么在这种情况下,ArraySetAsSeries()方法效果更好。
看,从你的代码中删除所有ArraySetAsSeries()(上面Init()和 OnCalculate()中的第一行),并纠正了循环。
for(i=0;i<limit;i++)
理论上说,所有的东西都应该合在一起!但是没有!图表的结果是不同的--这是我不能理解的地方。
看,我把所有ArraySetAsSeries() 从我的代码中删除了(在Init()的顶部和 OnCalculate()的第一行中),并修复了这个循环。
for(i=0;i<limit;i++)
从理论上讲,所有的东西都应该合在一起!但是没有!图表的结果是不同的,而这正是我无法理解的地方!"。
我告诉你--它比这更复杂。你必须改变逻辑。仅仅反转循环是不够的。
这里有一个小例子:在代码中,有
Buf_NTLine1[i+1])
当数组的索引 不同时,i+1的索引将去哪里?
而且有很多这样的情况。IHighest() - 开始和数字。一个指数化的起点在哪里,另一个指数化的起点在哪里?
以此类推......。
而且有很多。在一个索引和另一个索引中,它从哪里开始?
哦,伙计!这是正确的!做得好!!是的,这是棘手的部分!!!。
是啊...MT5有很多不同之处,在程序员的头上有很多检查和各种预防措施...
前段时间我看到这条消息,在MT5中,似乎并不是所有的东西都能在Init() 中正确初始化,似乎Init()可能在时间段还没有准备好的时候就结束了。
我昨天看到一个bug:如果这个指标在MT5中切换时间段,有时指标缓冲区 可能不是空的--似乎旧的值仍然存在,如果不在OnCalculate()中给指标数组中的每个元素分配一个特定的值,我试着把 ArrayInitialize(arr, 0.0)放在Init() 中--它也能工作,然后不...
就我的理解而言,是正确的。
- 在MT5中,在Init()初始化时,指标缓冲区没有自动初始化?(在MT4中,我不记得有什么东西留在缓冲区内。)
- 在MT5的Init()中,如果没有加载历史记录,缓冲区数组的大小可能是未知的,这就是为什么ArrayInitialize(arr, 0.0)也不总是正确地初始化缓冲区?
该死的!这就对了!做得很好!是的,这才是有趣的部分!!!。
是啊...MT5有很多不同之处,有很多检查和各种预防措施在程序员的头上...
前段时间我看到这条消息,在MT5中,似乎并不是所有的东西都能在Init() 中正确初始化,似乎Init()可能在时间段还没有准备好的时候就结束了。
我昨天看到一个bug:如果这个指标在MT5中切换时间段,有时指标缓冲区 可能不是空的--似乎旧的值仍然存在,如果不在OnCalculate()中给指标数组中的每个元素分配一个特定的值,我试着把 ArrayInitialize(arr, 0.0)放在Init() 中--它也能工作,然后不...
就我的理解而言,是正确的。
- 在MT5中,在Init()初始化时,指标缓冲区没有自动初始化?(在MT4中,我不记得有什么东西留在缓冲区内。)
- 在MT5的Init()中,如果没有加载历史记录,缓冲区数组的大小可能是未知的,这就是为什么ArrayInitialize(arr, 0.0)也不总是正确地初始化缓冲区?
没有真正进入它的逻辑。
没有真正进入它的逻辑。
这是正确的方法:不要把进场点放在最大/最小的价格上--最好放在开盘价 上。
而且这些线应该被删除--它们在图表上是为了什么?如果只是为了拖住他们?
无类型的声明
如果我编译一个include文件,就不会有错误。如果我编译包含这个include文件的主程序文件,就会出现一个没有类型的声明错误。它没有看到include文件中声明的对象,protected CSomeClass *object。该包含文件有#include "SomeClass.mqh "指令。而在主文件中,创建了一个 包含文件的类的对象,并调用了其中的一个方法。