编码帮助 - 页 320 1...313314315316317318319320321322323324325326327...786 新评论 [删除] 2014.08.01 19:38 #3191 你好。 我已经很久没有在这里了... 我在做一个EA的想法,我需要添加一个指标,但我不知道如何将其纳入EA,请你帮助我好吗? 指标是斜率方向线,我想让它在日线图中工作,并在低位TF图中触发订单,指标的代码是。 //+------------------------------------------------------------------+ 坡度方向线 D.L.M.mq4 |//|斜率方向线 //| daniel luchinger 2014 | //|MQL5: 使用MetaTrader的自动外汇交易、策略测试器和自定义指标。 //+------------------------------------------------------------------+ #property indicator_chart_window #属性 indicator_buffers 2 #属性 indicator_color1 Blue #属性 indicator_width1 3 #属性 indicator_color2 红色 #属性 indicator_width2 3 //---- 输入参数 extern int period=14; extern int method=3; // MODE_SMA Extern int price=0; // PRICE_CLOSE //---- 缓冲区 double Uptrend[]; double Dntrend[]; double ExtMapBuffer[]; //+------------------------------------------------------------------+ //|自定义指标初始化函数| //+------------------------------------------------------------------+ int init() { IndicatorBuffers(3); SetIndexBuffer(0, Uptrend); SetIndexBuffer(1, Dntrend); SetIndexBuffer(2, ExtMapBuffer)。 ArraySetAsSeries(ExtMapBuffer, true)。 SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3)。 IndicatorShortName("斜率方向线")。 return(0); } //+------------------------------------------------------------------+ //|自定义指标去初始化函数 //+------------------------------------------------------------------+ int deinit(){return(0);} 双重WMA(int x, int p) { return(iMA(NULL, 0, p, 0, method, price, x))。 } //+------------------------------------------------------------------+ //|自定义指标迭代函数| //+------------------------------------------------------------------+ int start() { int counted_bars = IndicatorCounted(); 如果(counted_bars < 0) 返回(-1)。 int x = 0; int p = MathSqrt(period); int e = Bars - counted_bars + period + 1; 双重 vect[], trend[]。 如果(e>Bars) e = Bars; ArrayResize(vect, e)。 ArraySetAsSeries(vect, true)。 ArrayResize(trend, e); ArraySetAsSeries(trend, true)。 for(x = 0; x < e; x++) { vect[x] = 2*WMA(x, period/2) - WMA(x, period)。 } for(x = 0; x < e-period; x++) ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x)。 for(x = e-period; x >= 0; x--) { trend[x] = trend[x+1]。 如果(ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1。 如果(ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1。 如果(trend[x]>0) { Uptrend[x] = ExtMapBuffer[x]; 如果(trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1]; Dntrend[x] = EMPTY_VALUE。 } 否则 如果(trend[x]<0) { Dntrend[x] = ExtMapBuffer[x]; 如果(trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1]; Uptrend[x] = EMPTY_VALUE。 } } 返回(0)。 --------------- -------------- 我的编码方式如下。 double UpTrend = iCustom(NULL,1440, "斜率方向线D.L.M",20,3,0,1); // 其中0 = UptrendBuffer double DnTrend = iCustom(NULL,1440, "斜率方向线D.L.M",20,3,1,1); // 其中1 = DntrendBuffer double _sl = 0,_tp = 0; { 如果(haMode == 0 || haMode == 1) { 如果(UpTrend) {label("LONG Condition OK"); 如果(Close[0] >= srDown && Close[0] < srUp) //if(StopLoss > 0) _sl = Ask - StopLoss; _sl = srDownHT-StopLossShift; if(TakeProfit > 0) _tp = Ask + TakeProfit; 如果(tt && orders<MaxTrades) { openOrder(getLots(),MagicNumber,OP_BUY, _sl,_tp)。 } }} } } 谁能纠正我,因为我肯定这是不可行的。 谢谢 邓小平1983年 Coding help 求助!EA中如何调用该指标? Please help translate this Jan Fouquaert 2014.08.01 20:05 #3192 非常感谢Mistertools的帮助。 但是... 我想做的是在#_FullSSA_normalize correct mtf nmc上应用移动平均线。 当我在M5上以正常的方式借助MT4的MA进行操作时,这个操作是没有问题的。 这是我在MT4上唯一使用的东西 ... 在M1上,它有时工作,有时不工作。这可能与设置有关。 请看图片,SSA可以,但MA不行...... 我一直在尝试自己做,但对我来说太复杂了,尽管在 "我的工作 "之后我只得到了两个错误。 一定是运气好,但尽管如此,SSA的工作没有问题,但MA却不见踪影。 当然,SSA是一个精英的.... 这是我前段时间买的,它是值得的...... 附加的文件: ssa.png 72 kb Mladen Rakic 2014.08.01 20:21 #3193 daniel1983: 你好。我已经很久没有来这里了... 我在做一个EA的创意,我需要添加一个指标,但我不知道如何将其纳入EA,请你帮助我好吗? 指标是斜率方向线,我想让它在日线图中工作,并在低位TF图中触发订单,指标的代码是。 //+------------------------------------------------------------------+ 坡度方向线 D.L.M.mq4 |//|斜率方向线 //| daniel luchinger 2014 | //|MQL5: 使用MetaTrader的自动外汇交易、策略测试器和自定义指标。 //+------------------------------------------------------------------+ #property indicator_chart_window #属性 indicator_buffers 2 #属性 indicator_color1 Blue #属性 indicator_width1 3 #属性 indicator_color2 红色 #属性 indicator_width2 3 //---- 输入参数 extern int period=14; extern int method=3; // MODE_SMA Extern int price=0; // PRICE_CLOSE //---- 缓冲区 double Uptrend[]; double Dntrend[]; double ExtMapBuffer[]; //+------------------------------------------------------------------+ //|自定义指标初始化函数| //+------------------------------------------------------------------+ int init() { IndicatorBuffers(3); SetIndexBuffer(0, Uptrend); SetIndexBuffer(1, Dntrend); SetIndexBuffer(2, ExtMapBuffer)。 ArraySetAsSeries(ExtMapBuffer, true)。 SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3); SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3)。 IndicatorShortName("斜率方向线")。 return(0); } //+------------------------------------------------------------------+ //|自定义指标去初始化函数 //+------------------------------------------------------------------+ int deinit(){return(0);} 双重WMA(int x, int p) { return(iMA(NULL, 0, p, 0, method, price, x))。 } //+------------------------------------------------------------------+ //|自定义指标迭代函数| //+------------------------------------------------------------------+ int start() { int counted_bars = IndicatorCounted(); 如果(counted_bars < 0) 返回(-1)。 int x = 0; int p = MathSqrt(period); int e = Bars - counted_bars + period + 1; 双重 vect[], trend[]。 如果(e>Bars) e = Bars; ArrayResize(vect, e)。 ArraySetAsSeries(vect, true)。 ArrayResize(trend, e); ArraySetAsSeries(trend, true)。 for(x = 0; x < e; x++) { vect[x] = 2*WMA(x, period/2) - WMA(x, period)。 } for(x = 0; x < e-period; x++) ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x)。 for(x = e-period; x >= 0; x--) { trend[x] = trend[x+1]。 如果(ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1。 如果(ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1。 如果(trend[x]>0) { Uptrend[x] = ExtMapBuffer[x]; 如果(trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1]; Dntrend[x] = EMPTY_VALUE。 } 否则 如果(trend[x]<0) { Dntrend[x] = ExtMapBuffer[x]; 如果(trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1]; Uptrend[x] = EMPTY_VALUE。 } } 返回(0)。 --------------- -------------- 我的编码方式如下。 double UpTrend = iCustom(NULL,1440, "斜率方向线D.L.M",20,3,0,1); // 其中0 = UptrendBuffer double DnTrend = iCustom(NULL,1440, "斜率方向线D.L.M",20,3,1,1); // 其中1 = DntrendBuffer double _sl = 0,_tp = 0; { 如果(haMode == 0 || haMode == 1) { 如果(UpTrend) {label("LONG Condition OK"); 如果(Close[0] >= srDown && Close[0] < srUp) //if(StopLoss > 0) _sl = Ask - StopLoss; _sl = srDownHT-StopLossShift; if(TakeProfit > 0) _tp = Ask + TakeProfit; 如果(tt && orders<MaxTrades) { openOrder(getLots(),MagicNumber,OP_BUY, _sl,_tp)。 } }} } } 谁能纠正我,因为我肯定这是不可行的。 谢谢 Daniel1983 这是不可行的,因为斜率方向线是一个重新绘制的指标。采取任何正常的Hull平均线("斜率方向线 "是Hull平均线),一切都会变得简单。 [删除] 2014.08.01 22:12 #3194 谢谢你,Mladen,我感谢你的时间。 我在关于HMA的帖子中发现,您创建了一个带速度控制的HMA。 我想在EA中试试,和我想用斜率方向指标的想法一样。 但对于您发布的这个HMA指标 "Hull Moving Averages 2.0 &SR lines",我想在EA中尝试使用。 如何使其在我的EA中工作的代码? 我写道。 输入int IndicatorTF = 1440 //(日线时间框架的指标) 输入 int HMAPeriod = 35; //(允许我改变这个参数) 输入 ENUM_HMAPrice = PRICE_CLOSE; //(允许我改变这个参数) 输入 int HMASpeed = 2.0; //(允许我改变这个参数) double trendUp = iCustom(Symbol(),IndicatorTF, "Hull moving average 2.0 & sr lines",HMAPeriod,ENUM_HMAPrice, HMASpeed,0,0)。 double trendDn = iCustom(Symbol(),IndicatorTF, "Hull moving average 2.0 & sr lines",HMAPeriod,ENUM_HMAPrice,HMASpeed,1,0)。 如果(trendUp > 0) { 开盘买入 } 指标代码为。 //+------------------------------------------------------------------+ //| Hull移动平均线| //| mladen | //+------------------------------------------------------------------+ #property copyright"www.forex-tsd.com" #property link "www.forex-tsd.com" #property indicator_chart_window #属性 indicator_buffers 3 #属性 indicator_color1 LimeGreen #属性 indicator_color2 PaleVioletRed #属性 indicator_color3 淡紫红 #属性 indicator_color3 淡紫红 #属性 indicator_width1 2 #属性指示器宽度2 2 #perty indicator_width3 2 // // // // // 外部字符串 TimeFrame = "当前时间框架"。 Extern int HMAPeriod = 35; Extern int HMAPrice = PRICE_CLOSE; 外置双数 HMASpeed = 2.0; 外部 bool LinesVisible = false; 外置 int LinesNumber = 5; 外部颜色 ColorUp = LimeGreen; 外部颜色 ColorDown = PaleVioletRed; 外部字符串 UniqueID = "HullLines1"; 外部 bool alertsOn = false; extern bool alertsOnCurrent = true; extern bool alertsMessage = true; 外部bool alertsSound = false; 外部bool alertsEmail = false; // // // // // 双重hma[]。 双倍 hmada[]。 双倍 hmadb[]。 double work[]; 双重趋势[]。 int HalfPeriod; int HullPeriod; string indicatorFileName; bool returnBars; bool calculateValue; int timeFrame; //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // int init() { IndicatorBuffers(5); SetIndexBuffer(0,hma); SetIndexBuffer(1,hmada); SetIndexBuffer(2,hmadb); SetIndexBuffer(3,trend); SetIndexBuffer(4,work); // // // // // HMAPeriod = MathMax(2,HMAPeriod); HalfPeriod = MathFloor(HMAPeriod/HMASpeed); HullPeriod = MathFloor(MathSqrt(HMAPeriod))。 指标文件名 = WindowExpertName(); calculateValue = TimeFrame=="calculateValue"; if (calculateValue) { return(0); } returnBars = TimeFrame=="returnBars"; if (returnBars) { return(0); } timeFrame = stringToTimeFrame(TimeFrame)。 // // // // // IndicatorShortName(timeFrameToString(timeFrame)+" HMA("+HMAPeriod+")")。 return(0); } 空白deinit() { deleteLines()。 } 空白的deleteLines() { int lookForLength = StringLen(UniqueID); for (int i= ObjectsTotal()-1; i>=0; i--) { string name = ObjectName(i); 如果(StringSubstr(name,0,lookForLength)==UniqueID) ObjectDelete(name); } } //------------------------------------------------------------------ // //------------------------------------------------------------------ // // // // // int start() { int i,counted_bars = IndicatorCounted(); if(counted_bars<0) return(-1); 如果(counted_bars>0) counted_bars--。 int limit=MathMin(Bars-counted_bars,Bars-1)。 if (returnBars) { hma[0] = MathMin(limit+1,Bars-1); return(0); } // // // // // 如果(calculateValue || timeFrame == Period() { 如果(趋势[limit] == -1)CleanPoint(limit,hmada,hmadb)。 for(i=limit; i>=0; i--) work = 2.0*iMA(NULL,0,HalfPeriod,0,MODE_LWMA,HMAPrice,i) -iMA(NULL,0,HMAPeriod,0,MODE_LWMA,HMAPrice,i) 。 for(i=limit; i>=0; i--) { hma = iMAOnArray(work,0,HullPeriod,0,MODE_LWMA,i)。 hmada = EMPTY_VALUE; hmadb = EMPTY_VALUE; trend = 趋势。 if (hma > hma) trend = 1; 如果(hma < hma) trend = -1。 如果(trend == -1) PlotPoint(i,hmada,hmadb,hma)。 } deleteLines()。 如果(LinesVisible) { int k = 0; for (i=0; i<Bars &&k<LinesNumber; i++) 如果(trend!=trend) { string name = UniqueID+(string)Time; ObjectCreate(name,OBJ_TREND,0,Time,hma,Time+Period()*60,hma) 。 如果(trend==1) ObjectSet(name,OBJPROP_COLOR,ColorUp)。 否则ObjectSet(name,OBJPROP_COLOR,ColorDown)。 k++; } } manageAlerts()。 return(0); } // // // // // limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName, "returnBars",0,0)*timeFrame/Period())。 如果(trend[limit]==-1)CleanPoint(limit,hmada,hmadb)。 for (i=limit; i>=0; i--) { int y = iBarShift(NULL,timeFrame,Time); trend = iCustom(NULL,timeFrame,indicatorFileName, "calculateValue",HMAPeriod,HMAPrice,HMASpeed,LinesVisible,LinesNumber,ColorUp,ColorDown,UniqueID,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,3,y)。 hma = iCustom(NULL,timeFrame,indicatorFileName, "calculateValue",HMAPeriod,HMAPrice,HMASpeed,LinesVisible,LinesNumber,ColorUp,ColorDown,UniqueID,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,y)。 hmada = EMPTY_VALUE; hmadb = EMPTY_VALUE; } for (i=limit;i>=0;i--) if (trend==-1) PlotPoint(i,hmada,hmadb,hma); 返回(0)。 } //+------------------------------------------------------------------- //| //+------------------------------------------------------------------- // // // // // 空白管理提示()。 { 如果(alertsOn) { 如果 (alertsOnCurrent) int whichBar = 0; 否则whichBar = 1。 如果(趋势[whichBar] !=趋势[whichBar+1])。 { 如果(trend[whichBar] == 1) doAlert(whichBar, "up")。 如果(trend[whichBar] == -1) doAlert(whichBar, "down"); } } } // // // // // void doAlert(int forBar, string doWhat) { 静态字符串previousAlert="无"。 static datetime previousTime; 字符串信息。 如果(previousAlert != doWhat || previousTime != Time[forBar]) { previousAlert = doWhat; previousTime = Time[forBar]; // // // // // message = Symbol()+" "+timeFrameToString(Period())+" at "+TimeToStr(TimeLocal(),TIME_SECONDS)+" HMA趋势改变为 "+doWhat; 如果(alertsMessage)警报(消息)。 如果(alertsEmail) SendMail(Symbol()+" HMA ",message); 如果(alertsSound) PlaySound("alert2.wav")。 } } //------------------------------------------------------------------- // //------------------------------------------------------------------- // // // // // void CleanPoint(int i,double& first[],double& second[]) { if ((second != EMPTY_VALUE) && (second != EMPTY_VALUE)) second = EMPTY_VALUE。 否则 如果((first != EMPTY_VALUE) && (first != EMPTY_VALUE) && (first == EMPTY_VALUE)) first = EMPTY_VALUE。 } // // // // // void PlotPoint(int i,double& first[],double& second[],double& from[] ) { 如果(first == EMPTY_VALUE) { 如果(first == EMPTY_VALUE) { first = from; first = from; 第二 = EMPTY_VALUE。 } 否则 { second = from; second = from; first = EMPTY_VALUE; } } 否则 { first = from; second = EMPTY_VALUE; } } //------------------------------------------------------------------- // //------------------------------------------------------------------- // // // // // string sTfTable[] = {"M1", "M5", "M15", "M30", "H1", "H4", "D1", "W1", "MN" }; int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200}; // // // // // int stringToTimeFrame(string tfs) { tfs = stringUpperCase(tfs); for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tfs==sTfTable || tfs==""+iTfTable) return(MathMax(iTfTable,Period() ))。 return(Period())。 } string timeFrameToString(int tf) { for (int i=ArraySize(iTfTable)-1; i>=0; i--) if (tf==iTfTable) return(sTfTable); return("")。 } // // // // // stringUpperCase(string str) { string s = str; for (int length=StringLen(str)-1; length>=0; length--) { int tchar = StringGetChar(s, length); if((tsar > 96 && tchar 223 && tchar < 256)) s = StringSetChar(s, length, tchar - 32); 否则如果(tchar > -33 && tchar < 0) s = StringSetChar(s, length, tchar + 224); } return(s); } Coding help 多时间框架指标 编程问题,求高手指点,谢谢! zigflip 2014.08.02 01:49 #3195 mladen: 这不是一个其他指标干扰的问题(除非你在同一个图表上使用多个相同指标的实例)。在这种情况下,它可能会发生,因为该指标没有被写成在同一图表上作为多实例指标使用。 你好,MLaden ,非常感谢你,但这不是我在一个图表上使用多个实例的情况,只有一个。 如果它不明显,不要担心,我将保持原样,感谢您的意见!祝您有一个愉快的一天...... zigflip Mladen Rakic 2014.08.02 05:25 #3196 zigflip: 你好,MLaden ,非常感谢你,但我不是在一个图表上使用多个实例,只有一个。如果它不明显,不用担心,我会保持原样,谢谢你的意见!祝你有一个愉快的一天...... zigflip 我确实试过我发布的那个,它们没有移位。 试试吧,也许会有帮助 [删除] 2014.08.02 17:19 #3197 我如何在EA中调用HMA指标? double (NULL,0, "HMA",??????) 条件是 如果(trendUp)则买入,或者如果(trendUp =1)则买入,或者类似这样的条件? 谢谢 Mladen Rakic 2014.08.02 17:46 #3198 daniel1983: 我如何在EA中调用HMA指标?double (NULL,0, "HMA",??????) 而条件是 如果(trendUp)则买入,或者如果(trendUp =1)则买入,或者类似这样的条件? 谢谢 取决于指标参数,但你必须使用iCustom()来实现。 你可以在这里找到更多的信息和不少的例子:https://www.mql5.com/en/forum/173108 [删除] 2014.08.02 19:50 #3199 mladen: 取决于指标参数,但你必须使用iCustom()来实现。 更多信息和相当多的例子你可以在这里找到:https://www.mql5.com/en/forum/173108 谢谢你的指导,我仍然很困惑,我找到了一个与斜线代码相似的HMA指标,它是 "HMA_Russian_Color",但我在条件上仍然有问题,用于过滤买入趋势和卖出趋势。 我写道 double Uptrend = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,0); // where last 0 = UptrendBuffer double Dntrend = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,1); // where last 1 = DntrendBuffer //period = 20 / type = 3 / price = 0是正确的吗? if(Uptrend) //我怎么写这个? { 打开购买 } 当HMA下降趋势或红色时,订单买入仍然打开... 请纠正我,或帮助我解决这个问题...。 谢谢 Mladen Rakic 2014.08.02 20:05 #3200 daniel1983: 谢谢你的指导,我仍然很困惑,我找到了一个与斜率线代码相似的HMA指标,它是 "HMA_Russian_Color",但我在条件上仍然有问题,用于过滤买入趋势和卖出趋势。我写道 double Uptrend = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,0); // where last 0 = UptrendBuffer double Dntrend = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,1); // where last 1 = DntrendBuffer //period = 20 / type = 3 / price = 0是正确的吗? if(Uptrend) //我怎么写这个? { 打开购买 } 当HMA下降趋势或红色时,订单买入仍然打开... 请纠正我,或帮助我解决这个问题... 谢谢 对于斜率变化,请尝试这样的方法。 double current = iCustom(Symbol(),0,"HMA_Russian_Color",20,3,0,0); double previous1 = iCustom(Symbol(),0,"HMA_Russian_Color",20,3,0,1); double previous2 = iCustom(Symbol(),0,"HMA_Russian_Color",20,3,0,2); if (current>previous1 && previous1<previous2) { // slope changed to up } if (currentprevious2) { // slope changed to down } 1...313314315316317318319320321322323324325326327...786 新评论 原因: 取消 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
你好。
我已经很久没有在这里了...
我在做一个EA的想法,我需要添加一个指标,但我不知道如何将其纳入EA,请你帮助我好吗?
指标是斜率方向线,我想让它在日线图中工作,并在低位TF图中触发订单,指标的代码是。
//+------------------------------------------------------------------+
坡度方向线 D.L.M.mq4 |//|斜率方向线
//| daniel luchinger 2014 |
//|MQL5: 使用MetaTrader的自动外汇交易、策略测试器和自定义指标。
//+------------------------------------------------------------------+
#property indicator_chart_window
#属性 indicator_buffers 2
#属性 indicator_color1 Blue
#属性 indicator_width1 3
#属性 indicator_color2 红色
#属性 indicator_width2 3
//---- 输入参数
extern int period=14;
extern int method=3; // MODE_SMA
Extern int price=0; // PRICE_CLOSE
//---- 缓冲区
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];
//+------------------------------------------------------------------+
//|自定义指标初始化函数|
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0, Uptrend);
SetIndexBuffer(1, Dntrend);
SetIndexBuffer(2, ExtMapBuffer)。
ArraySetAsSeries(ExtMapBuffer, true)。
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3)。
IndicatorShortName("斜率方向线")。
return(0);
}
//+------------------------------------------------------------------+
//|自定义指标去初始化函数
//+------------------------------------------------------------------+
int deinit(){return(0);}
双重WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x))。
}
//+------------------------------------------------------------------+
//|自定义指标迭代函数|
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
如果(counted_bars < 0)
返回(-1)。
int x = 0;
int p = MathSqrt(period);
int e = Bars - counted_bars + period + 1;
双重 vect[], trend[]。
如果(e>Bars)
e = Bars;
ArrayResize(vect, e)。
ArraySetAsSeries(vect, true)。
ArrayResize(trend, e);
ArraySetAsSeries(trend, true)。
for(x = 0; x < e; x++)
{
vect[x] = 2*WMA(x, period/2) - WMA(x, period)。
}
for(x = 0; x < e-period; x++)
ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x)。
for(x = e-period; x >= 0; x--)
{
trend[x] = trend[x+1]。
如果(ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1。
如果(ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1。
如果(trend[x]>0)
{ Uptrend[x] = ExtMapBuffer[x];
如果(trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
Dntrend[x] = EMPTY_VALUE。
}
否则
如果(trend[x]<0)
{
Dntrend[x] = ExtMapBuffer[x];
如果(trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
Uptrend[x] = EMPTY_VALUE。
}
}
返回(0)。
---------------
--------------
我的编码方式如下。
double UpTrend = iCustom(NULL,1440, "斜率方向线D.L.M",20,3,0,1); // 其中0 = UptrendBuffer
double DnTrend = iCustom(NULL,1440, "斜率方向线D.L.M",20,3,1,1); // 其中1 = DntrendBuffer
double _sl = 0,_tp = 0;
{
如果(haMode == 0 || haMode == 1)
{
如果(UpTrend)
{label("LONG Condition OK");
如果(Close[0] >= srDown && Close[0] < srUp)
//if(StopLoss > 0) _sl = Ask - StopLoss;
_sl = srDownHT-StopLossShift;
if(TakeProfit > 0) _tp = Ask + TakeProfit;
如果(tt && orders<MaxTrades)
{
openOrder(getLots(),MagicNumber,OP_BUY, _sl,_tp)。
}
}}
}
}
谁能纠正我,因为我肯定这是不可行的。
谢谢
邓小平1983年
非常感谢Mistertools的帮助。
但是...
我想做的是在#_FullSSA_normalize correct mtf nmc上应用移动平均线。
当我在M5上以正常的方式借助MT4的MA进行操作时,这个操作是没有问题的。
这是我在MT4上唯一使用的东西 ...
在M1上,它有时工作,有时不工作。这可能与设置有关。
请看图片,SSA可以,但MA不行......
我一直在尝试自己做,但对我来说太复杂了,尽管在 "我的工作 "之后我只得到了两个错误。
一定是运气好,但尽管如此,SSA的工作没有问题,但MA却不见踪影。
当然,SSA是一个精英的....
这是我前段时间买的,它是值得的......
你好。
我已经很久没有来这里了...
我在做一个EA的创意,我需要添加一个指标,但我不知道如何将其纳入EA,请你帮助我好吗?
指标是斜率方向线,我想让它在日线图中工作,并在低位TF图中触发订单,指标的代码是。
//+------------------------------------------------------------------+
坡度方向线 D.L.M.mq4 |//|斜率方向线
//| daniel luchinger 2014 |
//|MQL5: 使用MetaTrader的自动外汇交易、策略测试器和自定义指标。
//+------------------------------------------------------------------+
#property indicator_chart_window
#属性 indicator_buffers 2
#属性 indicator_color1 Blue
#属性 indicator_width1 3
#属性 indicator_color2 红色
#属性 indicator_width2 3
//---- 输入参数
extern int period=14;
extern int method=3; // MODE_SMA
Extern int price=0; // PRICE_CLOSE
//---- 缓冲区
double Uptrend[];
double Dntrend[];
double ExtMapBuffer[];
//+------------------------------------------------------------------+
//|自定义指标初始化函数|
//+------------------------------------------------------------------+
int init()
{
IndicatorBuffers(3);
SetIndexBuffer(0, Uptrend);
SetIndexBuffer(1, Dntrend);
SetIndexBuffer(2, ExtMapBuffer)。
ArraySetAsSeries(ExtMapBuffer, true)。
SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,3);
SetIndexStyle(1,DRAW_LINE,STYLE_SOLID,3)。
IndicatorShortName("斜率方向线")。
return(0);
}
//+------------------------------------------------------------------+
//|自定义指标去初始化函数
//+------------------------------------------------------------------+
int deinit(){return(0);}
双重WMA(int x, int p)
{
return(iMA(NULL, 0, p, 0, method, price, x))。
}
//+------------------------------------------------------------------+
//|自定义指标迭代函数|
//+------------------------------------------------------------------+
int start()
{
int counted_bars = IndicatorCounted();
如果(counted_bars < 0)
返回(-1)。
int x = 0;
int p = MathSqrt(period);
int e = Bars - counted_bars + period + 1;
双重 vect[], trend[]。
如果(e>Bars)
e = Bars;
ArrayResize(vect, e)。
ArraySetAsSeries(vect, true)。
ArrayResize(trend, e);
ArraySetAsSeries(trend, true)。
for(x = 0; x < e; x++)
{
vect[x] = 2*WMA(x, period/2) - WMA(x, period)。
}
for(x = 0; x < e-period; x++)
ExtMapBuffer[x] = iMAOnArray(vect, 0, p, 0, method, x)。
for(x = e-period; x >= 0; x--)
{
trend[x] = trend[x+1]。
如果(ExtMapBuffer[x]> ExtMapBuffer[x+1]) trend[x] =1。
如果(ExtMapBuffer[x]< ExtMapBuffer[x+1]) trend[x] =-1。
如果(trend[x]>0)
{ Uptrend[x] = ExtMapBuffer[x];
如果(trend[x+1]<0) Uptrend[x+1]=ExtMapBuffer[x+1];
Dntrend[x] = EMPTY_VALUE。
}
否则
如果(trend[x]<0)
{
Dntrend[x] = ExtMapBuffer[x];
如果(trend[x+1]>0) Dntrend[x+1]=ExtMapBuffer[x+1];
Uptrend[x] = EMPTY_VALUE。
}
}
返回(0)。
---------------
--------------
我的编码方式如下。
double UpTrend = iCustom(NULL,1440, "斜率方向线D.L.M",20,3,0,1); // 其中0 = UptrendBuffer
double DnTrend = iCustom(NULL,1440, "斜率方向线D.L.M",20,3,1,1); // 其中1 = DntrendBuffer
double _sl = 0,_tp = 0;
{
如果(haMode == 0 || haMode == 1)
{
如果(UpTrend)
{label("LONG Condition OK");
如果(Close[0] >= srDown && Close[0] < srUp)
//if(StopLoss > 0) _sl = Ask - StopLoss;
_sl = srDownHT-StopLossShift;
if(TakeProfit > 0) _tp = Ask + TakeProfit;
如果(tt && orders<MaxTrades)
{
openOrder(getLots(),MagicNumber,OP_BUY, _sl,_tp)。
}
}}
}
}
谁能纠正我,因为我肯定这是不可行的。
谢谢
Daniel1983这是不可行的,因为斜率方向线是一个重新绘制的指标。采取任何正常的Hull平均线("斜率方向线 "是Hull平均线),一切都会变得简单。
谢谢你,Mladen,我感谢你的时间。
我在关于HMA的帖子中发现,您创建了一个带速度控制的HMA。
我想在EA中试试,和我想用斜率方向指标的想法一样。
但对于您发布的这个HMA指标 "Hull Moving Averages 2.0 &SR lines",我想在EA中尝试使用。
如何使其在我的EA中工作的代码?
我写道。
输入int IndicatorTF = 1440 //(日线时间框架的指标)
输入 int HMAPeriod = 35; //(允许我改变这个参数)
输入 ENUM_HMAPrice = PRICE_CLOSE; //(允许我改变这个参数)
输入 int HMASpeed = 2.0; //(允许我改变这个参数)
double trendUp = iCustom(Symbol(),IndicatorTF, "Hull moving average 2.0 & sr lines",HMAPeriod,ENUM_HMAPrice, HMASpeed,0,0)。
double trendDn = iCustom(Symbol(),IndicatorTF, "Hull moving average 2.0 & sr lines",HMAPeriod,ENUM_HMAPrice,HMASpeed,1,0)。
如果(trendUp > 0)
{
开盘买入
}
指标代码为。
//+------------------------------------------------------------------+
//| Hull移动平均线|
//| mladen |
//+------------------------------------------------------------------+
#property copyright"www.forex-tsd.com"
#property link "www.forex-tsd.com"
#property indicator_chart_window
#属性 indicator_buffers 3
#属性 indicator_color1 LimeGreen
#属性 indicator_color2 PaleVioletRed
#属性 indicator_color3 淡紫红 #属性 indicator_color3 淡紫红
#属性 indicator_width1 2
#属性指示器宽度2 2
#perty indicator_width3 2
//
//
//
//
//
外部字符串 TimeFrame = "当前时间框架"。
Extern int HMAPeriod = 35;
Extern int HMAPrice = PRICE_CLOSE;
外置双数 HMASpeed = 2.0;
外部 bool LinesVisible = false;
外置 int LinesNumber = 5;
外部颜色 ColorUp = LimeGreen;
外部颜色 ColorDown = PaleVioletRed;
外部字符串 UniqueID = "HullLines1";
外部 bool alertsOn = false;
extern bool alertsOnCurrent = true;
extern bool alertsMessage = true;
外部bool alertsSound = false;
外部bool alertsEmail = false;
//
//
//
//
//
双重hma[]。
双倍 hmada[]。
双倍 hmadb[]。
double work[];
双重趋势[]。
int HalfPeriod;
int HullPeriod;
string indicatorFileName;
bool returnBars;
bool calculateValue;
int timeFrame;
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int init()
{
IndicatorBuffers(5);
SetIndexBuffer(0,hma);
SetIndexBuffer(1,hmada);
SetIndexBuffer(2,hmadb);
SetIndexBuffer(3,trend);
SetIndexBuffer(4,work);
//
//
//
//
//
HMAPeriod = MathMax(2,HMAPeriod);
HalfPeriod = MathFloor(HMAPeriod/HMASpeed);
HullPeriod = MathFloor(MathSqrt(HMAPeriod))。
指标文件名 = WindowExpertName();
calculateValue = TimeFrame=="calculateValue"; if (calculateValue) { return(0); }
returnBars = TimeFrame=="returnBars"; if (returnBars) { return(0); }
timeFrame = stringToTimeFrame(TimeFrame)。
//
//
//
//
//
IndicatorShortName(timeFrameToString(timeFrame)+" HMA("+HMAPeriod+")")。
return(0);
}
空白deinit()
{
deleteLines()。
}
空白的deleteLines()
{
int lookForLength = StringLen(UniqueID);
for (int i= ObjectsTotal()-1; i>=0; i--)
{
string name = ObjectName(i);
如果(StringSubstr(name,0,lookForLength)==UniqueID) ObjectDelete(name);
}
}
//------------------------------------------------------------------
//
//------------------------------------------------------------------
//
//
//
//
//
int start()
{
int i,counted_bars = IndicatorCounted();
if(counted_bars<0) return(-1);
如果(counted_bars>0) counted_bars--。
int limit=MathMin(Bars-counted_bars,Bars-1)。
if (returnBars) { hma[0] = MathMin(limit+1,Bars-1); return(0); }
//
//
//
//
//
如果(calculateValue || timeFrame == Period()
{
如果(趋势[limit] == -1)CleanPoint(limit,hmada,hmadb)。
for(i=limit; i>=0; i--) work = 2.0*iMA(NULL,0,HalfPeriod,0,MODE_LWMA,HMAPrice,i) -iMA(NULL,0,HMAPeriod,0,MODE_LWMA,HMAPrice,i) 。
for(i=limit; i>=0; i--)
{
hma = iMAOnArray(work,0,HullPeriod,0,MODE_LWMA,i)。
hmada = EMPTY_VALUE;
hmadb = EMPTY_VALUE;
trend = 趋势。
if (hma > hma) trend = 1;
如果(hma < hma) trend = -1。
如果(trend == -1) PlotPoint(i,hmada,hmadb,hma)。
}
deleteLines()。
如果(LinesVisible)
{
int k = 0;
for (i=0; i<Bars &&k<LinesNumber; i++)
如果(trend!=trend)
{
string name = UniqueID+(string)Time;
ObjectCreate(name,OBJ_TREND,0,Time,hma,Time+Period()*60,hma) 。
如果(trend==1)
ObjectSet(name,OBJPROP_COLOR,ColorUp)。
否则ObjectSet(name,OBJPROP_COLOR,ColorDown)。
k++;
}
}
manageAlerts()。
return(0);
}
//
//
//
//
//
limit = MathMax(limit,MathMin(Bars-1,iCustom(NULL,timeFrame,indicatorFileName, "returnBars",0,0)*timeFrame/Period())。
如果(trend[limit]==-1)CleanPoint(limit,hmada,hmadb)。
for (i=limit; i>=0; i--)
{
int y = iBarShift(NULL,timeFrame,Time);
trend = iCustom(NULL,timeFrame,indicatorFileName, "calculateValue",HMAPeriod,HMAPrice,HMASpeed,LinesVisible,LinesNumber,ColorUp,ColorDown,UniqueID,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,3,y)。
hma = iCustom(NULL,timeFrame,indicatorFileName, "calculateValue",HMAPeriod,HMAPrice,HMASpeed,LinesVisible,LinesNumber,ColorUp,ColorDown,UniqueID,alertsOn,alertsOnCurrent,alertsMessage,alertsSound,alertsEmail,0,y)。
hmada = EMPTY_VALUE;
hmadb = EMPTY_VALUE;
}
for (i=limit;i>=0;i--) if (trend==-1) PlotPoint(i,hmada,hmadb,hma);
返回(0)。
}
//+-------------------------------------------------------------------
//|
//+-------------------------------------------------------------------
//
//
//
//
//
空白管理提示()。
{
如果(alertsOn)
{
如果 (alertsOnCurrent)
int whichBar = 0;
否则whichBar = 1。
如果(趋势[whichBar] !=趋势[whichBar+1])。
{
如果(trend[whichBar] == 1) doAlert(whichBar, "up")。
如果(trend[whichBar] == -1) doAlert(whichBar, "down");
}
}
}
//
//
//
//
//
void doAlert(int forBar, string doWhat)
{
静态字符串previousAlert="无"。
static datetime previousTime;
字符串信息。
如果(previousAlert != doWhat || previousTime != Time[forBar]) {
previousAlert = doWhat;
previousTime = Time[forBar];
//
//
//
//
//
message = Symbol()+" "+timeFrameToString(Period())+" at "+TimeToStr(TimeLocal(),TIME_SECONDS)+" HMA趋势改变为 "+doWhat;
如果(alertsMessage)警报(消息)。
如果(alertsEmail) SendMail(Symbol()+" HMA ",message);
如果(alertsSound) PlaySound("alert2.wav")。
}
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//
void CleanPoint(int i,double& first[],double& second[])
{
if ((second != EMPTY_VALUE) && (second != EMPTY_VALUE))
second = EMPTY_VALUE。
否则
如果((first != EMPTY_VALUE) && (first != EMPTY_VALUE) && (first == EMPTY_VALUE))
first = EMPTY_VALUE。
}
//
//
//
//
//
void PlotPoint(int i,double& first[],double& second[],double& from[] )
{
如果(first == EMPTY_VALUE)
{
如果(first == EMPTY_VALUE) {
first = from;
first = from;
第二 = EMPTY_VALUE。
}
否则 {
second = from;
second = from;
first = EMPTY_VALUE;
}
}
否则
{
first = from;
second = EMPTY_VALUE;
}
}
//-------------------------------------------------------------------
//
//-------------------------------------------------------------------
//
//
//
//
//
string sTfTable[] = {"M1", "M5", "M15", "M30", "H1", "H4", "D1", "W1", "MN" };
int iTfTable[] = {1,5,15,30,60,240,1440,10080,43200};
//
//
//
//
//
int stringToTimeFrame(string tfs)
{
tfs = stringUpperCase(tfs);
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
if (tfs==sTfTable || tfs==""+iTfTable) return(MathMax(iTfTable,Period() ))。
return(Period())。
}
string timeFrameToString(int tf)
{
for (int i=ArraySize(iTfTable)-1; i>=0; i--)
if (tf==iTfTable) return(sTfTable);
return("")。
}
//
//
//
//
//
stringUpperCase(string str)
{
string s = str;
for (int length=StringLen(str)-1; length>=0; length--)
{
int tchar = StringGetChar(s, length);
if((tsar > 96 && tchar 223 && tchar < 256))
s = StringSetChar(s, length, tchar - 32);
否则如果(tchar > -33 && tchar < 0)
s = StringSetChar(s, length, tchar + 224);
}
return(s);
}
这不是一个其他指标干扰的问题(除非你在同一个图表上使用多个相同指标的实例)。在这种情况下,它可能会发生,因为该指标没有被写成在同一图表上作为多实例指标使用。
你好,MLaden ,非常感谢你,但这不是我在一个图表上使用多个实例的情况,只有一个。
如果它不明显,不要担心,我将保持原样,感谢您的意见!祝您有一个愉快的一天......
zigflip
你好,MLaden ,非常感谢你,但我不是在一个图表上使用多个实例,只有一个。
如果它不明显,不用担心,我会保持原样,谢谢你的意见!祝你有一个愉快的一天......
zigflip我确实试过我发布的那个,它们没有移位。
试试吧,也许会有帮助
我如何在EA中调用HMA指标?
double (NULL,0, "HMA",??????)
条件是
如果(trendUp)则买入,或者如果(trendUp =1)则买入,或者类似这样的条件?
谢谢
我如何在EA中调用HMA指标?
double (NULL,0, "HMA",??????)
而条件是
如果(trendUp)则买入,或者如果(trendUp =1)则买入,或者类似这样的条件?
谢谢取决于指标参数,但你必须使用iCustom()来实现。
你可以在这里找到更多的信息和不少的例子:https://www.mql5.com/en/forum/173108
取决于指标参数,但你必须使用iCustom()来实现。 更多信息和相当多的例子你可以在这里找到:https://www.mql5.com/en/forum/173108
谢谢你的指导,我仍然很困惑,我找到了一个与斜线代码相似的HMA指标,它是 "HMA_Russian_Color",但我在条件上仍然有问题,用于过滤买入趋势和卖出趋势。
我写道
double Uptrend = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,0); // where last 0 = UptrendBuffer
double Dntrend = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,1); // where last 1 = DntrendBuffer
//period = 20 / type = 3 / price = 0是正确的吗?
if(Uptrend) //我怎么写这个?
{
打开购买
}
当HMA下降趋势或红色时,订单买入仍然打开...
请纠正我,或帮助我解决这个问题...。
谢谢
谢谢你的指导,我仍然很困惑,我找到了一个与斜率线代码相似的HMA指标,它是 "HMA_Russian_Color",但我在条件上仍然有问题,用于过滤买入趋势和卖出趋势。
我写道
double Uptrend = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,0); // where last 0 = UptrendBuffer
double Dntrend = iCustom(Symbol(),0, "HMA_Russian_Color",20,3,0,1); // where last 1 = DntrendBuffer
//period = 20 / type = 3 / price = 0是正确的吗?
if(Uptrend) //我怎么写这个?
{
打开购买
}
当HMA下降趋势或红色时,订单买入仍然打开...
请纠正我,或帮助我解决这个问题...
谢谢对于斜率变化,请尝试这样的方法。
double previous1 = iCustom(Symbol(),0,"HMA_Russian_Color",20,3,0,1);
double previous2 = iCustom(Symbol(),0,"HMA_Russian_Color",20,3,0,2);
if (current>previous1 && previous1<previous2)
{
// slope changed to up
}
if (currentprevious2)
{
// slope changed to down
}