问吧! - 页 135 1...128129130131132133134135136137138139140141142...182 新评论 cutzpr 2008.10.08 00:30 #1341 Kalenzo: 我认为你把事情搞得太复杂了。试着使用一些较短的代码部分,而不是一个大函数。这应该给你一些提示。 谢谢你的帮助。我试图添加你说的代码,但老实告诉你,我很迷茫。在我添加了代码后,EA显示了一系列的问题。我一直在研究语法,但我迷失了方向。 我还有一个关于在int start()函数中使用函数 的问题。这是否允许?在一个函数中初始化的变量不是不能被其他函数看到吗? 所以 int start() { function( int x) { //做一些事情 return(x) } // 做点什么 ... "在start()函数中可以调用x吗? return0; } 我附上了我的EA源代码。非常感谢您的帮助。 //+------------------------------------------------------------------+ //| CCCCCCCCIEA.mq4 aka 8xCIEA.mq4 | //| By CuTzPR | //|------------------------------------------------------------------+ #property copyright "CuTzPR@Forex-TSD" //---- input parameters extern double Risk_Percent=10; extern bool Turned_On=true; extern bool Allow_Risk=false; extern bool TimeFilter=false; extern double FromHourTrade=0; //Adjust for Broker GMT Time extern double ToHourTrade=23; //Adjust for Broker GMT Time extern double TP=20; // Take Profit Level extern int MaxLong=5,MaxShort=5; extern int MaxOpenOrders=10; extern double Magic=10000; //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { int ticket; double Lots; bool Canopen,BlockTrade; double Poin; // This variable was included to solve the problem where some brokers use 6 digit quotes instead of 5 static datetime timeprev; // Portion of coded was added to alloy only one trade per bar. datetime CMT; //Close time of last trade int total=OrdersTotal(); double Spread=Ask-Bid; //This portion of code was added to only allow one trade per bar. if(timeprev==Time[0]) { return(0); //only execute on new bar } else if (timeprev==0) { timeprev=Time[0]; // do nothing if freshly added to chart return(0); } else { timeprev=Time[0]; } // End of alllow one trade per bar code //*****Following code was added to control the Risk per trade. if (Allow_Risk==true) Lots=MathCeil(AccountFreeMargin() * Risk_Percent / 10000) / 10; else Lots=0.1; //End of Risk Code //The following code was also included to solve the 6 digit broker quoting if (Point == 0.00001) Poin = 0.0001; //6 digits else if (Point == 0.001) Poin = 0.01; //3 digits (for Yen based pairs) else Poin = Point; //Normal //End Point Code // Custom Functions double cci=iCCI(NULL,PERIOD_M5,5,PRICE_TYPICAL,0); double SATL=iCustom(NULL,PERIOD_H1,"$SATL",0,1); // End of Custom Function //Start of total count of open Long and Short Orders. int totalOrders (totalBuy) { int totalNumber= 0; for (int cnt = total ; cnt >=0 ; cnt-- ) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderMagicNumber() == Magic && OrderType() == OP_BUY) totalNumber++; } return (totalNumber); } int totalOrders (totalSell) { int totalNumber = 0; for (int cnt = total ; cnt >=0 ; cnt-- ) { OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES); if (OrderMagicNumber() == Magic && OrderType() == OP_SELL) totalNumber++; } return(totalNumber); } int totalBuy = totalOrders(totalBuy); int totalSell = totalOrders(totalSell); int EAopenOrders=totalBuy+totalSell; //End of total Open Long and Short count code // Time filter Code if (TimeFilter==true) { if (!(Hour() >= FromHourTrade && Hour() <= ToHourTrade && Minute() <=2)) BlockTrade=true; else BlockTrade=false; } //End of time Filter code // Are trades allowed to be opened? if(EAopenOrders<=MaxOpenOrders && BlockTrade==false && Turned_On==true) Canopen=true; else if(EAopenOrders>MaxOpenOrders || BlockTrade==true || Turned_On==false) Canopen=false; // End of Allow code //*****Trade Open Order Functions if(Canopen==true) { if (totalBuy<=MaxLong) { if (cci>-100 && SATL<Ask) { ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"CCI0",Magic,0,Blue); if(ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); } else Print ("Error opening BUY order : ",GetLastError()); return (0); } } else if (totalSell<=MaxShort) { if (cciBid) { ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"CCI",Magic,0,Red); if (ticket>0) { if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print ("Sell order opened : ",OrderOpenPrice()); } else Print("Error opening SELL Order : ",GetLastError()); return (0); } } }// End of Trade Open Order Functions //****Close Orders if they are profitable for (int cnt = total ; cnt >=0 ; cnt-- ) { OrderSelect(0,SELECT_BY_POS,MODE_TRADES); if (OrderMagicNumber()==Magic) { if(OrderType()==OP_BUY && TP != 0 && totalBuy!= 0) { if(Bid >= ((OrderOpenPrice()+TP*Poin)+Spread)) { OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // Long position closed. CMT=OrderCloseTime(); return(0); } } } if (OrderMagicNumber()==Magic) { if(OrderType()==OP_SELL && TP != 0 && totalSell!=0 ) { if(Ask <= ((OrderOpenPrice()-TP*Poin)+Spread)) { OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // Short position closed. CMT=OrderCloseTime(); return(0); } } } } // Close Profitable trades loop closed }// End of Start function 非常感谢您的帮助。 Ask! Ojala EA 請高手指教!!!關於修改程序!!! 請高手幫幫忙,急需中.... cutzpr 2008.10.08 00:41 #1342 Limstylz: 大家好。我最初是作为一个新的主题发布的,但它被移到了另一个编程主题中(我不反对它的移动,BTW),现在似乎由于该主题中的发帖者数量而丢失了。 也许这里有人能帮助我? Limstylz看一下这个Ask!主题的第39页。我想那里可能有一些信息可以帮助你。好运 Limstylz 2008.10.08 03:02 #1343 干杯,伙计... cutzpr: Limstylz看一下这个 "问 "字,第39页。我想那里可能有一些信息可以帮助你。好运 谢谢cutzpr,但我已经设法解决了......该死的网络连接一整天都坏了,我不得不使用自己的 脑细胞一次 总之,为了回答你关于int start ()的问题......这是你的EA的主体,并且是持续更新的,每一个tick(我想这是对的)。 你的代码有点混乱......你能解释一下你在哪里遇到了问题吗? 如果你能把问题分解开来,我也许能帮上忙,尽管我自己真的只是在学习MQL4。 [删除] 2008.10.09 22:26 #1344 这有什么问题吗? 谁能帮帮我,如果我把这个指标复制到我的元数据中,我需要5分钟以上才能打开我的元数据。但当我删除它,重新打开我的元数据时,它又变得正常了。 附加的文件: kg_pivot_8h.mq4 5 kb bluesky123 2008.10.10 09:05 #1345 谢谢!!!这很好 increase 2008.10.17 11:28 #1346 回到绘图板 [删除] 2008.10.17 11:43 #1347 嵌入自定义指标 到专家顾问中 大家好,有人知道如何将下面的自定义指标添加到专家顾问中吗?这样我们就不需要使用icustom来从文件中调用它? //+------------------------------------------------------------------+ //| ARSI.mq4 //+------------------------------------------------------------------+ #property copyright "Alexander Kirilyuk M." #property link "" #property indicator_separate_window //#property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 DodgerBlue extern int ARSIPeriod = 14; //---- buffers double ARSI[]; int init() { string short_name = "ARSI (" + ARSIPeriod + ")"; SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ARSI); //SetIndexDrawBegin(0,ARSIPeriod); return(0); } int start() { int i, counted_bars = IndicatorCounted(); int limit; if(Bars <= ARSIPeriod) return(0); if(counted_bars < 0) { return; } if(counted_bars == 0) { limit = Bars; } if(counted_bars > 0) { limit = Bars - counted_bars; } double sc; for(i = limit; i >= 0; i--) { sc = MathAbs(iRSI(NULL, 0, ARSIPeriod, PRICE_CLOSE, i)/100.0 - 0.5) * 2.0; if( Bars - i <= ARSIPeriod) ARSI = Close; else ARSI = ARSI + sc * (Close - ARSI); } Print ("Try2 : " , ARSI[0], ":", ARSI[1]); return(0); } Ask! 这么个简单的程序为什么画不出线呢?请教牛牛们。 如何编码? [删除] 2008.10.18 00:52 #1348 yast77: 大家好,有谁知道如何将下面的自定义指标添加到专家顾问中?这样我们就不需要使用icustom从文件中调用它?//+------------------------------------------------------------------+ //| ARSI.mq4 //+------------------------------------------------------------------+ #property copyright "Alexander Kirilyuk M." #property link "" #property indicator_separate_window //#property indicator_chart_window #property indicator_buffers 1 #property indicator_color1 DodgerBlue extern int ARSIPeriod = 14; //---- buffers double ARSI[]; int init() { string short_name = "ARSI (" + ARSIPeriod + ")"; SetIndexStyle(0,DRAW_LINE); SetIndexBuffer(0,ARSI); //SetIndexDrawBegin(0,ARSIPeriod); return(0); } int start() { int i, counted_bars = IndicatorCounted(); int limit; if(Bars <= ARSIPeriod) return(0); if(counted_bars < 0) { return; } if(counted_bars == 0) { limit = Bars; } if(counted_bars > 0) { limit = Bars - counted_bars; } double sc; for(i = limit; i >= 0; i--) { sc = MathAbs(iRSI(NULL, 0, ARSIPeriod, PRICE_CLOSE, i)/100.0 - 0.5) * 2.0; if( Bars - i <= ARSIPeriod) ARSI = Close; else ARSI = ARSI + sc * (Close - ARSI); } Print ("Try2 : " , ARSI[0], ":", ARSI[1]); return(0); } 你必须在你的EA中使用iCustom函数 来调用这个指标。 iCustom(Symbol(),0, "ARSI",ARSIPeriod,0, 0)。 红色的数字是你要看的条形图。根据你的需要改变它。 斐路费(FerruFx [删除] 2008.10.18 12:05 #1349 FerruFx: 你必须在你的EA中使用iCustom函数来调用这个指标。iCustom(Symbol(),0, "ARSI",ARSIPeriod,0, 0)。 红色的数字是你要看的条形图。根据你的需要改变它。 FerruFx 谢谢你的回答。是的,我知道我们可以使用icustom函数,但据我所知,我们可以通过输入指标的编码来嵌入指标功能,以下网站指标嵌入专家顾问(iCustom替代方案)|www.metatrader.info,由codersguru解释描述,但对于ARSI指标,我不确定如何将其嵌入专家顾问。谢谢你的建议!!"。 Marcel Corzo 2008.10.18 16:28 #1350 改进10点3 大家好。 我们正试图改进10points3。我们需要改变代码,以关闭最后三分之一的交易。请参考这里的最新帖子。 https://www.mql5.com/en/forum/174975/page259。 我们在这里得到了很好的结果。 1...128129130131132133134135136137138139140141142...182 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
我认为你把事情搞得太复杂了。试着使用一些较短的代码部分,而不是一个大函数。这应该给你一些提示。
谢谢你的帮助。我试图添加你说的代码,但老实告诉你,我很迷茫。在我添加了代码后,EA显示了一系列的问题。我一直在研究语法,但我迷失了方向。
我还有一个关于在int start()函数中使用函数 的问题。这是否允许?在一个函数中初始化的变量不是不能被其他函数看到吗?
所以
int start()
{
function( int x)
{
//做一些事情
return(x)
}
// 做点什么 ... "在start()函数中可以调用x吗?
return0;
}
我附上了我的EA源代码。非常感谢您的帮助。
//| CCCCCCCCIEA.mq4 aka 8xCIEA.mq4 |
//| By CuTzPR |
//|------------------------------------------------------------------+
#property copyright "CuTzPR@Forex-TSD"
//---- input parameters
extern double Risk_Percent=10;
extern bool Turned_On=true;
extern bool Allow_Risk=false;
extern bool TimeFilter=false;
extern double FromHourTrade=0; //Adjust for Broker GMT Time
extern double ToHourTrade=23; //Adjust for Broker GMT Time
extern double TP=20; // Take Profit Level
extern int MaxLong=5,MaxShort=5;
extern int MaxOpenOrders=10;
extern double Magic=10000;
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
int ticket;
double Lots;
bool Canopen,BlockTrade;
double Poin; // This variable was included to solve the problem where some brokers use 6 digit quotes instead of 5
static datetime timeprev; // Portion of coded was added to alloy only one trade per bar.
datetime CMT; //Close time of last trade
int total=OrdersTotal();
double Spread=Ask-Bid;
//This portion of code was added to only allow one trade per bar.
if(timeprev==Time[0])
{
return(0); //only execute on new bar
}
else if (timeprev==0)
{
timeprev=Time[0]; // do nothing if freshly added to chart
return(0);
}
else
{
timeprev=Time[0];
}
// End of alllow one trade per bar code
//*****Following code was added to control the Risk per trade.
if (Allow_Risk==true)
Lots=MathCeil(AccountFreeMargin() * Risk_Percent / 10000) / 10;
else Lots=0.1;
//End of Risk Code
//The following code was also included to solve the 6 digit broker quoting
if (Point == 0.00001) Poin = 0.0001; //6 digits
else if (Point == 0.001) Poin = 0.01; //3 digits (for Yen based pairs)
else Poin = Point; //Normal
//End Point Code
// Custom Functions
double cci=iCCI(NULL,PERIOD_M5,5,PRICE_TYPICAL,0);
double SATL=iCustom(NULL,PERIOD_H1,"$SATL",0,1);
// End of Custom Function
//Start of total count of open Long and Short Orders.
int totalOrders (totalBuy)
{
int totalNumber= 0;
for (int cnt = total ; cnt >=0 ; cnt-- )
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == Magic && OrderType() == OP_BUY)
totalNumber++;
}
return (totalNumber);
}
int totalOrders (totalSell)
{
int totalNumber = 0;
for (int cnt = total ; cnt >=0 ; cnt-- )
{
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber() == Magic && OrderType() == OP_SELL)
totalNumber++;
}
return(totalNumber);
}
int totalBuy = totalOrders(totalBuy);
int totalSell = totalOrders(totalSell);
int EAopenOrders=totalBuy+totalSell;
//End of total Open Long and Short count code
// Time filter Code
if (TimeFilter==true)
{
if (!(Hour() >= FromHourTrade && Hour() <= ToHourTrade && Minute() <=2))
BlockTrade=true;
else BlockTrade=false;
}
//End of time Filter code
// Are trades allowed to be opened?
if(EAopenOrders<=MaxOpenOrders && BlockTrade==false && Turned_On==true)
Canopen=true;
else if(EAopenOrders>MaxOpenOrders || BlockTrade==true || Turned_On==false)
Canopen=false;
// End of Allow code
//*****Trade Open Order Functions
if(Canopen==true)
{
if (totalBuy<=MaxLong)
{
if (cci>-100 && SATL<Ask)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"CCI0",Magic,0,Blue);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print("BUY order opened : ",OrderOpenPrice());
}
else Print ("Error opening BUY order : ",GetLastError());
return (0);
}
}
else if (totalSell<=MaxShort)
{
if (cciBid)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"CCI",Magic,0,Red);
if (ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
Print ("Sell order opened : ",OrderOpenPrice());
}
else Print("Error opening SELL Order : ",GetLastError());
return (0);
}
}
}// End of Trade Open Order Functions
//****Close Orders if they are profitable
for (int cnt = total ; cnt >=0 ; cnt-- )
{
OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if (OrderMagicNumber()==Magic)
{
if(OrderType()==OP_BUY && TP != 0 && totalBuy!= 0)
{
if(Bid >= ((OrderOpenPrice()+TP*Poin)+Spread))
{
OrderClose(OrderTicket(),OrderLots(),Bid,3,Green); // Long position closed.
CMT=OrderCloseTime();
return(0);
}
}
}
if (OrderMagicNumber()==Magic)
{
if(OrderType()==OP_SELL && TP != 0 && totalSell!=0 )
{
if(Ask <= ((OrderOpenPrice()-TP*Poin)+Spread))
{
OrderClose(OrderTicket(),OrderLots(),Ask,3,Green); // Short position closed.
CMT=OrderCloseTime();
return(0);
}
}
}
} // Close Profitable trades loop closed
}// End of Start function
非常感谢您的帮助。
大家好。
我最初是作为一个新的主题发布的,但它被移到了另一个编程主题中(我不反对它的移动,BTW),现在似乎由于该主题中的发帖者数量而丢失了。
也许这里有人能帮助我?
Limstylz看一下这个Ask!主题的第39页。我想那里可能有一些信息可以帮助你。好运
干杯,伙计...
Limstylz看一下这个 "问 "字,第39页。我想那里可能有一些信息可以帮助你。好运
谢谢cutzpr,但我已经设法解决了......该死的网络连接一整天都坏了,我不得不使用自己的 脑细胞一次
总之,为了回答你关于int start ()的问题......这是你的EA的主体,并且是持续更新的,每一个tick(我想这是对的)。
你的代码有点混乱......你能解释一下你在哪里遇到了问题吗? 如果你能把问题分解开来,我也许能帮上忙,尽管我自己真的只是在学习MQL4。
这有什么问题吗?
谁能帮帮我,如果我把这个指标复制到我的元数据中,我需要5分钟以上才能打开我的元数据。但当我删除它,重新打开我的元数据时,它又变得正常了。
谢谢!!!这很好
回到绘图板
嵌入自定义指标 到专家顾问中
大家好,有人知道如何将下面的自定义指标添加到专家顾问中吗?这样我们就不需要使用icustom来从文件中调用它?
//| ARSI.mq4
//+------------------------------------------------------------------+
#property copyright "Alexander Kirilyuk M."
#property link ""
#property indicator_separate_window
//#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
extern int ARSIPeriod = 14;
//---- buffers
double ARSI[];
int init()
{
string short_name = "ARSI (" + ARSIPeriod + ")";
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ARSI);
//SetIndexDrawBegin(0,ARSIPeriod);
return(0);
}
int start()
{
int i, counted_bars = IndicatorCounted();
int limit;
if(Bars <= ARSIPeriod)
return(0);
if(counted_bars < 0)
{
return;
}
if(counted_bars == 0)
{
limit = Bars;
}
if(counted_bars > 0)
{
limit = Bars - counted_bars;
}
double sc;
for(i = limit; i >= 0; i--)
{
sc = MathAbs(iRSI(NULL, 0, ARSIPeriod, PRICE_CLOSE, i)/100.0 - 0.5) * 2.0;
if( Bars - i <= ARSIPeriod)
ARSI = Close;
else
ARSI = ARSI + sc * (Close - ARSI);
}
Print ("Try2 : " , ARSI[0], ":", ARSI[1]);
return(0);
}大家好,有谁知道如何将下面的自定义指标添加到专家顾问中?这样我们就不需要使用icustom从文件中调用它?
//| ARSI.mq4
//+------------------------------------------------------------------+
#property copyright "Alexander Kirilyuk M."
#property link ""
#property indicator_separate_window
//#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
extern int ARSIPeriod = 14;
//---- buffers
double ARSI[];
int init()
{
string short_name = "ARSI (" + ARSIPeriod + ")";
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,ARSI);
//SetIndexDrawBegin(0,ARSIPeriod);
return(0);
}
int start()
{
int i, counted_bars = IndicatorCounted();
int limit;
if(Bars <= ARSIPeriod)
return(0);
if(counted_bars < 0)
{
return;
}
if(counted_bars == 0)
{
limit = Bars;
}
if(counted_bars > 0)
{
limit = Bars - counted_bars;
}
double sc;
for(i = limit; i >= 0; i--)
{
sc = MathAbs(iRSI(NULL, 0, ARSIPeriod, PRICE_CLOSE, i)/100.0 - 0.5) * 2.0;
if( Bars - i <= ARSIPeriod)
ARSI = Close;
else
ARSI = ARSI + sc * (Close - ARSI);
}
Print ("Try2 : " , ARSI[0], ":", ARSI[1]);
return(0);
}你必须在你的EA中使用iCustom函数 来调用这个指标。
iCustom(Symbol(),0, "ARSI",ARSIPeriod,0, 0)。
红色的数字是你要看的条形图。根据你的需要改变它。
斐路费(FerruFx
你必须在你的EA中使用iCustom函数来调用这个指标。
iCustom(Symbol(),0, "ARSI",ARSIPeriod,0, 0)。
红色的数字是你要看的条形图。根据你的需要改变它。
FerruFx谢谢你的回答。是的,我知道我们可以使用icustom函数,但据我所知,我们可以通过输入指标的编码来嵌入指标功能,以下网站指标嵌入专家顾问(iCustom替代方案)|www.metatrader.info,由codersguru解释描述,但对于ARSI指标,我不确定如何将其嵌入专家顾问。谢谢你的建议!!"。
改进10点3
大家好。
我们正试图改进10points3。我们需要改变代码,以关闭最后三分之一的交易。请参考这里的最新帖子。
https://www.mql5.com/en/forum/174975/page259。
我们在这里得到了很好的结果。