新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 1644 1...163716381639164016411642164316441645164616471648164916501651...1953 新评论 Tretyakov Rostyslav 2021.10.03 12:17 #16431 Andrey Sokolov 终端关闭 或指示器重新启动时才会显示。 2张截图,除了第一张,没有移动,错误5019(文件不存在),尽管它们显示在文件夹中(除了第一张由定时器制作)。 市场已经关闭,计时器在测试器中不起作用。 Tretyakov Rostyslav 2021.10.03 12:26 #16432 Andrey Sokolov 终端关闭 或指示器重新启动时才会显示。 2张截图,除了第一张,没有被移动,错误5019(文件不存在),尽管它们被显示在一个文件夹中(除了第一张由定时器制作的)。 在cripta上检查,所有的截图都是如此,但有一个移动错误 2021.10.03 15:23:56.384 Scrin BTCUSD,M5: screen name_file 2021.10.03 15-23-56.png 2021.10.03 15:23:56.367 Scrin BTCUSD,M5: FileMove ERR: 4051 2021.10.03 15:23:56.367 Scrin BTCUSD,M5: OnTimer() 2021.10.03 15:23:51.391 Scrin BTCUSD,M5: screen name_file 2021.10.03 15-23-51.png 2021.10.03 15:23:51.374 Scrin BTCUSD,M5: FileMove ERR: 4051 2021.10.03 15:23:51.374 Scrin BTCUSD,M5: OnTimer() 2021.10.03 15:23:46.378 Scrin BTCUSD,M5: screen name_file 2021.10.03 15-23-46.png 2021.10.03 15:23:46.360 Scrin BTCUSD,M5: FileMove ERR: 4051 2021.10.03 15:23:46.360 Scrin BTCUSD,M5: OnTimer() Tretyakov Rostyslav 2021.10.03 13:09 #16433 MakarFX #:检查了地穴上的所有截图,但有一个位移错误这就是它的作用。//+------------------------------------------------------------------+ bool Move(){ string src_path=name_file; string dst_path=name_folder+"//"+name_file; ResetLastError(); if(FileMove(src_path,0,dst_path,0)){ Print("FileMove OK "); return true; } else{ string err_text="FileMove ERR: "+(string)GetLastError(); if(GetLastError()==5019) err_text+=(" 5019 name_file "+name_file); Print(err_text); } return false; } 为什么一开始要费心搬家? EVGENII SHELIPOV 2021.10.03 14:12 #16434 MakarFX #:将各项功能分开,使你更容易浏览。 下面是一个OnTick()的例子正如你所看到的,这里只有对函数的调用 日安,Makar,我已经重新制作了代码,并在日志中实现了计算平均价格的功能,没有错误,但没有从平均价格中拖出。 //+----------------------------------------------------------------------------+ //| Расчет среденй цены | //+----------------------------------------------------------------------------+ double GetAveragePrice() { order_lots = 0; price = 0; { for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { price += OrderOpenPrice() * OrderLots(); order_lots += OrderLots(); avg_price = NormalizeDouble(price / order_lots, Digits); { ObjectDelete(0, "AveragePriceLine"); ObjectCreate(0,"AveragePriceLine" ,OBJ_HLINE, 0, 0, avg_price); ObjectSet("AveragePriceLine",OBJPROP_COLOR, Magenta); } } } } } } return(avg_price); } //+----------------------------------------------------------------------------+ //| Модификация групповых ордеров | //+----------------------------------------------------------------------------+ void ModifyOrders(int otype) { for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype) { if (otype == OP_BUY) tp = NormalizeDouble (GetAveragePrice() + TakeProfitGroupOrder*Point, Digits); if (otype == OP_SELL) tp = NormalizeDouble (GetAveragePrice() - TakeProfitGroupOrder*Point, Digits); if ((otype == OP_BUY || otype == OP_SELL) && (Drawdown > DrawdownClosingTakeprofitZero)) tp = NormalizeDouble (GetAveragePrice(), Digits); } } } for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype) { if(OrderModify(OrderTicket(), OrderOpenPrice(), 0, tp, 0)) Print("Ордера успешно модифицированы!"); else Print("Ошибка модификации ордеров!"); TrailingGroupOrder(); } } } } //+----------------------------------------------------------------------------+ //| Трейлинг стоп групповых ордеров | //+----------------------------------------------------------------------------+ void TrailingGroupOrder() { for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderType() == OP_BUY && Bid - GetAveragePrice() > TrailingStopGroupOrder*Point) { if(Bid - GetAveragePrice() > TrailingStopGroupOrder*Point || OrderStopLoss() == 0) { if(OrderStopLoss() < Bid - (TrailingStep + TrailingStopGroupOrder )*Point || OrderStopLoss() == 0) { if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - TrailingStopGroupOrder*Point, Digits), tp, 0)) Print("Ошибка модификации групповых ордеров на покупку!"); } } } if(OrderType() == OP_SELL && GetAveragePrice() - Ask > TrailingStopGroupOrder*Point) { if(GetAveragePrice() - Ask > TrailingStopGroupOrder*Point || OrderStopLoss() == 0) { if(OrderStopLoss() > Ask + (TrailingStep + TrailingStopGroupOrder)*Point || OrderStopLoss() == 0) { if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + TrailingStopGroupOrder*Point, Digits), tp, 0)) Print("Ошибка модификации групповых ордеров на продажу!"); } } } } } } 我采取的原则是,从这个函数中设置一个拖网,用于单笔订单的工作,没有失败。 //+----------------------------------------------------------------------------+ //| Трейлинг стоп одиночных ордеров | //+----------------------------------------------------------------------------+ void Trailing() { for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { if(OrderType() == OP_BUY && Bid - OrderOpenPrice() > TrailingStopFirstOrder*Point) { if(Bid - OrderOpenPrice() > TrailingStopFirstOrder*Point || OrderStopLoss() == 0) { if(OrderStopLoss() < Bid - (TrailingStep + TrailingStopFirstOrder)*Point || OrderStopLoss() == 0) { if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - TrailingStopFirstOrder*Point, Digits), tp, 0)) Print("Ошибка модификации ордера на покупку!"); } } } if(OrderType() == OP_SELL && OrderOpenPrice() - Ask > TrailingStopFirstOrder*Point) { if(OrderOpenPrice() - Ask > TrailingStopFirstOrder*Point || OrderStopLoss() == 0) { if(OrderStopLoss() > Ask + (TrailingStep + TrailingStopFirstOrder)*Point || OrderStopLoss() == 0) { if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + TrailingStopFirstOrder*Point, Digits), tp, 0)) Print("Ошибка модификации ордера на продажу!"); } } } } } } } Tretyakov Rostyslav 2021.10.03 14:39 #16435 EVGENII SHELIPOV #:日安,Makar,我已经重新设计了计算平均价格的代码,但平均价格的拖网没有出现在日志中。我从这个功能中提取了线索设置原则,用于单笔订单,效果完美无缺下面是它的工作原理...//+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- if(CountTrade()>1) TrailingGroupOrder(); } //+----------------------------------------------------------------------------+ //| Расчет среденй цены | //+----------------------------------------------------------------------------+ double GetAveragePrice() { order_lots = 0; price = 0; { for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { price += OrderOpenPrice() * OrderLots(); order_lots += OrderLots(); avg_price = NormalizeDouble(price / order_lots, Digits); ObjectDelete(0, "AveragePriceLine"); ObjectCreate(0,"AveragePriceLine" ,OBJ_HLINE, 0, 0, avg_price); ObjectSet("AveragePriceLine",OBJPROP_COLOR, Magenta); } } } } } return(avg_price); } //+----------------------------------------------------------------------------+ //| Трейлинг стоп групповых ордеров | //+----------------------------------------------------------------------------+ void TrailingGroupOrder() { for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderType() == OP_BUY) { if(Bid - GetAveragePrice() > TrailingStopGroupOrder*Point || OrderStopLoss() == 0) { if(OrderStopLoss() < Bid - (TrailingStep + TrailingStopGroupOrder )*Point || OrderStopLoss() == 0) { if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - TrailingStopGroupOrder*Point, Digits), tp, 0)) Print("Ошибка модификации групповых ордеров на покупку!"); } } } if(OrderType() == OP_SELL) { if(GetAveragePrice() - Ask > TrailingStopGroupOrder*Point || OrderStopLoss() == 0) { if(OrderStopLoss() > Ask + (TrailingStep + TrailingStopGroupOrder)*Point || OrderStopLoss() == 0) { if(!OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + TrailingStopGroupOrder*Point, Digits), tp, 0)) Print("Ошибка модификации групповых ордеров на продажу!"); } } } } } } //+----------------------------------------------------------------------------+ //| Модификация групповых ордеров | //+----------------------------------------------------------------------------+ void ModifyOrders(int otype) { for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype) { if (otype == OP_BUY) { tp = NormalizeDouble (GetAveragePrice() + TakeProfitGroupOrder*Point, Digits); if(OrderModify(OrderTicket(), OrderOpenPrice(), 0, tp, 0)) Print("Ордера успешно модифицированы!"); else Print("Ошибка модификации ордеров!"); } if (otype == OP_SELL) { tp = NormalizeDouble (GetAveragePrice() - TakeProfitGroupOrder*Point, Digits); if(OrderModify(OrderTicket(), OrderOpenPrice(), 0, tp, 0)) Print("Ордера успешно модифицированы!"); else Print("Ошибка модификации ордеров!"); } } } } } 我调整了功能--删除了不必要的 Andrei Sokolov 2021.10.03 14:43 #16436 MakarFX #:所以它是有效的。 你确定它有用吗?我,用这个选项,仍然有所有的问题。而且是mt5。 Andrei Sokolov 2021.10.03 14:44 #16437 MakarFX #: 为什么大惊小怪地要搬家? 要分类 Tretyakov Rostyslav 2021.10.03 14:48 #16438 Andrey Sokolov #:用于分拣 也是分类,但没有额外的功能 #property strict #property indicator_chart_window #property indicator_plots 0 enum ENUM_FULL_MANUAL { full, //весь график manual, //указанный }; input int timer=5; //время на шаг в секундах input ENUM_FULL_MANUAL skr_mode=full; //размер скриншота input int width = 640; // ширина input int height = 320;// высота input string format = ".png"; ENUM_ALIGN_MODE align_mode=ALIGN_RIGHT; // тип выравнивания string name_folder, name_file; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int OnInit() { EventSetTimer(timer); Print("OnInit()"); name_folder=Symbol()+" "+StringPeriod(); ScreenShot(); return(INIT_SUCCEEDED); } //=================================================================== void OnDeinit(const int reason) { EventKillTimer(); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int OnCalculate(const int rates_total, const int prev_calculated, const datetime &time[], const double &open[], const double &high[], const double &low[], const double &close[], const long &tick_volume[], const long &volume[], const int &spread[]) { //--- //--- return value of prev_calculated for next call return(rates_total); } //+------------------------------------------------------------------+ //| Timer function | //+------------------------------------------------------------------+ void OnTimer() { Print("OnTimer() "); ScreenShot(); } //+------------------------------------------------------------------+ bool ScreenShot(){ name_file=TimeToString(TimeLocal(), TIME_DATE|TIME_SECONDS)+format; StringReplace(name_file, ":", "-"); if(skr_mode==full){ if(ChartScreenShot(0, name_folder+"//"+name_file, (int)ChartGetInteger(0, CHART_WIDTH_IN_PIXELS, 0) , (int)ChartGetInteger(0, CHART_HEIGHT_IN_PIXELS, 0), ALIGN_RIGHT)){ Print("screen name_file ", name_file); return true; } else{ Print("screen ERR: ", GetLastError()); } } if(skr_mode==manual){ if(ChartScreenShot(0, name_file, width, height, align_mode)){ return true; } } return false; } string StringPeriod(){ if(Period()==1) return "M1"; if(Period()==2) return "M2"; if(Period()==3) return "M3"; if(Period()==4) return "M4"; if(Period()==5) return "M5"; if(Period()==6) return "M6"; if(Period()==10) return "M10"; if(Period()==12) return "M12"; if(Period()==15) return "M15"; if(Period()==20) return "M20"; if(Period()==30) return "M30"; if(Period()==16385) return "H1"; if(Period()==16386) return "H2"; if(Period()==16387) return "H3"; if(Period()==16388) return "H4"; if(Period()==16390) return "H6"; if(Period()==16392) return "H8"; if(Period()==16396) return "H12"; if(Period()==16408) return "Daily"; if(Period()==32769) return "Weekly"; if(Period()==49153) return "Monthly"; return "ERROR"; } Tretyakov Rostyslav 2021.10.03 14:51 #16439 Andrey Sokolov #:你确定它有用吗?我,用这个选项,仍然有所有的问题。而且是mt5。对不起,我写的是4...签到了5个!一切正常。2021.10.03 17:55:54.192 Scrin (BTCUSD,M5) OnTimer() 2021.10.03 17:55:54.195 Scrin (BTCUSD,M5) screen name_file 2021.10.03 17-55-54.png 2021.10.03 17:55:59.211 Scrin (BTCUSD,M5) OnTimer() 2021.10.03 17:55:59.213 Scrin (BTCUSD,M5) screen name_file 2021.10.03 17-55-59.png 2021.10.03 17:56:04.214 Scrin (BTCUSD,M5) OnTimer() 2021.10.03 17:56:04.217 Scrin (BTCUSD,M5) screen name_file 2021.10.03 17-56-04.png 2021.10.03 17:56:09.204 Scrin (BTCUSD,M5) OnTimer() 2021.10.03 17:56:09.236 Scrin (BTCUSD,M5) screen name_file 2021.10.03 17-56-09.png 2021.10.03 17:56:14.202 Scrin (BTCUSD,M5) OnTimer() 2021.10.03 17:56:14.205 Scrin (BTCUSD,M5) screen name_file 2021.10.03 17-56-14.png 附加的文件: Scrin.mq5 8 kb EVGENII SHELIPOV 2021.10.03 15:03 #16440 MakarFX #:情况是这样的... 我对功能进行了调整 - 我删除了不必要的 Makar,你能不能澄清一下代码中提到的函数是指哪里? //+----------------------------------------------------------------------------+ //| Модификация групповых ордеров | //+----------------------------------------------------------------------------+ void ModifyOrders(int otype) { for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype) { if (otype == OP_BUY) tp = NormalizeDouble (GetAveragePrice() + TakeProfitGroupOrder*Point, Digits); if (otype == OP_SELL) tp = NormalizeDouble (GetAveragePrice() - TakeProfitGroupOrder*Point, Digits); if ((otype == OP_BUY || otype == OP_SELL) && (Drawdown > DrawdownClosingTakeprofitZero)) tp = NormalizeDouble (GetAveragePrice(), Digits); } } } for(int i = OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderType() == otype) { if(OrderModify(OrderTicket(), OrderOpenPrice(), 0, tp, 0)) Print("Ордера успешно модифицированы!"); else Print("Ошибка модификации ордеров!"); TrailingGroupOrder(); } } } } 1...163716381639164016411642164316441645164616471648164916501651...1953 新评论 您错过了交易机会: 免费交易应用程序 8,000+信号可供复制 探索金融市场的经济新闻 注册 登录 拉丁字符(不带空格) 密码将被发送至该邮箱 发生错误 使用 Google 登录 您同意网站政策和使用条款 如果您没有帐号,请注册 可以使用cookies登录MQL5.com网站。 请在您的浏览器中启用必要的设置,否则您将无法登录。 忘记您的登录名/密码? 使用 Google 登录
2张截图,除了第一张,没有移动,错误5019(文件不存在),尽管它们显示在文件夹中(除了第一张由定时器制作)。
2张截图,除了第一张,没有被移动,错误5019(文件不存在),尽管它们被显示在一个文件夹中(除了第一张由定时器制作的)。
在cripta上检查,所有的截图都是如此,但有一个移动错误
检查了地穴上的所有截图,但有一个位移错误
这就是它的作用。
为什么一开始要费心搬家?将各项功能分开,使你更容易浏览。
下面是一个OnTick()的例子
正如你所看到的,这里只有对函数的调用
日安,Makar,我已经重新制作了代码,并在日志中实现了计算平均价格的功能,没有错误,但没有从平均价格中拖出。
我采取的原则是,从这个函数中设置一个拖网,用于单笔订单的工作,没有失败。
日安,Makar,我已经重新设计了计算平均价格的代码,但平均价格的拖网没有出现在日志中。
我从这个功能中提取了线索设置原则,用于单笔订单,效果完美无缺
下面是它的工作原理...
我调整了功能--删除了不必要的所以它是有效的。
你确定它有用吗?我,用这个选项,仍然有所有的问题。而且是mt5。
为什么大惊小怪地要搬家?
要分类
用于分拣
也是分类,但没有额外的功能
你确定它有用吗?我,用这个选项,仍然有所有的问题。而且是mt5。
对不起,我写的是4...
签到了5个!一切正常。
情况是这样的...
我对功能进行了调整 - 我删除了不必要的Makar,你能不能澄清一下代码中提到的函数是指哪里?