如何编码? - 页 151

 
luxinterior:
使用OrderReliable包含文件。 Lux

对于OrderSendReliable函数 来说,似乎有点缺失,你有一个新的版本吗?

 

如何在计算中使用时间

我是MQL4的新手,只是想看看我是否可以做一个简单的EA,使用一些基本的功能。我对C++很熟悉,但对MQL4一定很糟糕,因为我觉得这段代码有问题,我认为它与时间功能有关,也可能是与买入/卖出功能有关,下面是代码。...顺便说一下,这不是为了赚钱而设计的,只是为了测试这些功能。

int start()

{

//----

double currenttimeN, currentvalue;

double timeM = TimeMinute(TimeCurrent())。

双倍 timeH = TimeHour(TimeCurrent())。

currenttimeN = (timeH / 24) + (timeM / 1440);//给出一天中时间的百分比或1(1=一个完整的一天),所以总是小于1

currentvalue = Ask;

如果(currentvalue > currenttimeN){

OrderSend(Symbol(),OP_SELL,1,Ask,3,Ask-25*Point,Ask+25*Point, "My order #2",16384,0,Green)。

}

/* 买入命令 */

否则如果(currentvalue < currenttimeN){

OrderSend(Symbol(),OP_BUY,1,Ask,3,Ask-25*Point,Ask+25*Point, "My order #2",16384,0,Green)。

}

//----

return(0);

}

 

...................

 

错误的字符串。

currenttimeN = (timeH / 24) + (timeM / 1440);//gives the time of day as a percent or 1 (1 = one complete day) so always less than 1[/CODE]

could be:

[CODE]currenttimeN = (timeH *60 + timeM) / 1440;

如何比较一天中的部分时间和价格?

 

在同一时间买入和卖出

谁能帮助编程,使我能同时买入和卖出......一些脚本或其他......。

我很感激...

例如

如果(Stoch1>=Stoch2)

{

ticket=OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask-Stoploss*Point, Ask+TakeProfit*Point, "-", 0, 0, Green)。

ticket=OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Ask-Stoploss*Point, Bid-TakeProfit*Point, "-", 0, 0, Red);

}

问题是它只能买入...但我需要它同时执行两个订单...谢谢。

 
kk81:
谁能帮助编程,使我能同时买入和卖出......一些脚本或其他......。

我很感激...

例如。

如果(Stoch1>=Stoch2)

{

ticket=OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, Ask-Stoploss*Point, Ask+TakeProfit*Point, "-", 0, 0, Green);

ticket=OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, Ask-Stoploss*Point, Bid-TakeProfit*Point, "-", 0, 0, Red);

}

问题是它只买入...但我需要它执行两个订单...谢谢。

https://www.mql5.com/en/forum/177583/page37

 

如何获得OrderClose的返回价格?

我想知道,订单在什么价格被关闭

附加的文件:
closeorder.jpg  62 kb
 

外汇自由栏

非常感谢所有的朋友,具体的Roger09

我想要专家(自动交易)ForexFreedomBars。

当广场5米,15米,30米,1H为红色时,发送订单10-20 TP卖出。

当广场5米,15米,30米,1H为蓝色时,发送订单10-20 TP买入。

(TP, SL , lot, maxtrade)的能力必须改变

请帮助我。

//+------------------------------------------------------------------+

//| #外汇自由棒

//|

//+------------------------------------------------------------------+

#属性版权 "由Eli hayun编程"

#属性 indicator_separate_window

#property indicator_minimum -0.5

//#property indicator_maximum 5

#属性 indicator_buffers 8

#属性 indicator_color1 红色

#属性 indicator_color2 DodgerBlue

#属性 indicator_color3 红色

#属性indicator_color4 DodgerBlue

#属性指示器_color5 红色

#属性指示器_color6 DodgerBlue

#属性指示器_color7 红色

#属性指示器_color8 DodgerBlue

//---- 缓冲区

double buf4_up[];

double buf4_down[];

double buf3_up[];

double buf3_down[];

double buf2_up[];

double buf2_down[];

double buf1_up[];

double buf1_down[];

extern double Gap = 1; // 条形线之间的差距

extern int Period_1 = PERIOD_M5;//M15

extern int Period_2 = PERIOD_M15;/M30

extern int Period_3 = PERIOD_M30;//H1

外置int Period_4 = PERIOD_H1;//H4

外置int cci_1 = 2;//50

外置int cci_2 = 2;//14

extern int cci_3 = 2;

extern int cci_4 = 2;

extern int StopLoss=100;

extern int TakeProfit=100;

外置双数 Lots=0.1;

外部 bool AutoDisplay = false;

string shortname = "";

bool firstTime = true;

int UniqueNum = 228;

//+------------------------------------------------------------------+

//|自定义指标 初始化函数

//+------------------------------------------------------------------+

int init()

{

SetAutoDisplay()。

shortname = "# Forex Freedom("+Period_1+", "+Period_2+", "+Period_3+", "+Period_4+")" 。

firstTime = true;

IndicatorShortName(shortname)。

//---- 指标

SetIndexStyle(0,DRAW_ARROW);

SetIndexArrow(0,110);

SetIndexBuffer(0,buf4_up);

SetIndexEmptyValue(0,0.0);

SetIndexStyle(1,DRAW_ARROW)。

SetIndexArrow(1,110);

SetIndexBuffer(1,buf4_down)。

SetIndexEmptyValue(1,0.0)。

SetIndexStyle(2,DRAW_ARROW)。

SetIndexArrow(2,110);

SetIndexBuffer(2,buf3_up);

SetIndexEmptyValue(2,0.0)。

SetIndexStyle(3,DRAW_ARROW)。

SetIndexArrow(3,110);

SetIndexBuffer(3,buf3_down)。

SetIndexEmptyValue(3,0.0)。

SetIndexStyle(4,DRAW_ARROW)。

SetIndexArrow(4,110);

SetIndexBuffer(4,buf2_up);

SetIndexEmptyValue(4,0.0)。

SetIndexStyle(5,DRAW_ARROW)。

SetIndexArrow(5,110);

SetIndexBuffer(5,buf2_down)。

SetIndexEmptyValue(5,0.0)。

SetIndexStyle(6,DRAW_ARROW)。

SetIndexArrow(6,110);

SetIndexBuffer(6,buf1_up);

SetIndexEmptyValue(6,0.0);

SetIndexStyle(7,DRAW_ARROW);

SetIndexArrow(7,110);

SetIndexBuffer(7,buf1_down);

SetIndexEmptyValue(7,0.0)。

//----

返回(0)。

}

//+------------------------------------------------------------------+

//|自定义指标去初始化功能|

//+------------------------------------------------------------------+

int deinit()

{

//----

SetAutoDisplay()。

shortname = "# Forex Freedom("+Period_1+", "+Period_2+", "+Period_3+", "+Period_4+")" 。

firstTime = true;

//----

return(0);

}

//+------------------------------------------------------------------+

//|自定义指标迭代函数|

//+------------------------------------------------------------------+

int start()

{

int counted_bars=IndicatorCounted()。

int i=0, y5m=0, y1h=0, y30m=0, y15m=0, yy;

int limit=Bars-counted_bars;

datetime TimeArray_1H[], TimeArray_30M[], TimeArray_15M[], TimeArray_5M[]。

//----

如果(firstTime || NewBar())

{

firstTime = false;

int win = UniqueNum; // WindowFind(shortname);

double dif = Time[0] - Time[1];

for (int ii=ObjectsTotal()-1; ii>-1; ii--)

{

如果(StringFind(ObjectName(ii), "FF_"+win+"_") >= 0)

ObjectDelete(ObjectName(ii))。

否则

ii=-1。

}

double shift = 0.2;

for (ii=0; ii<4; ii++)

{

string txt = "??";

双重gp。

switch (ii)

{

case 0: txt = tf2txt(Period_1); gp = 1 + shift; break;

case 1: txt = tf2txt(Period_2); gp = 1 + Gap + shift; break;

case 2: txt = tf2txt(Period_3); gp = 1 + Gap*2 + shift; break;

case 3: txt = tf2txt(Period_4); gp = 1 + Gap*3 + shift; break;

}

string name = "FF_"+win+"_"+ii+"_"+txt;

ObjectCreate(name, OBJ_TEXT, WindowFind(shortname), iTime(NULL,0,0)+dif*3, gp) 。

ObjectSetText(name, txt,8, "Arial", Silver)。

}

}

ArrayCopySeries(TimeArray_1H,MODE_TIME,Symbol(), Period_4)。

ArrayCopySeries(TimeArray_30M,MODE_TIME,Symbol(),Period_3)。

ArrayCopySeries(TimeArray_15M,MODE_TIME,Symbol(),Period_2)。

ArrayCopySeries(TimeArray_5M,MODE_TIME,Symbol(),Period_1)。

for(i=0, y5m=0, y1h=0, y30m=0, y15m=0; i<limit; i++)

{

if (Time<TimeArray_5M[y5m]) y5m++;

如果(Time<TimeArray_1H[y1h])y1h++。

如果(Time<TimeArray_30M[y30m])y30m++。

如果(Time<TimeArray_15M[y15m])y15m++。

int cci_n = cci_1;

for (int tf = 0; tf < 4; tf++)

{

int prd;

switch (tf)

{

case 0: prd = Period_1; cci_n = cci_1; yy = y5m; break;

case 1: prd = Period_2; cci_n = cci_2; yy = y15m; break;

case 2: prd = Period_3; cci_n = cci_3; yy = y30m; break;

case 3: prd = Period_4; cci_n = cci_4; yy = y1h; break;

}

double cci = iCCI(NULL, prd, cci_n,PRICE_TYPICAL, yy);

double dUp = EMPTY_VALUE; // iCustom(NULL, prd, "SuperTrend", false, 1, yy);

double dDn = EMPTY_VALUE; //iCustom(NULL, prd, "SuperTrend", false, 0, yy);

如果(cci < 0) dUp = 1; 否则dDn = 1;

switch (tf)

{

case 0: if (dUp == EMPTY_VALUE) buf1_down = 1; else buf1_up = 1; break;

case 1: if (dUp == EMPTY_VALUE) buf2_down = 1 + Gap * 1; else buf2_up = 1 + Gap * 1; break;

case 2: 如果(dUp == EMPTY_VALUE) buf3_down = 1 + Gap * 2; else buf3_up = 1 + Gap * 2; break;

case 3: 如果 (dUp == EMPTY_VALUE) buf4_down = 1 + Gap * 3; else buf4_up = 1 + Gap * 3; break;

}

如果(NewBar())

{

string sDir = "";

如果(buf1_up[0] + buf2_up[0] + buf3_up[0] + buf4_up[0] == 4)

sDir = "向上"。

如果(buf1_down[0] + buf2_down[0] + buf3_down[0] + buf4_down[0] == 4)

sDir = "向下"。

如果(sDir != "")

{

PlaySound("alert1.wav")。

Print("Forex freeway - Direction ",sDir)。

}

}

}

}

如果(buf1_up[0] + buf2_up[0] + buf3_up[0] + buf4_up[0] ==4)

OrderSend(Symbol(),OP_BUY,Lots,Ask,3,StopLoss ,TakeProfit); else

返回(0)。

}

//+------------------------------------------------------------------+

string tf2txt(int tf)

{

if (tf == PERIOD_M1) return("M1");

if (tf == PERIOD_M5) return("M5");

如果 (tf == PERIOD_M15) 返回("M15")。

如果 (tf == PERIOD_M30) 返回("M30")。

if (tf == PERIOD_H1) return("H1");

如果 (tf == PERIOD_H4) 返回("H4")。

如果 (tf == PERIOD_D1) 返回("D1")。

如果 (tf == PERIOD_W1) 返回("W1")。

如果 (tf == PERIOD_MN1) 返回("MN1")。

return("??")。

}

void SetValues(int p1, int p2, int p3, int p4)

{

Period_1 = p1; Period_2 = p2; Period_3 = p3; Period_4 = p4。

}

空白 SetAutoDisplay()

{

如果 (AutoDisplay)

{

switch (Period())

{

case PERIOD_M1 : SetValues(PERIOD_M1, PERIOD_M5, PERIOD_M15,PERIOD_M30) ; break;

case PERIOD_M5 : SetValues(PERIOD_M5, PERIOD_M15,PERIOD_M30,PERIOD_H1); break;

case PERIOD_M15 : SetValues(PERIOD_M5, PERIOD_M15,PERIOD_M30,PERIOD_H1); break;

case PERIOD_M30 : SetValues(PERIOD_M5, PERIOD_M15,PERIOD_M30, PERIOD_H1); break;

case PERIOD_H1 : SetValues(PERIOD_M15, PERIOD_M30,PERIOD_H1, PERIOD_H4); break;

case PERIOD_H4 : SetValues(PERIOD_M30, PERIOD_H1, PERIOD_H4, PERIOD_D1) ; break;

case PERIOD_D1 : SetValues(PERIOD_H1, PERIOD_H4, PERIOD_D1, PERIOD_W1); break;

case PERIOD_W1 : SetValues(PERIOD_H4, PERIOD_D1, PERIOD_W1,PERIOD_MN1) ; break;

case PERIOD_MN1 : SetValues(PERIOD_H4, PERIOD_D1, PERIOD_W1,PERIOD_MN1); break;

}

}

}

bool NewBar()

{

static datetime dt = 0;

如果(Time[0] != dt)

{

dt = Time[0];

return(true);

}

return(false);

}

 

将指标作为过滤函数迁移到EA的问题

当我试图在我的EA中使用指标的一部分作为一个函数时,我现在意识到有三种类型的函数。第一种类型是Void,执行一个过程并返回0;第二种类型是执行计算并返回一个结果。第三种类型期望得到一组特定的值来处理,然后返回一个结果。

如果我的计算产生了三个结果,需要以至少两种不同的方式使用,我可以做什么?这些计算可能需要位于Start()函数中,原因如下:信息从外部变量(可手动调整)和全局变量(除非重新编译,否则保持静态)流向EA的各个功能。Start()函数是EA的大脑,它向其他函数索取信息。它可以将一组变量传递给一个函数,作为该函数的参数,如果该函数在它的()括号内声明了这些变量。然后,它收到一个结果,并可能将更多的变量传递给另一个函数以完成它的过程。

一旦我学会了将变量作为参数传递给其他函数,我就希望能在我的EA编码中获得一定程度的成功。不幸的是,我产生了一个零除法 错误,可能是因为我试图将一个值作为参数从一个函数传递到另一个函数,所以该值在需要时没有到达。由于它实际上是缺失的,我得到了零除法错误。我的下一个修订版去掉了中间步骤,直接将值传递到使用它们的函数中。

(我不认为我在学习MQL4编码的头两个月的经历中记录这一点对自己有什么好处。然而,任何可能在谷歌上搜索 "MQL4零除法错误 "的人,可能会很高兴知道我是如何解决这个问题的)。

我的下一个EA修订版治愈了我的零除法错误,但我的stratagy测试器的日志评论现在显示了一个堆栈超限。对于那些在谷歌上搜索 "MQL4堆栈超限 "的人,我将公布我发现的原因。它是在改变开仓或修改订单的价格时,未能通过使用 "Points "常数将手数转换为小数点后的等值。

我想在这里发布的最后一个提示(在我最初两个月的编码经验和超过12次的EA重写之后)是我能够解决难以找到的 "不等长的左括号 "的方法。MetaEditor不能用颜色突出显示括号内的文字。如果你有AutoDesk产品的Visual LISP编辑器,你可以在该编辑器中打开你的MQ4文件,看到几乎所有的括号对都是彩色的。这样就更容易校对出缺失的括号了。

感谢每个在这个论坛上分享答案的人。

编码愉快!

 

有什么帮助吗?

还想知道Metatrader的订单是否可以从命令行运行。或者一般来说,是否有可能使用某种API将外部应用程序与Metatrader连接起来。

谢谢

杰夫

原因: