如何编码? - 页 325 1...318319320321322323324325326327328329330331332...347 新评论 ccjjaa 2013.01.20 00:39 #3241 代码 cja: 嗨,mladen。有时间看一下这个吗? 友好的问候 CJA 嗨,mladen。 我只是想让你知道,我已经得到了我的尾随代码请求的解决方案,所以你可以把这个问题从你的todo列表中删除。 注意:CJA Mladen Rakic 2013.01.20 06:27 #3242 很高兴你解决了这个问题 祝你进一步编码和交易愉快 cja: 嗨,mladen。我只是想让你知道,我已经得到了我的尾随代码请求的解决方案,所以你可以把这个问题从你的todo列表中删除。 尊敬的CJA dasio 2013.01.25 18:17 #3243 你好。 我需要检查 我的EA的最后一笔平仓单是盈利还是亏损。 我想检查EA的最后两个平仓盈利订单,并将其相加。 问题是我在同一个账户中有几个EA,所以有必要用特定的MagicNumber检查历史订单。我尝试了几种模式,但没有成功。 你能帮助我吗? 谢谢你。 Mladen Rakic 2013.01.25 18:30 #3244 dasio 这个函数 返回最后一次平仓的订单利润(正如你所看到的,你也可以指定神奇的数字作为参数,所以它解决了你的多个实例的问题)。 double lastOrderProfit(int magicNumber=0) { datetime lastTime = 0; double lastProfit = 0; for(int i=OrdersHistoryTotal()-1; i>=0; i--) { if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break; if (magicNumber!=0) if (OrderMagicNumber() != magicNumber) continue; if (OrderSymbol() != Symbol()) continue; if (OrderCloseTime() <= lastTime) continue; lastTime = OrderCloseTime(); lastProfit = OrderProfit()+OrderSwap()+OrderCommission(); } return(lastProfit); } 你只需检查该函数的返回值是正数还是负数。 dasio: 你好。我需要检查我的EA最后关闭的订单是盈利还是亏损。 我想检查EA的最后两笔盈利订单,并将其相加。 问题是我在同一个账户中有几个EA,所以有必要用特定的MagicNumber检查历史订单。我尝试了几种模式,但没有成功。 你能帮助我吗? 谢谢你 关闭订单的利润计算 "HELP" 通用MA交叉EA How to code? dasio 2013.01.26 12:51 #3245 mladen: dasio这个函数返回最后一笔平仓订单的利润(正如你所看到的,你也可以指定神奇数字作为参数,所以它解决了你的多个实例的问题)。 double lastOrderProfit(int magicNumber=0) { datetime lastTime = 0; double lastProfit = 0; for(int i=OrdersHistoryTotal()-1; i>=0; i--) { if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break; if (magicNumber!=0) if (OrderMagicNumber() != magicNumber) continue; if (OrderSymbol() != Symbol()) continue; if (OrderCloseTime() <= lastTime) continue; lastTime = OrderCloseTime(); lastProfit = OrderProfit()+OrderSwap()+OrderCommission(); } return(lastProfit); } 你只需要检查函数的返回值是正数还是负数即可。 所以我只需要用我的魔法号码调用这个函数,它就会给我带来我的EA的最后一笔平仓订单的利润,对吗? Mladen Rakic 2013.01.26 12:53 #3246 是的,它是正确的 dasio: 所以我只需要用我的魔法数字调用这个函数,它就会给我带来我的EA的最后一笔平仓订单的利润,对吗? dasio 2013.01.26 13:56 #3247 mladen: 是的,这是对的 谢谢你。 但是,如果我启动EA,历史上没有订单,我如何才能在我的EA平仓的情况下调用这个功能? Mladen Rakic 2013.01.26 14:38 #3248 那么首先使用这个函数。 int closedSoFarForMagic(int magicNumber=0) { int closedSoFar=0; for(int i=OrdersHistoryTotal()-1; i>=0; i--) { if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break; if (magicNumber!=0) if (OrderMagicNumber() != magicNumber) continue; if (OrderSymbol() != Symbol()) continue; closedSoFar++; } return(closedSoFar); } 如果closedSoFarForMagic()>0,那么你就知道历史上已经有特定魔法数字 的平仓订单,然后你可以检查最后的订单利润。 dasio: 谢谢你,但是如果我启动EA,历史上没有订单,我怎样才能在我的EA平仓时调用这个函数? Fausto Nunziante Del Gaudio 2013.03.16 18:53 #3249 vma交叉扇形尾巴 你好,我想做一个指标,当两个vma交叉时显示箭头。我是一个mql初学者,我的指标显然不能工作,我被卡住了。有人能帮助我吗? 原来的指标是MA - fantail vma 3 #property copyright "Copyright © 2007, Forex-TSD.com " #property link "https://www.forex-tsd.com/" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Black #property indicator_width1 2 //#property indicator_color2 Red //#property indicator_width2 2 //---- input parameters //For both user settings, 2 is fast, 8 is slow.Weight=2.3 gives late entry. extern int ADX_Length=2; extern double Weighting=2.0; extern int MA_Length=1;//This must be =1 so that the VMA base line does not get averaged. extern int MA_Mode=1; //---- buffers double MA[]; double VMA[]; double VarMA[]; double ADX[]; double ADXR[]; double sPDI[]; double sMDI[]; double STR[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(8); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,MA); SetIndexBuffer(1,VMA); // SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(2,VarMA); SetIndexBuffer(3,ADX); SetIndexBuffer(4,ADXR); SetIndexBuffer(5,sPDI); SetIndexBuffer(6,sMDI); SetIndexBuffer(7,STR); //---- name for DataWindow and indicator subwindow label string short_name="MA - Fantail vma 3"; IndicatorShortName(short_name); SetIndexLabel(0,"MA - Fantail vma 3"); //---- SetIndexDrawBegin(0,2*MA_Length+40); // SetIndexDrawBegin(1,2*MA_Length+40);//Used for displaying internal signals. //---- Safety limits for user settings if (ADX_Length<2)ADX_Length=2; if (ADX_Length>8)ADX_Length=8; if (Weighting<1)Weighting=1; if (Weighting>8)Weighting=8; return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, j, counted_bars=IndicatorCounted(); //---- if ( counted_bars < 0 ) return(-1); if ( counted_bars ==0 ) limit=Bars-1; if ( counted_bars < 1 ) for(i=1;i<2*(MA_Length+ADX_Length+10);i++) { VMA=Close; VarMA=Close; MA=Close; STR = High-Low; sPDI = 0; sMDI = 0; ADX=0; ADXR=0; } if(counted_bars>0) limit=Bars-counted_bars; limit--; for(i=limit; i>=0; i--) { double Hi = High; double Hi1 = High; double Lo = Low; double Lo1 = Low; double Close1= Close; double Bulls = 0.5*(MathAbs(Hi-Hi1)+(Hi-Hi1)); double Bears = 0.5*(MathAbs(Lo1-Lo)+(Lo1-Lo)); if (Bulls > Bears) Bears = 0; else if (Bulls < Bears) Bulls = 0; else if (Bulls == Bears) {Bulls = 0;Bears = 0;} sPDI = (Weighting*sPDI + Bulls)/(Weighting+1);//ma weighting sMDI = (Weighting*sMDI + Bears)/(Weighting+1);//ma weighting double TR = MathMax(Hi-Lo,Hi-Close1); STR = (Weighting*STR + TR)/(Weighting+1);//ma weighting if(STR>0 ) { double PDI = sPDI/STR; double MDI = sMDI/STR; } if((PDI + MDI) > 0) double DX = MathAbs(PDI - MDI)/(PDI + MDI); else DX = 0; ADX = (Weighting*ADX + DX)/(Weighting+1);//ma weighting double vADX = ADX; double ADXmin = 1000000; for (j=0; j<=ADX_Length-1;j++) ADXmin = MathMin(ADXmin,ADX); double ADXmax = -1; for (j=0; j<=ADX_Length-1;j++) ADXmax = MathMax(ADXmax,ADX); double Diff = ADXmax - ADXmin; if(Diff > 0) double Const = (vADX- ADXmin)/Diff; else Const = 0; VarMA=((2-Const)*VarMA+Const*Close)/2;//Same equation but one less array, mod 10 Sept 2007. } for(j=limit; j>=0; j--) MA[j] = iMAOnArray(VarMA,0,MA_Length,0,MA_Mode,j); //---- return(0); } //+------------------------------------------------------------------+ [/PHP] and this is mine [PHP] //+------------------------------------------------------------------+ //| VMA cross arrows.mq4 | //| thefxpros@katamail.com | //+------------------------------------------------------------------+ #property copyright "thefxpros" #property link "thefxpros@katamail.com" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 C'255,198,198' #property indicator_color2 C'198,255,198' #property indicator_color3 Crimson #property indicator_color4 DarkGreen #property indicator_width1 3 #property indicator_width2 3 #property indicator_width3 2 #property indicator_width4 2 //-------------------------------------------------------- extern int VMA1_ADXLenght = 2; extern double VMA1_Weighting = 2.0; extern int VMA1_Length = 1; extern int VMA1_Mode = 1; extern int VMA2_ADXLenght = 2; extern double VMA2_Weighting = 3.0; extern int VMA2_Length = 3; extern int VMA2_Mode = 2; //-------------------------------------------------------- double buffer1[]; double buffer2[]; double buffer3[]; double buffer4[]; //-------------------------------------------------------- int init() { SetIndexStyle (0,DRAW_HISTOGRAM); SetIndexStyle (1,DRAW_HISTOGRAM); SetIndexBuffer (0,buffer3); SetIndexBuffer (1,buffer4); SetIndexBuffer (2,buffer1); SetIndexBuffer (3,buffer2); return(0); } int deinit() { return(0); } //-------------------------------------------------------- int start() { int counted_bars=IndicatorCounted(); int limit,i; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; //-------------------------------------------------------- for(i=limit; i>=0; i--) { buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode, i); buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode, i); buffer3 = buffer1; buffer4 = buffer2; } return(0); } How to code? 如何在两个均线之间填充颜色??? 这么个简单的程序为什么画不出线呢?请教牛牛们。 Mladen Rakic 2013.03.16 20:12 #3250 thefxpros, 首先检查指标的名称。 ""MA -fatailvma 3" 那里应该是 "fantail"。 另外,在对iCustom()指标的调用中,你缺少了缓冲区的编号。我只是猜测这是你想实现的目标 buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode,0, i); buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode,1, i);[/PHP] thefxpros: Hi, i'm trying to make an indicator that shows arrows when two vma crosses. I'm a mql beginner and my indicator obviously does not work, I'm stuck. Somebody can help me? The original indicator is MA - fantail vma 3 #property copyright "Copyright © 2007, Forex-TSD.com " #property link "https://www.forex-tsd.com/" #property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 Black #property indicator_width1 2 //#property indicator_color2 Red //#property indicator_width2 2 //---- input parameters //For both user settings, 2 is fast, 8 is slow.Weight=2.3 gives late entry. extern int ADX_Length=2; extern double Weighting=2.0; extern int MA_Length=1;//This must be =1 so that the VMA base line does not get averaged. extern int MA_Mode=1; //---- buffers double MA[]; double VMA[]; double VarMA[]; double ADX[]; double ADXR[]; double sPDI[]; double sMDI[]; double STR[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators IndicatorBuffers(8); SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,MA); SetIndexBuffer(1,VMA); // SetIndexStyle(2,DRAW_LINE); SetIndexBuffer(2,VarMA); SetIndexBuffer(3,ADX); SetIndexBuffer(4,ADXR); SetIndexBuffer(5,sPDI); SetIndexBuffer(6,sMDI); SetIndexBuffer(7,STR); //---- name for DataWindow and indicator subwindow label string short_name="MA - Fantail vma 3"; IndicatorShortName(short_name); SetIndexLabel(0,"MA - Fantail vma 3"); //---- SetIndexDrawBegin(0,2*MA_Length+40); // SetIndexDrawBegin(1,2*MA_Length+40);//Used for displaying internal signals. //---- Safety limits for user settings if (ADX_Length<2)ADX_Length=2; if (ADX_Length>8)ADX_Length=8; if (Weighting<1)Weighting=1; if (Weighting>8)Weighting=8; return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int limit, i, j, counted_bars=IndicatorCounted(); //---- if ( counted_bars < 0 ) return(-1); if ( counted_bars ==0 ) limit=Bars-1; if ( counted_bars < 1 ) for(i=1;i<2*(MA_Length+ADX_Length+10);i++) { VMA=Close; VarMA=Close; MA=Close; STR = High-Low; sPDI = 0; sMDI = 0; ADX=0; ADXR=0; } if(counted_bars>0) limit=Bars-counted_bars; limit--; for(i=limit; i>=0; i--) { double Hi = High; double Hi1 = High; double Lo = Low; double Lo1 = Low; double Close1= Close; double Bulls = 0.5*(MathAbs(Hi-Hi1)+(Hi-Hi1)); double Bears = 0.5*(MathAbs(Lo1-Lo)+(Lo1-Lo)); if (Bulls > Bears) Bears = 0; else if (Bulls < Bears) Bulls = 0; else if (Bulls == Bears) {Bulls = 0;Bears = 0;} sPDI = (Weighting*sPDI + Bulls)/(Weighting+1);//ma weighting sMDI = (Weighting*sMDI + Bears)/(Weighting+1);//ma weighting double TR = MathMax(Hi-Lo,Hi-Close1); STR = (Weighting*STR + TR)/(Weighting+1);//ma weighting if(STR>0 ) { double PDI = sPDI/STR; double MDI = sMDI/STR; } if((PDI + MDI) > 0) double DX = MathAbs(PDI - MDI)/(PDI + MDI); else DX = 0; ADX = (Weighting*ADX + DX)/(Weighting+1);//ma weighting double vADX = ADX; double ADXmin = 1000000; for (j=0; j<=ADX_Length-1;j++) ADXmin = MathMin(ADXmin,ADX); double ADXmax = -1; for (j=0; j<=ADX_Length-1;j++) ADXmax = MathMax(ADXmax,ADX); double Diff = ADXmax - ADXmin; if(Diff > 0) double Const = (vADX- ADXmin)/Diff; else Const = 0; VarMA=((2-Const)*VarMA+Const*Close)/2;//Same equation but one less array, mod 10 Sept 2007. } for(j=limit; j>=0; j--) MA[j] = iMAOnArray(VarMA,0,MA_Length,0,MA_Mode,j); //---- return(0); } //+------------------------------------------------------------------+ and this is mine [PHP] //+------------------------------------------------------------------+ //| VMA cross arrows.mq4 | //| thefxpros@katamail.com | //+------------------------------------------------------------------+ #property copyright "thefxpros" #property link "thefxpros@katamail.com" #property indicator_chart_window #property indicator_buffers 4 #property indicator_color1 C'255,198,198' #property indicator_color2 C'198,255,198' #property indicator_color3 Crimson #property indicator_color4 DarkGreen #property indicator_width1 3 #property indicator_width2 3 #property indicator_width3 2 #property indicator_width4 2 //-------------------------------------------------------- extern int VMA1_ADXLenght = 2; extern double VMA1_Weighting = 2.0; extern int VMA1_Length = 1; extern int VMA1_Mode = 1; extern int VMA2_ADXLenght = 2; extern double VMA2_Weighting = 3.0; extern int VMA2_Length = 3; extern int VMA2_Mode = 2; //-------------------------------------------------------- double buffer1[]; double buffer2[]; double buffer3[]; double buffer4[]; //-------------------------------------------------------- int init() { SetIndexStyle (0,DRAW_HISTOGRAM); SetIndexStyle (1,DRAW_HISTOGRAM); SetIndexBuffer (0,buffer3); SetIndexBuffer (1,buffer4); SetIndexBuffer (2,buffer1); SetIndexBuffer (3,buffer2); return(0); } int deinit() { return(0); } //-------------------------------------------------------- int start() { int counted_bars=IndicatorCounted(); int limit,i; if(counted_bars<0) return(-1); if(counted_bars>0) counted_bars--; limit=Bars-counted_bars; //-------------------------------------------------------- for(i=limit; i>=0; i--) { buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode, i); buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode, i); buffer3 = buffer1; buffer4 = buffer2; } return(0); } 1...318319320321322323324325326327328329330331332...347 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
代码
嗨,mladen。
有时间看一下这个吗?
友好的问候 CJA嗨,mladen。
我只是想让你知道,我已经得到了我的尾随代码请求的解决方案,所以你可以把这个问题从你的todo列表中删除。
注意:CJA
很高兴你解决了这个问题
祝你进一步编码和交易愉快
嗨,mladen。
我只是想让你知道,我已经得到了我的尾随代码请求的解决方案,所以你可以把这个问题从你的todo列表中删除。
尊敬的CJA你好。
我需要检查 我的EA的最后一笔平仓单是盈利还是亏损。
我想检查EA的最后两个平仓盈利订单,并将其相加。
问题是我在同一个账户中有几个EA,所以有必要用特定的MagicNumber检查历史订单。我尝试了几种模式,但没有成功。
你能帮助我吗?
谢谢你。
dasio
这个函数 返回最后一次平仓的订单利润(正如你所看到的,你也可以指定神奇的数字作为参数,所以它解决了你的多个实例的问题)。
{
datetime lastTime = 0;
double lastProfit = 0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;
if (magicNumber!=0)
if (OrderMagicNumber() != magicNumber) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderCloseTime() <= lastTime) continue;
lastTime = OrderCloseTime();
lastProfit = OrderProfit()+OrderSwap()+OrderCommission();
}
return(lastProfit);
}你只需检查该函数的返回值是正数还是负数。
你好。
我需要检查我的EA最后关闭的订单是盈利还是亏损。
我想检查EA的最后两笔盈利订单,并将其相加。
问题是我在同一个账户中有几个EA,所以有必要用特定的MagicNumber检查历史订单。我尝试了几种模式,但没有成功。
你能帮助我吗?
谢谢你dasio
这个函数返回最后一笔平仓订单的利润(正如你所看到的,你也可以指定神奇数字作为参数,所以它解决了你的多个实例的问题)。
{
datetime lastTime = 0;
double lastProfit = 0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;
if (magicNumber!=0)
if (OrderMagicNumber() != magicNumber) continue;
if (OrderSymbol() != Symbol()) continue;
if (OrderCloseTime() <= lastTime) continue;
lastTime = OrderCloseTime();
lastProfit = OrderProfit()+OrderSwap()+OrderCommission();
}
return(lastProfit);
}所以我只需要用我的魔法号码调用这个函数,它就会给我带来我的EA的最后一笔平仓订单的利润,对吗?
是的,它是正确的
所以我只需要用我的魔法数字调用这个函数,它就会给我带来我的EA的最后一笔平仓订单的利润,对吗?
是的,这是对的
谢谢你。
但是,如果我启动EA,历史上没有订单,我如何才能在我的EA平仓的情况下调用这个功能?
那么首先使用这个函数。
{
int closedSoFar=0;
for(int i=OrdersHistoryTotal()-1; i>=0; i--)
{
if (OrderSelect(i,SELECT_BY_POS, MODE_HISTORY)==false) break;
if (magicNumber!=0)
if (OrderMagicNumber() != magicNumber) continue;
if (OrderSymbol() != Symbol()) continue;
closedSoFar++;
}
return(closedSoFar);
}
如果closedSoFarForMagic()>0,那么你就知道历史上已经有特定魔法数字 的平仓订单,然后你可以检查最后的订单利润。
谢谢你,但是如果我启动EA,历史上没有订单,我怎样才能在我的EA平仓时调用这个函数?
vma交叉扇形尾巴
你好,我想做一个指标,当两个vma交叉时显示箭头。我是一个mql初学者,我的指标显然不能工作,我被卡住了。有人能帮助我吗?
原来的指标是MA - fantail vma 3
#property link "https://www.forex-tsd.com/"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Black
#property indicator_width1 2
//#property indicator_color2 Red
//#property indicator_width2 2
//---- input parameters
//For both user settings, 2 is fast, 8 is slow.Weight=2.3 gives late entry.
extern int ADX_Length=2;
extern double Weighting=2.0;
extern int MA_Length=1;//This must be =1 so that the VMA base line does not get averaged.
extern int MA_Mode=1;
//---- buffers
double MA[];
double VMA[];
double VarMA[];
double ADX[];
double ADXR[];
double sPDI[];
double sMDI[];
double STR[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(8);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MA);
SetIndexBuffer(1,VMA);
// SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,VarMA);
SetIndexBuffer(3,ADX);
SetIndexBuffer(4,ADXR);
SetIndexBuffer(5,sPDI);
SetIndexBuffer(6,sMDI);
SetIndexBuffer(7,STR);
//---- name for DataWindow and indicator subwindow label
string short_name="MA - Fantail vma 3";
IndicatorShortName(short_name);
SetIndexLabel(0,"MA - Fantail vma 3");
//----
SetIndexDrawBegin(0,2*MA_Length+40);
// SetIndexDrawBegin(1,2*MA_Length+40);//Used for displaying internal signals.
//---- Safety limits for user settings
if (ADX_Length<2)ADX_Length=2;
if (ADX_Length>8)ADX_Length=8;
if (Weighting<1)Weighting=1;
if (Weighting>8)Weighting=8;
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i, j, counted_bars=IndicatorCounted();
//----
if ( counted_bars < 0 ) return(-1);
if ( counted_bars ==0 ) limit=Bars-1;
if ( counted_bars < 1 )
for(i=1;i<2*(MA_Length+ADX_Length+10);i++)
{
VMA=Close;
VarMA=Close;
MA=Close;
STR = High-Low;
sPDI = 0;
sMDI = 0;
ADX=0;
ADXR=0;
}
if(counted_bars>0) limit=Bars-counted_bars;
limit--;
for(i=limit; i>=0; i--)
{
double Hi = High;
double Hi1 = High;
double Lo = Low;
double Lo1 = Low;
double Close1= Close;
double Bulls = 0.5*(MathAbs(Hi-Hi1)+(Hi-Hi1));
double Bears = 0.5*(MathAbs(Lo1-Lo)+(Lo1-Lo));
if (Bulls > Bears) Bears = 0;
else
if (Bulls < Bears) Bulls = 0;
else
if (Bulls == Bears) {Bulls = 0;Bears = 0;}
sPDI = (Weighting*sPDI + Bulls)/(Weighting+1);//ma weighting
sMDI = (Weighting*sMDI + Bears)/(Weighting+1);//ma weighting
double TR = MathMax(Hi-Lo,Hi-Close1);
STR = (Weighting*STR + TR)/(Weighting+1);//ma weighting
if(STR>0 )
{
double PDI = sPDI/STR;
double MDI = sMDI/STR;
}
if((PDI + MDI) > 0)
double DX = MathAbs(PDI - MDI)/(PDI + MDI);
else DX = 0;
ADX = (Weighting*ADX + DX)/(Weighting+1);//ma weighting
double vADX = ADX;
double ADXmin = 1000000;
for (j=0; j<=ADX_Length-1;j++) ADXmin = MathMin(ADXmin,ADX);
double ADXmax = -1;
for (j=0; j<=ADX_Length-1;j++) ADXmax = MathMax(ADXmax,ADX);
double Diff = ADXmax - ADXmin;
if(Diff > 0) double Const = (vADX- ADXmin)/Diff; else Const = 0;
VarMA=((2-Const)*VarMA+Const*Close)/2;//Same equation but one less array, mod 10 Sept 2007.
}
for(j=limit; j>=0; j--) MA[j] = iMAOnArray(VarMA,0,MA_Length,0,MA_Mode,j);
//----
return(0);
}
//+------------------------------------------------------------------+
[/PHP]
and this is mine
[PHP]
//+------------------------------------------------------------------+
//| VMA cross arrows.mq4 |
//| thefxpros@katamail.com |
//+------------------------------------------------------------------+
#property copyright "thefxpros"
#property link "thefxpros@katamail.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 C'255,198,198'
#property indicator_color2 C'198,255,198'
#property indicator_color3 Crimson
#property indicator_color4 DarkGreen
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 2
#property indicator_width4 2
//--------------------------------------------------------
extern int VMA1_ADXLenght = 2;
extern double VMA1_Weighting = 2.0;
extern int VMA1_Length = 1;
extern int VMA1_Mode = 1;
extern int VMA2_ADXLenght = 2;
extern double VMA2_Weighting = 3.0;
extern int VMA2_Length = 3;
extern int VMA2_Mode = 2;
//--------------------------------------------------------
double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
//--------------------------------------------------------
int init()
{
SetIndexStyle (0,DRAW_HISTOGRAM);
SetIndexStyle (1,DRAW_HISTOGRAM);
SetIndexBuffer (0,buffer3);
SetIndexBuffer (1,buffer4);
SetIndexBuffer (2,buffer1);
SetIndexBuffer (3,buffer2);
return(0);
}
int deinit()
{
return(0);
}
//--------------------------------------------------------
int start()
{
int counted_bars=IndicatorCounted();
int limit,i;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//--------------------------------------------------------
for(i=limit; i>=0; i--)
{
buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode, i);
buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode, i);
buffer3 = buffer1;
buffer4 = buffer2;
}
return(0);
}
thefxpros,
首先检查指标的名称。
""MA -fatailvma 3"
那里应该是 "fantail"。
另外,在对iCustom()指标的调用中,你缺少了缓冲区的编号。我只是猜测这是你想实现的目标
buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode,1, i);[/PHP]
Hi, i'm trying to make an indicator that shows arrows when two vma crosses. I'm a mql beginner and my indicator obviously does not work, I'm stuck. Somebody can help me?
The original indicator is MA - fantail vma 3
#property link "https://www.forex-tsd.com/"
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Black
#property indicator_width1 2
//#property indicator_color2 Red
//#property indicator_width2 2
//---- input parameters
//For both user settings, 2 is fast, 8 is slow.Weight=2.3 gives late entry.
extern int ADX_Length=2;
extern double Weighting=2.0;
extern int MA_Length=1;//This must be =1 so that the VMA base line does not get averaged.
extern int MA_Mode=1;
//---- buffers
double MA[];
double VMA[];
double VarMA[];
double ADX[];
double ADXR[];
double sPDI[];
double sMDI[];
double STR[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
IndicatorBuffers(8);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,MA);
SetIndexBuffer(1,VMA);
// SetIndexStyle(2,DRAW_LINE);
SetIndexBuffer(2,VarMA);
SetIndexBuffer(3,ADX);
SetIndexBuffer(4,ADXR);
SetIndexBuffer(5,sPDI);
SetIndexBuffer(6,sMDI);
SetIndexBuffer(7,STR);
//---- name for DataWindow and indicator subwindow label
string short_name="MA - Fantail vma 3";
IndicatorShortName(short_name);
SetIndexLabel(0,"MA - Fantail vma 3");
//----
SetIndexDrawBegin(0,2*MA_Length+40);
// SetIndexDrawBegin(1,2*MA_Length+40);//Used for displaying internal signals.
//---- Safety limits for user settings
if (ADX_Length<2)ADX_Length=2;
if (ADX_Length>8)ADX_Length=8;
if (Weighting<1)Weighting=1;
if (Weighting>8)Weighting=8;
return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int limit, i, j, counted_bars=IndicatorCounted();
//----
if ( counted_bars < 0 ) return(-1);
if ( counted_bars ==0 ) limit=Bars-1;
if ( counted_bars < 1 )
for(i=1;i<2*(MA_Length+ADX_Length+10);i++)
{
VMA=Close;
VarMA=Close;
MA=Close;
STR = High-Low;
sPDI = 0;
sMDI = 0;
ADX=0;
ADXR=0;
}
if(counted_bars>0) limit=Bars-counted_bars;
limit--;
for(i=limit; i>=0; i--)
{
double Hi = High;
double Hi1 = High;
double Lo = Low;
double Lo1 = Low;
double Close1= Close;
double Bulls = 0.5*(MathAbs(Hi-Hi1)+(Hi-Hi1));
double Bears = 0.5*(MathAbs(Lo1-Lo)+(Lo1-Lo));
if (Bulls > Bears) Bears = 0;
else
if (Bulls < Bears) Bulls = 0;
else
if (Bulls == Bears) {Bulls = 0;Bears = 0;}
sPDI = (Weighting*sPDI + Bulls)/(Weighting+1);//ma weighting
sMDI = (Weighting*sMDI + Bears)/(Weighting+1);//ma weighting
double TR = MathMax(Hi-Lo,Hi-Close1);
STR = (Weighting*STR + TR)/(Weighting+1);//ma weighting
if(STR>0 )
{
double PDI = sPDI/STR;
double MDI = sMDI/STR;
}
if((PDI + MDI) > 0)
double DX = MathAbs(PDI - MDI)/(PDI + MDI);
else DX = 0;
ADX = (Weighting*ADX + DX)/(Weighting+1);//ma weighting
double vADX = ADX;
double ADXmin = 1000000;
for (j=0; j<=ADX_Length-1;j++) ADXmin = MathMin(ADXmin,ADX);
double ADXmax = -1;
for (j=0; j<=ADX_Length-1;j++) ADXmax = MathMax(ADXmax,ADX);
double Diff = ADXmax - ADXmin;
if(Diff > 0) double Const = (vADX- ADXmin)/Diff; else Const = 0;
VarMA=((2-Const)*VarMA+Const*Close)/2;//Same equation but one less array, mod 10 Sept 2007.
}
for(j=limit; j>=0; j--) MA[j] = iMAOnArray(VarMA,0,MA_Length,0,MA_Mode,j);
//----
return(0);
}
//+------------------------------------------------------------------+
and this is mine
[PHP]
//+------------------------------------------------------------------+
//| VMA cross arrows.mq4 |
//| thefxpros@katamail.com |
//+------------------------------------------------------------------+
#property copyright "thefxpros"
#property link "thefxpros@katamail.com"
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 C'255,198,198'
#property indicator_color2 C'198,255,198'
#property indicator_color3 Crimson
#property indicator_color4 DarkGreen
#property indicator_width1 3
#property indicator_width2 3
#property indicator_width3 2
#property indicator_width4 2
//--------------------------------------------------------
extern int VMA1_ADXLenght = 2;
extern double VMA1_Weighting = 2.0;
extern int VMA1_Length = 1;
extern int VMA1_Mode = 1;
extern int VMA2_ADXLenght = 2;
extern double VMA2_Weighting = 3.0;
extern int VMA2_Length = 3;
extern int VMA2_Mode = 2;
//--------------------------------------------------------
double buffer1[];
double buffer2[];
double buffer3[];
double buffer4[];
//--------------------------------------------------------
int init()
{
SetIndexStyle (0,DRAW_HISTOGRAM);
SetIndexStyle (1,DRAW_HISTOGRAM);
SetIndexBuffer (0,buffer3);
SetIndexBuffer (1,buffer4);
SetIndexBuffer (2,buffer1);
SetIndexBuffer (3,buffer2);
return(0);
}
int deinit()
{
return(0);
}
//--------------------------------------------------------
int start()
{
int counted_bars=IndicatorCounted();
int limit,i;
if(counted_bars<0) return(-1);
if(counted_bars>0) counted_bars--;
limit=Bars-counted_bars;
//--------------------------------------------------------
for(i=limit; i>=0; i--)
{
buffer1 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA1_Weighting, VMA1_Length, VMA1_Mode, i);
buffer2 = iCustom(NULL, 0, "MA - fatail vma 3", VMA1_ADXLenght, VMA2_Weighting, VMA2_Length, VMA2_Mode, i);
buffer3 = buffer1;
buffer4 = buffer2;
}
return(0);
}