创建一个机器人 - 页 5

 

增加了两个按钮--用于设置水平线

-------------------------------------------------


附加的文件:
ioia3x_0004.PNG  96 kb
0004.mq5  44 kb
 

增加了水平线趋势线 的命令

//+------------------------------------------------------------------+
//|                                                         0005.mq5 |
//|                        Copyright 2020, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#define    InpMagic  182979245
//---
#include <Trade\PositionInfo.mqh>
#include <Trade\Trade.mqh>
#include <Trade\SymbolInfo.mqh>
//---
CPositionInfo  m_position; // trade position object
CTrade         m_trade;    // trading object
CSymbolInfo    m_symbol;   // symbol info object
//+------------------------------------------------------------------+
//| ENUM_TRADE_COMMAND                                               |
//+------------------------------------------------------------------+
enum ENUM_TRADE_COMMAND
  {
   Turn_Off=0,       // TURN  OFF
   UpName=1,         // Line UpName
   DownName=2,       // Line DownName
   UpName_s=3,       // Line UpName + Open Sell
   UpName_b=4,       // Line UpName + Open Buy
   DownName_b=5,     // Line DownName + Open Buy
   DownName_s=6,     // Line DownName + Open Sell
   close_buys=7,     // Close All Buy's
   close_sells=8,    // Close All Sell's
   close_all=9,      // Close All Buy's and Sell's
   open_buy=10,      // Open  Buy
   open_sell=11,     // Open  Sell
   close_open_b=12,  // Close Sell + Open Buy
   close_open_s=13,  // Close Buy + Open Sell
   open_buy_sell=14, // Open  Buy and Sell
  };
//+------------------------------------------------------------------+
input string   t="----- Lots                -----";              //
input double   InpLots                      = 0.01;              // Lots
input string   t0="---- Line Name           -----";              //
input string   InpObjUpName                 = "Имя Линии Up";    // Obj: Up (Trailing Horizontal Line) or Trend Line)
input ENUM_TRADE_COMMAND InpTradeCommand    = UpName_s;          // Obj:  command: UP
input string   InpObjDownName               = "Имя Линии Down";  // Obj: Down (Trailing Horizontal Line) or Trend Line)
input ENUM_TRADE_COMMAND InTradeCommand     = DownName_b;        // Obj:  command: DOWN
input ushort   InpObjStep                   = 15;                // Obj: Step (distance from price to object, in pips)
input string   t1="---- Indicators: UP      -----";              //
input bool     InpIndicatorsUp              = false;             // Indicators: Start (true)
input ENUM_TRADE_COMMAND InpTradeCommandY1  = open_buy;          // Trade command: ( Buy )
input ENUM_TRADE_COMMAND InpTradeCommandU1  = open_sell;         // Trade command: ( Sell )
input string   t2="---- Indicators:         -----";              //
input bool     InpIndicators                = false;             // Indicators: Start (true)
input ENUM_TRADE_COMMAND InpTradeCommandY   = close_sells;       // Trade command: ( Buy )
input ENUM_TRADE_COMMAND InpTradeCommandU   = close_buys;        // Trade command: ( Sell )
//---
double   m_adjusted_point;                // point value adjusted for 3 or 5 points
int      handle_iCustomUp;                // variable for storing the handle of the iStochastic indicator
int      handle_iCustom;                  // variable for storing the handle of the iStochastic indicator
datetime ExtPrevBarsUp           = 0;     // "0" -> D'1970.01.01 00:00';
datetime ExtPrevBars             = 0;     // "0" -> D'1970.01.01 00:00';
double   m_obj_step              = 0.0;   // Obj: Trailing Stop   -> double
uint     SLEEPTIME               = 1;     // Время паузы между повторами в секундах
ushort   InpSignalsFrequency     = 1;     // Search signals, in seconds (min value "1")
datetime ExtLastSignalsRx        = 0;     // "0" -> D'1970.01.01 00:00';
datetime ExtPrevBarsRx           = 0;     // "0" -> D'1970.01.01 00:00';
datetime ExtLastSignalsSx        = 0;     // "0" -> D'1970.01.01 00:00';
datetime ExtPrevBarsSx           = 0;     // "0" -> D'1970.01.01 00:00';
bool     ExtTurnOff              = false; //
bool     ExtUpName               = false; //
bool     ExtDownName             = false; //
bool     ExtNeedCloseBuy         = false; //
bool     ExtNeedCloseSell        = false; //
bool     ExtNeedCloseAll         = false; //
bool     ExtNeedOpenBuy          = false; //
bool     ExtNeedOpenSell         = false; //
bool     ExtNeedOpenBuySell      = false; //
//+------------------------------------------------------------------+
附加的文件:
0005.mq5  101 kb
 
SanAlex:

增加了水平线趋势线 的命令

祝大家有一个愉快的一天和良好的心情!

罗曼的要求是什么?以下是他第一篇帖子中的一段话:"完全的程序,要在交易开始时打开,请解释什么是什么。帮了很多忙。"

只添加代码而不解释它们 的用途是没有用的!

罗曼,你对这种情况的解决方案和我的完全一样。以CodeBase的任何一个简单的专家顾问为例,嗯,至少这个https://www.mql5.com/ru/code/138

在MetaEditor中打开其代码,开始研究每一行代码中的注释。有的EA的所有评论都是用英语写的。如果你不太懂语言,谷歌翻译会帮助你。如果在任何一个专家顾问中,缺少对行的注释,那么依次搜索程序代码中所有的彩色单词,将光标放在上面,按下F1键,MQL5手册的相应章节将为你打开。阅读这些部分,用你自己的话评论这些行文,如果有不清楚的地方,就在这里提出问题。这样,你在学习编程语言时就会进展得更快。

问候,弗拉基米尔。

Советник "Метод Пуриа"
Советник "Метод Пуриа"
  • www.mql5.com
Предлагается использовать следующие валютные пары в торговой стратегии форекс "Метод Пуриа" : AUDJPY - M30 - 15 пунктов (т.е. закрываем сделку при 15 пипсов тейк-профита) NZDUSD - 1H - 25 пунктов USDCAD - H1 - 20 пунктов EURGBP - H1 - 10 пунктов USDJPY - M30 - 15 пунктов GBPUSD - М30 - 20 пунктов USDCHF - M30 - 10 пунктов EURCHF - H1 - 15...
 
MrBrooklin:

大家今天好,心情好

罗曼的要求是什么?以下是他第一篇帖子中的一段话:"完全是程序,关于开始交易时,请解释什么是什么。帮了很多忙。"

简单地添加代码而不作解释,对他来说是没有用的!

罗曼,你在这种情况下的解决方案和我的完全一样。以CodeBase的任何一个简单的专家顾问为例,嗯,至少这个https://www.mql5.com/ru/code/138

在MetaEditor中打开其代码,开始研究每一行代码中的注释。有的EA的所有评论都是用英语写的。如果你不太懂语言,谷歌翻译会帮助你。如果在任何专家顾问中,缺少对行的注释,那么依次搜索程序代码中的所有彩色单词,将光标设置在这些单词上,按下F1键,MQL5手册的相应章节将为您打开。阅读这些部分,用你自己的话评论这些行文,如果有不清楚的地方,就在这里提出问题。这样一来,你在学习编程语言方面的进展就会更快。

问候,弗拉基米尔。

我不明白--删除我欺骗的东西是否更好?- 那他自己,怎么学?

 
SanAlex:

我不明白--删除我所做的事情是不是更好?- 以便他能自己学习?

不是删除, 而是解释代码中的内容,以及为什么要这样做!

真诚的,弗拉基米尔。

 
MrBrooklin:

不是删除, 而是解释代码中的内容,以及为什么要这样做!

尊敬的弗拉基米尔。

我自己是自学成才的--我自己从现有的代码中复制,--问题是我不知道如何解释如何雕刻!?- 内心的东西告诉我如何去雕刻。

----------------------------------

我知道我所塑造的是什么,缺少的是这条线路的Thrall。

 
SanAlex:

我自己是自学成才的--我自己从现有的代码中复制,--问题是我不知道如何解释如何雕刻!?- 内心的东西告诉我如何去雕刻。

这正是问题所在!当我开始学习MQL5语言时,我读了很多关于创建专家顾问 的文章。 起步 我还没有找到它。当然,有一些文章与罗曼的链接,但它们是不够的,至少对我来说。

例如,我自己看到了很多EA代码,但没有办法理解为什么要写这一行或那一行。到目前为止,我已经设法从一个现成的专家顾问中为自己重写代码。

问候,弗拉基米尔。

 
MrBrooklin:

这就是问题所在!当我开始学习MQL5语言时,我已经读了很多关于EA开发的 文章。 初学者 我还没有找到它。当然,有一些文章与罗曼的链接,但它们是不够的,至少对我来说。

例如,我自己看到很多专家顾问的代码,但我无法理解为什么要写这一行或那一行。到目前为止,我已经有足够的头脑从一个现成的专家顾问中为自己重写代码。

真诚的,弗拉基米尔。

我正在为我的任务寻找函数--当我开始了解一个函数的工作原理时,我就把它拆开,然后一切就容易学了。

 
SanAlex:

我为我的任务寻找函数--当我开始了解它的工作原理时,我把函数拆开,然后一切就容易学习了。

下面是我纠结了一个多小时的一个问题的现场例子。我需要它在EA开始时在图表上创建并显示ZigZagColor指标。这是在int OnInit中完成的。

   handle_iCustom=iCustom(m_symbol.Name(),Period(),"Examples\\ZigzagColor",
                          Inp_ZZ_Depth,
                          Inp_ZZ_Deviation,
                          Inp_ZZ_Backstep);
   ChartIndicatorAdd(ChartID(),0,handle_iCustom);

该指标被创建并显示。现在我需要在专家顾问被删除 后,将该指标删除。我正在写。

void OnDeinit(const int reason)
  {
//---
   IndicatorRelease(handle_iCustom);
   ObjectsDeleteAll(0,"Examples\\ZigzagColor");
  }

但指标没有被删除。我已经把一切都整理好了。我已经清理了手柄并应用了删除功能。我想知道它没有卸载的原因是什么。

问候,弗拉基米尔。

 
MrBrooklin:

下面是我纠结了一个多小时的一个问题的现场例子。我希望在启动EA时,ZigZagColor指标能被创建并显示在图表上。这是在int OnInit中完成的。

该指标被创建并显示。现在我需要在专家顾问被删除后,将该指标删除。我正在写。

但指标没有被删除。我已经把一切都整理好了。我已经清理了手柄并应用了删除功能。我想知道它没有卸载的原因是什么。

问候,弗拉基米尔。

有一个更复杂的功能用于删除

input string   t12="--- Indicator Delete    -----";              //
input string   Inpshort_name                = "Имя Индикатора";  // Delete Indicator Name
input string   Inpshort_name_1              = "Имя Индикатора";  // Delete Indicator Name
input bool     Inpres                       = false;             // Delete All Indicators
//+------------------------------------------------------------------+
//| ChartIndicatorDelete                                             |
//+------------------------------------------------------------------+
bool IndicatorDelete(void)
  {
     {ActionsOnTheChart(0);}
//---
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ActionsOnTheChart(const long chart_id)
  {
   int sub_windows_total =-1;
   int indicators_total  =0;
//---
   if(!ChartWindowsTotal(chart_id,sub_windows_total))
     {
      return(false);
     }
//---
   for(int i=sub_windows_total-1; i>=0; i--)
     {
      indicators_total=ChartIndicatorsTotal(chart_id,i);
      //---
      if(indicators_total>0)
        {
         ChIndicatorsDelete(chart_id,i,indicators_total);
        }
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ChartWindowsTotal(const long chart_ID,int &sub_windows_total)
  {
   long value=-1;
//---
   if(!ChartGetInteger(chart_ID,CHART_WINDOWS_TOTAL,0,value))
     {Print(__FUNCTION__," Error = ",GetLastError()); return(false);}
//---
   sub_windows_total=(int)value;
//---
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ChIndicatorsDelete(const long  chart_id,
                        const int   sub_window,
                        const int   indicators_total)
  {
   for(int i=indicators_total-1; i>=0; i--)
     {
      string indicator_name=ChartIndicatorName(chart_id,sub_window,i);
      //---
      ChIndicatorDelete(indicator_name,chart_id,sub_window);
      ChartRedraw();
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool ChIndicatorDelete(const string shortname,
                       const long   chartid=0,
                       const int    subwindow=0)
  {
   bool res=ChartIndicatorDelete(chartid,subwindow,Inpshort_name);
   bool res2=ChartIndicatorDelete(chartid,subwindow,Inpshort_name_1);
   if(Inpres)
      bool res0=ChartIndicatorDelete(chartid,subwindow,shortname);
//--- проанализируем результат вызова ChartIndicatorDelete()
   if(!res)
     {
      PrintFormat("%s",shortname,subwindow,GetLastError());
     }
//---
   return(true);
  }
//+------------------------------------------------------------------+