问吧! - 页 174 1...167168169170171172173174175176177178179180181182 新评论 ERAN123 2013.01.14 17:49 #1731 关于指标代码-----(3行)的问题 1.为什么在deinit中出现了2个标记的函数? 2.为什么720值在标记的行上? 解释一下这段代码。 //+------------------------------------------------------------------+ //| DailyBreakout.mq4 | //| Copyright © 2008, Robert Hill. | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, Robert Hill" #property link "NONE" #property indicator_chart_window //---- input parameters extern bool Alerts = false; extern int GMTshift = 0; extern int LabelShift = 20; extern int LineShift = 40; extern string pd = "PipsAboveBelowSR for Alert"; extern int PipDistance = 1; extern color StandardFontColor = White; extern int StandardFontSize = 8; extern color SupportColor = Red; extern color ResistanceColor = Lime; datetime LabelShiftTime, LineShiftTime; double yesterday_high=0; double yesterday_low=0; double LastHigh,LastLow,x; double R1=0; double S1=0; bool firstS1=true; bool firstR1=true; double myPoint; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators myPoint = SetPoint(Symbol()); //---- return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: add your code here //---- ObjectDelete("R1 Label"); ObjectDelete("R1 Line"); ObjectDelete("S1 Label"); ObjectDelete("S1 Line"); return(0); } double SetPoint(string mySymbol)// <<<<<<<-----why here on the deinit?????---------------- { double mPoint, myDigits; myDigits = MarketInfo (mySymbol, MODE_DIGITS); if (myDigits < 4) mPoint = 0.01; else mPoint = 0.0001; return(mPoint); } int DoAlerts()//<<<<<<<<<-------why here on the deint??????----------------- { double DifAboveR1,PipsLimit; double DifBelowS1; DifBelowS1 = S1 - Close[0]; DifAboveR1 = Close[0] - R1; PipsLimit = PipDistance * myPoint; if (DifBelowS1 > PipsLimit) firstS1 = true; if (DifBelowS1 0) { if (firstS1) { Alert("Below S1 Line by ",DifBelowS1, " for ", Symbol(),"-",Period()); PlaySound("alert.wav"); firstS1=false; } } if (DifAboveR1 > PipsLimit) firstR1 = true; if (DifAboveR1 0) { if (firstR1) { Alert("Above R1 Line by ",DifAboveR1," for ", Symbol(),"-",Period()); Sleep(2000); PlaySound("timeout.wav"); firstR1=false; } } } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- TODO: add your code here double day_high=0; double day_low=0; double yesterday_open=0; double today_open=0; double cur_day=0; double prev_day=0; int cnt=720;//<<<<<----why 720 ????????-------------------------------------------------- //---- exit if period is greater than 4 hr charts if(Period() > 240) { Print("Error - Chart period is greater than 4 hr."); return(-1); // then exit } //---- Get new daily prices & calculate pivots cur_day=0; prev_day=0; //---- Get new daily prices & calculate pivots while (cnt!= 0) { cur_day = TimeDay(Time[cnt]- (GMTshift*3600)); if (prev_day != cur_day) { yesterday_high = day_high; yesterday_low = day_low; day_high = High[cnt]; day_low = Low[cnt]; prev_day = cur_day; } if (High[cnt]>day_high) { day_high = High[cnt]; } if (Low[cnt]<day_low) { day_low = Low[cnt]; } cnt--; } S1 = yesterday_low; R1 = yesterday_high; LabelShiftTime = Time[LabelShift]; LineShiftTime = Time[LineShift]; //---- Set line labels on chart window DisplayLabel("R1 label", "R1", R1, StandardFontSize, StandardFontColor); DisplayLabel("S1 label", "S1", S1, StandardFontSize, StandardFontColor); //--- Draw Pivot lines on chart DisplayLine("S1 line", S1, 0, STYLE_DASHDOTDOT, SupportColor); DisplayLine("R1 line", R1, 0, STYLE_DASHDOTDOT, ResistanceColor); //---- done // Now check for Alert if (Alerts) DoAlerts(); //---- return(0); } //---- Set line labels on chart window void DisplayLabel(string LabelName, string LabelText, double LabelPos, int LabelFontSize, color LabelColor) { if(ObjectFind(LabelName) != 0) { ObjectCreate(LabelName, OBJ_TEXT, 0, LabelShiftTime, LabelPos); ObjectSetText(LabelName, LabelText, LabelFontSize, "Arial", LabelColor); } else { ObjectMove(LabelName, 0, LabelShiftTime, LabelPos); } } //--- Draw Pivot lines on chart void DisplayLine(string LineName, double LinePos, int LineWidth, int LineStyle, color LineColor) { if(ObjectFind(LineName) != 0) { ObjectCreate(LineName, OBJ_HLINE, 0, LineShiftTime, LinePos); ObjectSet(LineName, OBJPROP_STYLE, LineStyle); ObjectSet(LineName, OBJPROP_COLOR, LineColor); if (LineWidth > 0) ObjectSet(LineName, OBJPROP_WIDTH, LineWidth); } else { ObjectMove(LineName, 0, LineShiftTime, LinePos); } } //+------------------------------------------------------------------+ 谢谢。 Ask! 请教,问题出在哪, Small Problem to Fix Mladen Rakic 2013.01.14 18:45 #1732 ERAN123 1.它们不在deinit()中,而只是在deinit()后面(在deinit()和start()之间)。 在mql中,你不需要遵循任何程序和函数 的编写顺序。你可以把init()放在代码的最后,它仍然可以工作。) 2.它将计算固定在每个刻度的720条。为什么?我认为你应该向作者询问这个问题。 ERAN123: 1.为什么有两个标记的函数在deinit中?2.为什么标记线上的720值? 代码。 //+------------------------------------------------------------------+ //| DailyBreakout.mq4 | //| Copyright © 2008, Robert Hill. | //+------------------------------------------------------------------+ #property copyright "Copyright © 2008, Robert Hill" #property link "NONE" #property indicator_chart_window //---- input parameters extern bool Alerts = false; extern int GMTshift = 0; extern int LabelShift = 20; extern int LineShift = 40; extern string pd = "PipsAboveBelowSR for Alert"; extern int PipDistance = 1; extern color StandardFontColor = White; extern int StandardFontSize = 8; extern color SupportColor = Red; extern color ResistanceColor = Lime; datetime LabelShiftTime, LineShiftTime; double yesterday_high=0; double yesterday_low=0; double LastHigh,LastLow,x; double R1=0; double S1=0; bool firstS1=true; bool firstR1=true; double myPoint; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators myPoint = SetPoint(Symbol()); //---- return(0); } //+------------------------------------------------------------------+ //| Custor indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- TODO: add your code here //---- ObjectDelete("R1 Label"); ObjectDelete("R1 Line"); ObjectDelete("S1 Label"); ObjectDelete("S1 Line"); return(0); } double SetPoint(string mySymbol)// <<<<<<<-----why here on the deinit?????---------------- { double mPoint, myDigits; myDigits = MarketInfo (mySymbol, MODE_DIGITS); if (myDigits < 4) mPoint = 0.01; else mPoint = 0.0001; return(mPoint); } int DoAlerts()//<<<<<<<<<-------why here on the deint??????----------------- { double DifAboveR1,PipsLimit; double DifBelowS1; DifBelowS1 = S1 - Close[0]; DifAboveR1 = Close[0] - R1; PipsLimit = PipDistance * myPoint; if (DifBelowS1 > PipsLimit) firstS1 = true; if (DifBelowS1 0) { if (firstS1) { Alert("Below S1 Line by ",DifBelowS1, " for ", Symbol(),"-",Period()); PlaySound("alert.wav"); firstS1=false; } } if (DifAboveR1 > PipsLimit) firstR1 = true; if (DifAboveR1 0) { if (firstR1) { Alert("Above R1 Line by ",DifAboveR1," for ", Symbol(),"-",Period()); Sleep(2000); PlaySound("timeout.wav"); firstR1=false; } } } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int counted_bars=IndicatorCounted(); //---- TODO: add your code here double day_high=0; double day_low=0; double yesterday_open=0; double today_open=0; double cur_day=0; double prev_day=0; int cnt=720;//<<<<<----why 720 ????????-------------------------------------------------- //---- exit if period is greater than 4 hr charts if(Period() > 240) { Print("Error - Chart period is greater than 4 hr."); return(-1); // then exit } //---- Get new daily prices & calculate pivots cur_day=0; prev_day=0; //---- Get new daily prices & calculate pivots while (cnt!= 0) { cur_day = TimeDay(Time[cnt]- (GMTshift*3600)); if (prev_day != cur_day) { yesterday_high = day_high; yesterday_low = day_low; day_high = High[cnt]; day_low = Low[cnt]; prev_day = cur_day; } if (High[cnt]>day_high) { day_high = High[cnt]; } if (Low[cnt]<day_low) { day_low = Low[cnt]; } cnt--; } S1 = yesterday_low; R1 = yesterday_high; LabelShiftTime = Time[LabelShift]; LineShiftTime = Time[LineShift]; //---- Set line labels on chart window DisplayLabel("R1 label", "R1", R1, StandardFontSize, StandardFontColor); DisplayLabel("S1 label", "S1", S1, StandardFontSize, StandardFontColor); //--- Draw Pivot lines on chart DisplayLine("S1 line", S1, 0, STYLE_DASHDOTDOT, SupportColor); DisplayLine("R1 line", R1, 0, STYLE_DASHDOTDOT, ResistanceColor); //---- done // Now check for Alert if (Alerts) DoAlerts(); //---- return(0); } //---- Set line labels on chart window void DisplayLabel(string LabelName, string LabelText, double LabelPos, int LabelFontSize, color LabelColor) { if(ObjectFind(LabelName) != 0) { ObjectCreate(LabelName, OBJ_TEXT, 0, LabelShiftTime, LabelPos); ObjectSetText(LabelName, LabelText, LabelFontSize, "Arial", LabelColor); } else { ObjectMove(LabelName, 0, LabelShiftTime, LabelPos); } } //--- Draw Pivot lines on chart void DisplayLine(string LineName, double LinePos, int LineWidth, int LineStyle, color LineColor) { if(ObjectFind(LineName) != 0) { ObjectCreate(LineName, OBJ_HLINE, 0, LineShiftTime, LinePos); ObjectSet(LineName, OBJPROP_STYLE, LineStyle); ObjectSet(LineName, OBJPROP_COLOR, LineColor); if (LineWidth > 0) ObjectSet(LineName, OBJPROP_WIDTH, LineWidth); } else { ObjectMove(LineName, 0, LineShiftTime, LinePos); } } //+------------------------------------------------------------------+ 谢谢。 ERAN123 2013.01.14 19:03 #1733 嗨,mladen 谢谢你的回放。 1.刚刚注意到这个问题(我把这个问题搞错了,没有注意到)。 2.它是真正的奥秘 ERAN123 2013.01.18 16:36 #1734 待处理的订单 需要简单的帮助 !!!!!!!! 朋友们好 我有一个关于挂单的问题。 我有2个挂单,买入和卖出,一旦其中一个被击中,我就会关闭另一个。 我只是一个新手mql程序员,它超出了我现在的能力。 任何方向的朋友???? 非常感谢。 Mladen Rakic 2013.01.18 19:18 #1735 你可以使用这样的东西。 void CleanPendingOrders() { bool trade.BuyEntered = false; bool trade.SellEntered = false; for (int i=OrdersTotal()-1; i>=0; i--) { OrderSelect(i, SELECT_BY_POS, MODE_TRADES); // // // // // if ( OrderSymbol()==trade.symbol && OrderMagicNumber()==MagicNumber ) { int type = OrderType(); if (type==OP_BUY && !trade.ByEntered) trade.BuyEntered = true; if (type==OP_SELL && !trade.SellEntered) trade.SellEntered = true; if (type >OP_SELL && (trade.ByEntered || trade.BuyEntered)) OrderDelete(OrderTicket()); } } } 如果找到一个具有相同魔法号码和符号的正常订单,它将删除任何挂单。 ERAN123: 朋友们好我有一个关于挂单的问题。 我有两个挂单,分别是买入和卖出,一旦其中一个挂单成交,我将关闭另一个挂单。 我只是一个新手Mql程序员,它超出了我现在的能力。 任何方向的朋友???? 非常感谢。 EA不会在多对上运行,需要帮助 编码帮助 编码帮助......我如何让指标过滤而不是警报? ERAN123 2013.01.18 21:09 #1736 mladen 非常感谢,我将检查 它。 再次感谢 Mladen Rakic 2013.01.19 07:22 #1737 它应该可以正常工作 祝你周末愉快 ERAN123: mladen非常感谢,我将检查它。 再次感谢 qwertet 2013.02.04 16:08 #1738 交易员朋友们,你们好! 我已经做了几个月的交易,我想在mql4中编写一个策略。 我执行一个带有获利 的订单,像这样 "OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green); " 现在,当订单关闭时(T/P或S/L),我想做另一个同样的订单。 "OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green);" 以此类推,这样只要之前的买入被关闭,它就会引入一个买入头寸。 我几天前开始学习mql4,我被卡住了。请帮助我! Mladen Rakic 2013.02.04 17:06 #1739 你为什么不简单地计算一下当前开仓的订单数量(无论是买单还是卖单),当它为0时,开一个新仓? qwertet: 交易员朋友们,你们好!我已经用一个策略交易了几个月了,我正在尝试用mql4编程。 我执行一个带有获利的订单,像这样 "OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green); " 现在,当订单关闭时(T/P或S/L),我想做另一个同样的订单。 "OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green);" 以此类推,这样一来,只要之前的买入关闭,它就会引入一个买入头寸。 我几天前开始学习mql4,我在这个问题上卡住了。请帮助我! Kale 2013.02.04 19:07 #1740 qwertet: 以此类推,这样一来,只要之前的买入关闭,就会引入一个买入头寸。 我几天前开始学习mql4,我在这个问题上卡住了。请帮助我! 嘿,MLaden是对的--你需要计算订单来检查你是否准备好了新的订单。 以下是你可能想要使用的函数。 它将计算你已经从选定的魔法数字 和订单类型中打开了多少个订单。 如果您将-1作为您的订单类型,它将按选定的魔法数字计算所有订单。 请享用。 int orderCount(int type,int magic) { int oc = 0; for(int cnt = 0 ;cnt<OrdersTotal();cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); if(OrderMagicNumber() == magic && (OrderType() == type || type == -1)) oc+=1; } return(oc); } 1...167168169170171172173174175176177178179180181182 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
关于指标代码-----(3行)的问题
1.为什么在deinit中出现了2个标记的函数?
2.为什么720值在标记的行上?
解释一下这段代码。
//| DailyBreakout.mq4 |
//| Copyright © 2008, Robert Hill. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Robert Hill"
#property link "NONE"
#property indicator_chart_window
//---- input parameters
extern bool Alerts = false;
extern int GMTshift = 0;
extern int LabelShift = 20;
extern int LineShift = 40;
extern string pd = "PipsAboveBelowSR for Alert";
extern int PipDistance = 1;
extern color StandardFontColor = White;
extern int StandardFontSize = 8;
extern color SupportColor = Red;
extern color ResistanceColor = Lime;
datetime LabelShiftTime, LineShiftTime;
double yesterday_high=0;
double yesterday_low=0;
double LastHigh,LastLow,x;
double R1=0;
double S1=0;
bool firstS1=true;
bool firstR1=true;
double myPoint;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
myPoint = SetPoint(Symbol());
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
ObjectDelete("R1 Label");
ObjectDelete("R1 Line");
ObjectDelete("S1 Label");
ObjectDelete("S1 Line");
return(0);
}
double SetPoint(string mySymbol)// <<<<<<<-----why here on the deinit?????----------------
{
double mPoint, myDigits;
myDigits = MarketInfo (mySymbol, MODE_DIGITS);
if (myDigits < 4)
mPoint = 0.01;
else
mPoint = 0.0001;
return(mPoint);
}
int DoAlerts()//<<<<<<<<<-------why here on the deint??????-----------------
{
double DifAboveR1,PipsLimit;
double DifBelowS1;
DifBelowS1 = S1 - Close[0];
DifAboveR1 = Close[0] - R1;
PipsLimit = PipDistance * myPoint;
if (DifBelowS1 > PipsLimit) firstS1 = true;
if (DifBelowS1 0)
{
if (firstS1)
{
Alert("Below S1 Line by ",DifBelowS1, " for ", Symbol(),"-",Period());
PlaySound("alert.wav");
firstS1=false;
}
}
if (DifAboveR1 > PipsLimit) firstR1 = true;
if (DifAboveR1 0)
{
if (firstR1)
{
Alert("Above R1 Line by ",DifAboveR1," for ", Symbol(),"-",Period());
Sleep(2000);
PlaySound("timeout.wav");
firstR1=false;
}
}
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- TODO: add your code here
double day_high=0;
double day_low=0;
double yesterday_open=0;
double today_open=0;
double cur_day=0;
double prev_day=0;
int cnt=720;//<<<<<----why 720 ????????--------------------------------------------------
//---- exit if period is greater than 4 hr charts
if(Period() > 240)
{
Print("Error - Chart period is greater than 4 hr.");
return(-1); // then exit
}
//---- Get new daily prices & calculate pivots
cur_day=0;
prev_day=0;
//---- Get new daily prices & calculate pivots
while (cnt!= 0)
{
cur_day = TimeDay(Time[cnt]- (GMTshift*3600));
if (prev_day != cur_day)
{
yesterday_high = day_high;
yesterday_low = day_low;
day_high = High[cnt];
day_low = Low[cnt];
prev_day = cur_day;
}
if (High[cnt]>day_high)
{
day_high = High[cnt];
}
if (Low[cnt]<day_low)
{
day_low = Low[cnt];
}
cnt--;
}
S1 = yesterday_low;
R1 = yesterday_high;
LabelShiftTime = Time[LabelShift];
LineShiftTime = Time[LineShift];
//---- Set line labels on chart window
DisplayLabel("R1 label", "R1", R1, StandardFontSize, StandardFontColor);
DisplayLabel("S1 label", "S1", S1, StandardFontSize, StandardFontColor);
//--- Draw Pivot lines on chart
DisplayLine("S1 line", S1, 0, STYLE_DASHDOTDOT, SupportColor);
DisplayLine("R1 line", R1, 0, STYLE_DASHDOTDOT, ResistanceColor);
//---- done
// Now check for Alert
if (Alerts) DoAlerts();
//----
return(0);
}
//---- Set line labels on chart window
void DisplayLabel(string LabelName, string LabelText, double LabelPos, int LabelFontSize, color LabelColor)
{
if(ObjectFind(LabelName) != 0)
{
ObjectCreate(LabelName, OBJ_TEXT, 0, LabelShiftTime, LabelPos);
ObjectSetText(LabelName, LabelText, LabelFontSize, "Arial", LabelColor);
}
else
{
ObjectMove(LabelName, 0, LabelShiftTime, LabelPos);
}
}
//--- Draw Pivot lines on chart
void DisplayLine(string LineName, double LinePos, int LineWidth, int LineStyle, color LineColor)
{
if(ObjectFind(LineName) != 0)
{
ObjectCreate(LineName, OBJ_HLINE, 0, LineShiftTime, LinePos);
ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
ObjectSet(LineName, OBJPROP_COLOR, LineColor);
if (LineWidth > 0) ObjectSet(LineName, OBJPROP_WIDTH, LineWidth);
}
else
{
ObjectMove(LineName, 0, LineShiftTime, LinePos);
}
}
//+------------------------------------------------------------------+谢谢。
ERAN123
1.它们不在deinit()中,而只是在deinit()后面(在deinit()和start()之间)。 在mql中,你不需要遵循任何程序和函数 的编写顺序。你可以把init()放在代码的最后,它仍然可以工作。)
2.它将计算固定在每个刻度的720条。为什么?我认为你应该向作者询问这个问题。
1.为什么有两个标记的函数在deinit中?
2.为什么标记线上的720值?
代码。
//| DailyBreakout.mq4 |
//| Copyright © 2008, Robert Hill. |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Robert Hill"
#property link "NONE"
#property indicator_chart_window
//---- input parameters
extern bool Alerts = false;
extern int GMTshift = 0;
extern int LabelShift = 20;
extern int LineShift = 40;
extern string pd = "PipsAboveBelowSR for Alert";
extern int PipDistance = 1;
extern color StandardFontColor = White;
extern int StandardFontSize = 8;
extern color SupportColor = Red;
extern color ResistanceColor = Lime;
datetime LabelShiftTime, LineShiftTime;
double yesterday_high=0;
double yesterday_low=0;
double LastHigh,LastLow,x;
double R1=0;
double S1=0;
bool firstS1=true;
bool firstR1=true;
double myPoint;
//+------------------------------------------------------------------+
//| Custom indicator initialization function |
//+------------------------------------------------------------------+
int init()
{
//---- indicators
myPoint = SetPoint(Symbol());
//----
return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
//---- TODO: add your code here
//----
ObjectDelete("R1 Label");
ObjectDelete("R1 Line");
ObjectDelete("S1 Label");
ObjectDelete("S1 Line");
return(0);
}
double SetPoint(string mySymbol)// <<<<<<<-----why here on the deinit?????----------------
{
double mPoint, myDigits;
myDigits = MarketInfo (mySymbol, MODE_DIGITS);
if (myDigits < 4)
mPoint = 0.01;
else
mPoint = 0.0001;
return(mPoint);
}
int DoAlerts()//<<<<<<<<<-------why here on the deint??????-----------------
{
double DifAboveR1,PipsLimit;
double DifBelowS1;
DifBelowS1 = S1 - Close[0];
DifAboveR1 = Close[0] - R1;
PipsLimit = PipDistance * myPoint;
if (DifBelowS1 > PipsLimit) firstS1 = true;
if (DifBelowS1 0)
{
if (firstS1)
{
Alert("Below S1 Line by ",DifBelowS1, " for ", Symbol(),"-",Period());
PlaySound("alert.wav");
firstS1=false;
}
}
if (DifAboveR1 > PipsLimit) firstR1 = true;
if (DifAboveR1 0)
{
if (firstR1)
{
Alert("Above R1 Line by ",DifAboveR1," for ", Symbol(),"-",Period());
Sleep(2000);
PlaySound("timeout.wav");
firstR1=false;
}
}
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function |
//+------------------------------------------------------------------+
int start()
{
int counted_bars=IndicatorCounted();
//---- TODO: add your code here
double day_high=0;
double day_low=0;
double yesterday_open=0;
double today_open=0;
double cur_day=0;
double prev_day=0;
int cnt=720;//<<<<<----why 720 ????????--------------------------------------------------
//---- exit if period is greater than 4 hr charts
if(Period() > 240)
{
Print("Error - Chart period is greater than 4 hr.");
return(-1); // then exit
}
//---- Get new daily prices & calculate pivots
cur_day=0;
prev_day=0;
//---- Get new daily prices & calculate pivots
while (cnt!= 0)
{
cur_day = TimeDay(Time[cnt]- (GMTshift*3600));
if (prev_day != cur_day)
{
yesterday_high = day_high;
yesterday_low = day_low;
day_high = High[cnt];
day_low = Low[cnt];
prev_day = cur_day;
}
if (High[cnt]>day_high)
{
day_high = High[cnt];
}
if (Low[cnt]<day_low)
{
day_low = Low[cnt];
}
cnt--;
}
S1 = yesterday_low;
R1 = yesterday_high;
LabelShiftTime = Time[LabelShift];
LineShiftTime = Time[LineShift];
//---- Set line labels on chart window
DisplayLabel("R1 label", "R1", R1, StandardFontSize, StandardFontColor);
DisplayLabel("S1 label", "S1", S1, StandardFontSize, StandardFontColor);
//--- Draw Pivot lines on chart
DisplayLine("S1 line", S1, 0, STYLE_DASHDOTDOT, SupportColor);
DisplayLine("R1 line", R1, 0, STYLE_DASHDOTDOT, ResistanceColor);
//---- done
// Now check for Alert
if (Alerts) DoAlerts();
//----
return(0);
}
//---- Set line labels on chart window
void DisplayLabel(string LabelName, string LabelText, double LabelPos, int LabelFontSize, color LabelColor)
{
if(ObjectFind(LabelName) != 0)
{
ObjectCreate(LabelName, OBJ_TEXT, 0, LabelShiftTime, LabelPos);
ObjectSetText(LabelName, LabelText, LabelFontSize, "Arial", LabelColor);
}
else
{
ObjectMove(LabelName, 0, LabelShiftTime, LabelPos);
}
}
//--- Draw Pivot lines on chart
void DisplayLine(string LineName, double LinePos, int LineWidth, int LineStyle, color LineColor)
{
if(ObjectFind(LineName) != 0)
{
ObjectCreate(LineName, OBJ_HLINE, 0, LineShiftTime, LinePos);
ObjectSet(LineName, OBJPROP_STYLE, LineStyle);
ObjectSet(LineName, OBJPROP_COLOR, LineColor);
if (LineWidth > 0) ObjectSet(LineName, OBJPROP_WIDTH, LineWidth);
}
else
{
ObjectMove(LineName, 0, LineShiftTime, LinePos);
}
}
//+------------------------------------------------------------------+嗨,mladen
谢谢你的回放。
1.刚刚注意到这个问题(我把这个问题搞错了,没有注意到)。
2.它是真正的奥秘![](https://c.mql5.com/forextsd/smiles/regular_smile.png)
待处理的订单 需要简单的帮助 !!!!!!!!
朋友们好
我有一个关于挂单的问题。
我有2个挂单,买入和卖出,一旦其中一个被击中,我就会关闭另一个。
我只是一个新手mql程序员,它超出了我现在的能力。
任何方向的朋友????
非常感谢。
你可以使用这样的东西。
{
bool trade.BuyEntered = false;
bool trade.SellEntered = false;
for (int i=OrdersTotal()-1; i>=0; i--)
{
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
//
//
//
//
//
if ( OrderSymbol()==trade.symbol && OrderMagicNumber()==MagicNumber )
{
int type = OrderType();
if (type==OP_BUY && !trade.ByEntered) trade.BuyEntered = true;
if (type==OP_SELL && !trade.SellEntered) trade.SellEntered = true;
if (type >OP_SELL && (trade.ByEntered || trade.BuyEntered))
OrderDelete(OrderTicket());
}
}
}
如果找到一个具有相同魔法号码和符号的正常订单,它将删除任何挂单。
朋友们好
我有一个关于挂单的问题。
我有两个挂单,分别是买入和卖出,一旦其中一个挂单成交,我将关闭另一个挂单。
我只是一个新手Mql程序员,它超出了我现在的能力。
任何方向的朋友????
非常感谢。mladen
非常感谢,我将检查 它。
再次感谢![](https://c.mql5.com/forextsd/smiles/You_Rock_Emoticon.png)
它应该可以正常工作
祝你周末愉快![](https://c.mql5.com/forextsd/smiles/smile.png)
mladen
非常感谢,我将检查它。
再次感谢交易员朋友们,你们好!
我已经做了几个月的交易,我想在mql4中编写一个策略。
我执行一个带有获利 的订单,像这样
"OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green); "
现在,当订单关闭时(T/P或S/L),我想做另一个同样的订单。
"OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green);"
以此类推,这样只要之前的买入被关闭,它就会引入一个买入头寸。
我几天前开始学习mql4,我被卡住了。请帮助我!
你为什么不简单地计算一下当前开仓的订单数量(无论是买单还是卖单),当它为0时,开一个新仓?
交易员朋友们,你们好!
我已经用一个策略交易了几个月了,我正在尝试用mql4编程。
我执行一个带有获利的订单,像这样
"OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green); "
现在,当订单关闭时(T/P或S/L),我想做另一个同样的订单。
"OrderSend(Symbol(), OP_BUY, lots, Ask, 10, 30, Ask+takeprofit, "test", 12345, 0, Green);"
以此类推,这样一来,只要之前的买入关闭,它就会引入一个买入头寸。
我几天前开始学习mql4,我在这个问题上卡住了。请帮助我!以此类推,这样一来,只要之前的买入关闭,就会引入一个买入头寸。
我几天前开始学习mql4,我在这个问题上卡住了。请帮助我!嘿,MLaden是对的--你需要计算订单来检查你是否准备好了新的订单。
以下是你可能想要使用的函数。
它将计算你已经从选定的魔法数字 和订单类型中打开了多少个订单。
如果您将-1作为您的订单类型,它将按选定的魔法数字计算所有订单。
请享用。
int orderCount(int type,int magic)
{
int oc = 0;
for(int cnt = 0 ;cnt<OrdersTotal();cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == magic && (OrderType() == type || type == -1))
oc+=1;
}
return(oc);
}