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

 
Aleksei Stepanenko:

从一条线上的两个点,你可以找到该线上任意第三个点的价格,也是在未来(反之亦然)。

谢谢你!我将尝试一下。

P.S. 唯一的事情。我一看就不明白。在专家顾问中,在MT4中,它是否能发挥作用?

 
你好,各位专家。我需要你的帮助来纠正这个指标。该指标的实质如下。计算相对于前一栏的价格上涨值。对于零需要一个星条。就是说,开盘价等于收盘价。编译时没有错误,但测试时在第80行20个字符处出现错误。信号线 的画法也不正确。但我认为这就是主缓冲区计算不正确的原因。请帮助我解决这个问题。
//+------------------------------------------------------------------+
//|                                                         MSBB.mq4 |
//|                        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"
#property strict

#include <MovingAverages.mqh>

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  clrGreen
#property indicator_color2  clrRed
#property  indicator_width1  1
input int            InpMSBBPeriod=3;        // Period
input ENUM_MA_METHOD InpMSBBMethod=MODE_SMA;  // Method
//--- indicator buffers
double         ExtMSBBBuffer[];
double         ExtTempBuffer[];
double         ExtPriceBuffer[];
double         ExtSignalBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
//--- indicator buffers mapping
   IndicatorDigits(Digits-2);
//--- drawing settings
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexBuffer(0,ExtMSBBBuffer);
   SetIndexBuffer(1,ExtSignalBuffer);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(2,ExtTempBuffer);
   SetIndexBuffer(2,ExtPriceBuffer);
   SetIndexDrawBegin(1,InpMSBBPeriod);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MSBB("+IntegerToString(InpMSBBPeriod)+")");
   SetIndexLabel(0,"MSBB");
   SetIndexLabel(1,"Signal");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
   int    i;//limit;
//------
   if(rates_total<=InpMSBBPeriod || InpMSBBPeriod<=2)
      return(0);
   /*//--- counting from 0 to rates_total
      ArraySetAsSeries(ExtMSBBBuffer,false);
      ArraySetAsSeries(ExtSignalBuffer,false);
      ArraySetAsSeries(open,false);
      ArraySetAsSeries(high,false);
      ArraySetAsSeries(low,false);
      ArraySetAsSeries(close,false);*/
//---
  // limit=rates_total-prev_calculated;
   //if(prev_calculated>0)
     // limit++;
//--- typical price and its moving average
   for(i=0; i<rates_total; i++)
     {
      ExtTempBuffer[i] = NormalizeDouble((close[i]-open[i])/Point(),2);
      ExtPriceBuffer[i] = NormalizeDouble((close[i+1]-open[i+1])/Point(),2);
      //ExtMSBBBuffer[i]=price_open+ExtTempBuffer[i];
      //Print("ExtPriceBuffer[i] = ", ExtPriceBuffer[i]);
      if(ExtTempBuffer[i]==0)
         ExtMSBBBuffer[i]=0.0;
      if(ExtPriceBuffer[i]>0 && ExtTempBuffer[i]>0)
        {
         double price_open = NormalizeDouble((open[i]-open[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-close[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i] = 0.0;
         if((price_open<0 && price_close<0)||(price_open>0 && price_close>0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]>0 && ExtTempBuffer[i]<0)
        {
         double price_open = NormalizeDouble((open[i]-close[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-open[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i] = 0.0;
         if((price_open>0 && price_close>0)||(price_open<0 && price_close<0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]<0 && ExtTempBuffer[i]<0)
        {
         double price_open = NormalizeDouble((open[i]-open[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-close[i+1])/Point(),2);
         if((price_open<0 && price_close>0)||(price_open>0 && price_close<0))
            ExtMSBBBuffer[i]=0.0;
         if((price_open<0 && price_close<0)||(price_open>0 && price_close>0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      if(ExtPriceBuffer[i]<0 && ExtTempBuffer[i]>0)
        {
         double price_open = NormalizeDouble((open[i]-close[i+1])/Point(),2);
         double price_close = NormalizeDouble((close[i]-open[i+1])/Point(),2);
         if((price_open>0 && price_close<0)||(price_open<0 && price_close>0))
            ExtMSBBBuffer[i]=0.0;
         if((price_open>0 && price_close>0)||(price_open<0 && price_close<0))
            ExtMSBBBuffer[i]=ExtTempBuffer[i]+price_open;
        }
      //--- signal line counted in the 2-nd buffer
      //ExtSignalBuffer[i]=iMAOnArray(ExtMSBBBuffer,0,InpMSBBPeriod,0,InpMSBBMethod,0);
      SimpleMAOnBuffer(rates_total,prev_calculated,1,InpMSBBPeriod+2,ExtMSBBBuffer,ExtSignalBuffer);
      Print ("ExtSignalBuffer = ", ExtSignalBuffer[i]);
      //--- done
     }
   /* if(ExtPriceBuffer[i]>0||ExtPriceBuffer[i]<0)
     {
      ExtMSBBBuffer[i] = ExtPriceBuffer[i]+ExtTempBuffer[i];
      Print("ExtMSBBBuffer[i] = ", ExtMSBBBuffer[i]);
     }
   if(ExtPriceBuffer[i]==0)
     {
      ExtMSBBBuffer[i] = 0.0;
      Print("ExtMSBBBuffer[i] = ", ExtMSBBBuffer[i]);
     }
   }*/
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
 
我怎样才能查到进行单项测试的当地代理机构的号码?
 

下午好!

能否请您帮忙提供一个EA?

它在30和70水平的RSI信号上进行适当方向的交易,创建一个网格。

我在其中设置了一种止损%,但不时有订单被挂起,直到我手动关闭或卖出存款才会关闭。

也就是说,这种订单是在价格已经移动了5000点以上,但仍然挂在红线上的时候开的。

你需要找到这个错误。如果这是不可能的,我们应该在我们的EA中插入一个单独的止损点。

我试着将2个EA合并成一个,但以我的技能,这并不奏效。

附加的文件:
 

你好。你能给我一个提示吗?我需要得到在最后一个勾中通过的点数。但我无法得到它。

#property indicator_chart_window
#property indicator_buffers 1
double ExtMapBuffer[];
double dOldPriceEURUSD, dNewPriceEURUSD;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(5);
   SetIndexBuffer(0, ExtMapBuffer);
   SetIndexEmptyValue(0,0.0);        
   dOldPriceEURUSD=iClose("EURUSD",0,0);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
   dNewPriceEURUSD=iClose("EURUSD",0,0);
   double delta=NormalizeDouble(dOldPriceEURUSD-dNewPriceEURUSD,5);
   ExtMapBuffer[0] = delta;
   Alert(delta);     
   dOldPriceEURUSD=dNewPriceEURUSD;
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
Forallf:

你好。你能给我一个提示吗?我需要得到在最后一个勾中通过的点数。但这并不奏效。

试试这个。

//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 1
double ExtMapBuffer[];
double dOldPriceEURUSD, dNewPriceEURUSD;
double delta;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
   IndicatorDigits(5);
   SetIndexBuffer(0, ExtMapBuffer);
   SetIndexEmptyValue(0, 0.0);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
   dNewPriceEURUSD = NormalizeDouble(Close[0],Digits);
   delta = dOldPriceEURUSD - dNewPriceEURUSD;
   Comment(" delta = ", DoubleToStr(delta ,5));
   dOldPriceEURUSD = dNewPriceEURUSD;
   ExtMapBuffer[0] = delta;
 Alert(" delta = ", DoubleToStr(delta ,5));
   return(rates_total);
  }
//+------------------------------------------------------------------+
Domain Registration Services
  • www.registryrocket.com
Get a unique domain name plus our FREE value-added services to help you get the most from it. Call it a "dot-com name," a URL, or a domain. Whatever you call it, it's the cornerstone of your online presence, and we make getting one easy. Simply enter the name you want in the search field above, and we'll tell you instantly whether the name is...
 
Александр:

这样试试吧。

谢谢你!
 

又见面了。
请注意一个新手的问题。
我需要指出代码中的错误,因为在测试器中,专家顾问并没有打开订单...
编译器没有显示任何错误或警告,同样的日志也没有显示任何错误......。

extern double Lot=0.1;            
extern int Slippage = 3;
extern int TakeProfit = 30;
extern int StopLoss   = 30;
extern int MA_Smoth_S = 60;
extern int MA_Smoth_B = 12;
extern int MA_Simpl_S = 3;
extern int MA_Simpl_B = 1;
int start()
         {
          //___________________

          double SL, TP;
          int MA_Simpl_S_Cl,      //
              MA_Simpl_S_Op,      //
              MA_Simpl_B_Cl,      //
              MA_Simpl_B_Op;      //
         
          //________________

          //------------

          SL=NormalizeDouble(Bid-StopLoss*Point,Digits);      // 
          TP=NormalizeDouble(Bid+TakeProfit*Point,Digits);    //
          SL = StopLoss;                        
          TP = TakeProfit;
          if(_Digits==5 || _Digits==3)
            {
             SL = SL*10;
             TP = TP*10;
             return(0);
            }
            
          //_______________

          MA_Smoth_S = iMA(NULL,0,60,0,MODE_SMMA,PRICE_CLOSE,1);
          MA_Smoth_B = iMA(NULL,0,12,0,MODE_SMMA,PRICE_CLOSE,1);
          MA_Simpl_S = iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_B = iMA(NULL,0,1,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_S_Cl = iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_S_Op = iMA(NULL,0,3,0,MODE_SMA,PRICE_CLOSE,2);
          MA_Simpl_B_Cl = iMA(NULL,0,1,0,MODE_SMA,PRICE_CLOSE,1);
          MA_Simpl_B_Op = iMA(NULL,0,1,0,MODE_SMA,PRICE_CLOSE,2);
          
          //______________________

          while(MA_Smoth_B > MA_Smoth_S)
               {
                if(MA_Simpl_B_Op < MA_Simpl_S_Op && MA_Simpl_B_Cl > MA_Simpl_S_Cl)
                  {
                   bool check = OrderSend(Symbol(),OP_BUY,Lot,NormalizeDouble(Ask, Digits),Slippage,SL,TP,"Buy",0,0,clrGreen);
                   return(0);
                  }
               }
               
          //_____________________

          while(MA_Smoth_S > MA_Smoth_B)
               {
                if(MA_Simpl_B_Op > MA_Simpl_S_Op && MA_Simpl_B_Cl < MA_Simpl_S_Cl)
                  {
                   check = OrderSend(Symbol(),OP_SELL,Lot,NormalizeDouble(Ask, Digits),Slippage,SL,TP,"Sell",0,0,clrRed);
                   return(0);
                  }   
               }     
          return(0);
         } 
 

大家好!

我正在尝试将mql4转为mql5。

问题:为什么mql5计算并显示一些未知的表达式,如2.99999999-(减去)05,而不是当前价格和Hay 变量值之间的差异,这应该是<1(像在mql4)

我应该如何让mql5正确计算这些数值之间的差异?我使用 NormalizeDouble()对所有数值进行了归一化 处理,但上述数值

值显示不变。这对我来说很奇怪,因为这两个值都是二进制类型的。

感谢大家的帮助。

#include <Trade\Trade.mqh>                                        
int tm, s1 ;                                    
double P=SymbolInfoDouble(Symbol(),SYMBOL_BID),S=P+0.0030,T=P-0.0010,Lou,Hay,DL=0.0030; 
CTrade            m_Trade;                 //структура для выполнения торговых операций
//=============================================================================================================
void OnTick()
  {
Print("===============",SymbolInfoDouble(Symbol(),SYMBOL_BID) - Hay,"===Hay====",Hay,"===SymbolInfoDouble()====",SymbolInfoDouble(Symbol(),SYMBOL_BID)); 

m_Trade.Sell(0.1,Symbol(),P,S,T);
Hay=SymbolInfoDouble(Symbol(),SYMBOL_BID);

   }


 
MrBrooklin:

你好,伊万,这里没有人责骂新手,相反,他们会尽力帮助。我自己也是一个初学者。现在,关于你的问题。有几个仓位被打开了,因为进行了开仓的检查,但检查时忘记了 停止。操作员返回 将控制权返回给调用程序(取自MQL5参考)。

我们必须在专家顾问的代码中添加返回的 内容(用黄色标出)。

此外,为防止编译器产生警告,应在买入和卖出开仓条件中再增加一个条件,以检查OrderSend(mrequest,mresult)。这个条件是由if 操作符定义的,应该是这样的

还应考虑到一件事。有时,在23:59:59从一个交易日转到另一个交易日时,一个已开的头寸关闭,然后在00:00:00,一个新的头寸打开。这就是所谓的展期收盘和展期开盘,这取决于特定的外汇商和其交易条件。在论坛上搜索一下,我在某个地方有一些相关信息。

真诚的,弗拉基米尔。


你好。

非常感谢您的答复!但我不明白为什么我需要返回 运算符?这段代码中有两个条件,当其中一个条件得到满足时,检查应该停止。

//--- есть ли открытые позиции?
   bool Buy_opened=false;  // переменные, в которых будет храниться информация 
   bool Sell_opened=false; // о наличии соответствующих открытых позиций

   if(PositionSelect(_Symbol)==true) // есть открытая позиция
     {
      if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_BUY)  // если истина, выполняем условие 1
        {
         Buy_opened=true;  //это длинная позиция
        }
      else if(PositionGetInteger(POSITION_TYPE)==POSITION_TYPE_SELL)  // иначе выполняем условие 2
        {
         Sell_opened=true; // это короткая позиция
        }
     }
或者说不是吗?
原因: