新人对MQL4和MQL5的任何问题,对算法和代码的帮助和讨论 - 页 1488

 
de_leonid:

谢谢你的帮助。我还可以要求提供一个EA的例子(部分代码),说明如何从EA的这些行中获得价值。

我为自己做了一个专家顾问https://www.mql5.com/ru/code/34046-,可以对水平线或趋势线进行操作。

你需要从Tymen_STARC_Bands_MTF 中知道水平线的名称。

这里是他们的名字

string   m_r2_name      = "Highest";
string   m_r1_name      = "Top";
string   m_0_name       = "Middle";
string   m_s1_name      = "Bottom";
string   m_s2_name      = "Lowest";

并将其输入到专家顾问中,并设置指令

这里

sinput group "----------------- Trade Line UP ------------------------"
sinput ENUM_MODE          FilterLine_13              = mode_All;         // FILTER: ВКЛ.ВЫКЛ.
sinput ENUM_TIMEFRAMES    InpPeriod_Up               = PERIOD_CURRENT;   // Period
sinput ENUM_TRADE_COMMAND InpCommandOpenedUp         = open_buy;         // Trade command:
sinput string             InpNameAverageUp           = "Line Up";        // Line Name UP(Horizontal Line or Trend Line)
sinput ENUM_TRADE_COMMAND InpCommandOpenedUpLow      = open_sell;        // Trade command:
sinput bool               InpDelLineUp               = false;            // Delete (Horizontal Line or Trend Line)
sinput double             InpObjStepTradeUp          = 0;                // Obj: Distance from price to object, in pips
sinput color              InpObjAverageclrUp         = clrBlue;          // EA only monitors this lines color
sinput group "----------------- Trade Line_2 UP ----------------------"
sinput ENUM_MODE          FilterLine_15              = mode_All;         // FILTER: ВКЛ.ВЫКЛ.
sinput ENUM_TIMEFRAMES    InpPeriod_Up_2             = PERIOD_CURRENT;   // Period
sinput ENUM_TRADE_COMMAND InpCommandOpenedUp_2       = open_buy;         // Trade command:
sinput string             InpNameAverageUp_2         = "Line_2 Up";      // Line Name UP(Horizontal Line or Trend Line)
sinput ENUM_TRADE_COMMAND InpCommandOpenedUpLow_2    = open_sell;        // Trade command:
sinput bool               InpDelLineUp_2             = false;            // Delete (Horizontal Line or Trend Line)
sinput double             InpObjStepTradeUp_2        = 0;                // Obj: Distance from price to object, in pips
sinput color              InpObjAverageclrUp_2       = clrBlue;          // EA only monitors this lines color
sinput group "----------------- Trade Line DOWN ----------------------"
sinput ENUM_MODE          FilterLine_14              = mode_All;         // FILTER: ВКЛ.ВЫКЛ.
sinput ENUM_TIMEFRAMES    InpPeriod_Down             = PERIOD_CURRENT;   // Period
sinput ENUM_TRADE_COMMAND InpCommandOpenedDown       = open_buy;         // Trade command:
sinput string             InpNameAverageDown         = "Line Down";      // Line Name DOWN(Horizontal Line or Trend Line)
sinput ENUM_TRADE_COMMAND InpCommandOpenedDownLow    = open_sell;        // Trade command:
sinput bool               InpDelLineDown             = false;            // Delete (Horizontal Line or Trend Line)
sinput double             InpObjStepTradeDown        = 0;                // Obj: Distance from price to object, in pips
sinput color              InpObjAverageclrDown       = clrRed;           // EA only monitors this lines color
sinput group "----------------- Trade Line_2 DOWN --------------------"
sinput ENUM_MODE          FilterLine_16              = mode_All;         // FILTER: ВКЛ.ВЫКЛ.
sinput ENUM_TIMEFRAMES    InpPeriod_Down_2           = PERIOD_CURRENT;   // Period
sinput ENUM_TRADE_COMMAND InpCommandOpenedDown_2     = open_buy;         // Trade command:
sinput string             InpNameAverageDown_2       = "Line_2 Down";    // Line Name DOWN(Horizontal Line or Trend Line)
sinput ENUM_TRADE_COMMAND InpCommandOpenedDownLow_2  = open_sell;        // Trade command:
sinput bool               InpDelLineDown_2           = false;            // Delete (Horizontal Line or Trend Line)
sinput double             InpObjStepTradeDown_2      = 0;                // Obj: Distance from price to object, in pips
sinput color              InpObjAverageclrDown_2     = clrRed;           // EA only monitors this lines color
Algorithm manually automate
Algorithm manually automate
  • www.mql5.com
Эксперт для Автоматизации Ручной торговли.
 
de_leonid:

谢谢你的帮助。我还可以要求提供一个EA的例子(部分代码),如何在EA中从这些行中获得数值。

专家顾问中的函数本身来自水平线或趋势线

这里--(用黄色标记--这里设置了线的名称)\\\\\\\\\\\\,用于1分钟测试--手动放一条水平线或趋势线,在专家顾问和线本身中设置相同的名称。

//+------------------------------------------------------------------+
//|                                                TrendOpenedUp.mq5 |
//|                                  Copyright 2021, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021, MetaQuotes Ltd."
#property link      "https://www.mql5.com"
#property version   "1.00"
//---
sinput string InpNameAverageUp = "Line Up"; // Line Name UP(Horizontal Line or Trend Line)
sinput bool   InpDelLineUp     = false;     // Delete (Horizontal Line or Trend Line)
//---
datetime ExtPrevBarsUp;    // "0" -> D'1970.01.01 00:00';
datetime ExtLastAverageUp; // "0" -> D'1970.01.01 00:00';
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   TrendOpenedUp();
  }
//+------------------------------------------------------------------+
//| Check for long position opening                                  |
//+------------------------------------------------------------------+
bool TrendOpenedUp(void)
  {
   bool res=false;
   datetime time_0=iTime(Symbol(),Period(),0);
   if(time_0==ExtPrevBarsUp)
      return(true);
   ExtPrevBarsUp=time_0;
     {
      if(ObjectFind(0,InpNameAverageUp)<0)
         return(true);
      MqlRates ratesAverage[];
      ArraySetAsSeries(ratesAverage,true);
      int start_pos=0,count=3;
      if(CopyRates(Symbol(),Period(),start_pos,count,ratesAverage)!=count)
         return(false);
      if(ratesAverage[0].time==ExtLastAverageUp)
         return(true);
      double price_line=0.0;
      long object_type=ObjectGetInteger(0,InpNameAverageUp,OBJPROP_TYPE);
      if(object_type==OBJ_HLINE)
         price_line=ObjectGetDouble(0,InpNameAverageUp,OBJPROP_PRICE);
      else
         if(object_type==OBJ_TREND)
            price_line=ObjectGetValueByTime(0,InpNameAverageUp,ratesAverage[1].time,0);
      double value_by_time=price_line;
      if(value_by_time==0.0)
         return(true);
      if(ratesAverage[1].open<value_by_time && ratesAverage[1].close>value_by_time)
        {
         PlaySound("request.wav");
         if(InpDelLineUp)
            ObjectsDeleteAll(0,InpNameAverageUp);
         res=true;
        }
      if(ratesAverage[1].open>value_by_time && ratesAverage[1].close<value_by_time)
        {
         PlaySound("tick.wav");
         if(InpDelLineUp)
            ObjectsDeleteAll(0,InpNameAverageUp);
         res=true;
        }
     }
//--- result
   return(res);
  }
//+------------------------------------------------------------------+
 
de_leonid:

谢谢你的帮助。我还可以要求提供一个EA的例子(部分代码),如何在EA中从这些行中获得数值。

最容易和最简单的方法是从指标中获得水平线或趋势线的名称。

- 在图表上点击右键,找到LIST OF OBJECTS(复制并粘贴到Expert Advisor)。

图片来源

 
大家好!
,我乞求大家的帮助,我已经绞尽脑汁了,我找不到如何实现以下内容。
当打开一个新栏时,进行计算。
当再次打开一个新栏时,进行计算并执行任何操作。
我在MQL5中找不到它
,请帮助!!
 
m-r LSV:
大家好! ,我乞求大家的帮助,我已经绞尽脑汁了,我找不到如何实现以下内容。当打开一个新栏时,进行计算。当再次打开一个新栏时,进行计算并执行任何操作。我在MQL5中找不到它 ,请帮助!!




如果是为一个指标,则有 rates_total 和 prev_calculated。如果是针对EA,那么和mql4中一样...
 
Alexey Viktorov:
如果是用于指标,有 rates_total 和 prev_calculated。如果是针对专家顾问,那就和mql4中一样...

请给我一段简短的代码,我是个新手,我的头已经沸腾了。困惑。

 
Alexey Viktorov:
如果是为一个指标,则有 rates_total 和 prev_calculated。如果是针对EA,那么和mql4中一样...

是的,这是为指标服务的

 

Alexey Viktorov:
Если это для индикатора, то есть rates_total и prev_calculated. Если-же для советника, то так-же как и в mql4…


if(rates_total > prev_calculated)
 Print("Новый бар");

我没看错吧?

 

蜡烛的打开时间被推迟了9-12秒。
你能告诉我这是第一次打勾吗?

对我来说,在新蜡烛的第一个刻度上进行计算和执行任何行动是极其重要的。

2021.06.02 16:42:09.522 Test (Volatility 10 Index,M1)      Новый бар
2021.06.02 16:43:09.621 Test (Volatility 10 Index,M1)      Новый бар
2021.06.02 16:44:09.552 Test (Volatility 10 Index,M1)      Новый бар

 
m-r LSV:

我没看错吧?

datetime fin=0, last=0;

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[])
   {
   fin=iTime(symbol,frame,0);
   if(last==fin) return(rates_total);
   last=fin;