初学者的问题 MQL5 MT5 MetaTrader 5 - 页 1483

 
klycko DEAL_ENTRY_OUT 修改器。
但我不知道如何使用。

请帮助我。

亚历山大


你的方向是正确的。但不够细心


 
klycko DEAL_ENTRY_OUT 修改器。
但我不知道如何使用。
void  OnTradeTransaction(
   const MqlTradeTransaction&    trans,   // структура торговой транзакции
   const MqlTradeRequest&        request, // структура запроса
   const MqlTradeResult&         result   // структура ответа
)
  {
   if(trans.type==TRADE_TRANSACTION_DEAL_ADD)
     {
      if(HistoryDealSelect(trans.deal) && HistoryDealGetInteger(trans.deal,DEAL_ENTRY)==DEAL_ENTRY_OUT)
        {

           //---

        }

敬上,弗拉基米尔。

 
Alexey Viktorov #:

你的方向是对的。但不够专注

你好,阿列克谢,你能支持初学者学习编程语言,而且对我们这样的人不厌其烦,这真是太好了。非常感谢

初学者的主要问题是什么?我只说说我自己。是的,的确,我并不总能理解如何应用 MQL5 编程语言提供的各种可能性。如果没有顶级语言编程的基础教育或实践,就很难进入这个主题。只有像你们这样的论坛成员才能帮助我。我知道很多人已经厌倦(有时没有足够的时间或耐心)不断提示一个突然出现在论坛上的新人。

在此,我再次向所有回答我们的问题的人表示感谢,并祝愿上帝赐予你们健康、长寿、好运和繁荣!!!!!

弗拉基米尔

 

大家好。
,请告诉我如何添加加速振荡器 指标,以便在最后一栏收盘时发出红色的卖出信号和绿色的买入信号

谢谢

 
makssub 加速震荡 指标,在最后一栏收盘时发出红色的卖出信号和绿色的买入信号

谢谢

指标 连接到 Expert Advisor,通过CopyBuffer() 获取数据。颜色缓冲区的索引为 1,其中 0 表示绿色,1 表示红色。
Документация по MQL5: Технические индикаторы / iAC
Документация по MQL5: Технические индикаторы / iAC
  • www.mql5.com
iAC - Технические индикаторы - Справочник MQL5 - Справочник по языку алгоритмического/автоматического трейдинга для MetaTrader 5
 
Artyom Trishkin #:
指标 连接到 Expert Advisor,并通过CopyBuffer() 获取数据。颜色缓冲区的索引为 1,其中值 0 代表绿色,1 代表红色。

如果您不介意的话。能给我举个例子吗?

继 MQL4 之后,MQL5 对我来说很难。

 
makssub #:

如果不麻烦的话。能举个例子吗?

在 MQL4 之后,MQL5 对我来说很难。

例子在我上面帖子的链接中
 

您好。

代码库中有一个 ADX 指标。它包含这样一段代码

//--- set draw begin
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtADXPeriod<<1);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtADXPeriod);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtADXPeriod);

如果

ExtADXPeriod=14

则 ExtADXPeriod<<1 等于 9。

那我们为什么需要这样一个条目呢?难道不需要位移就能写出来吗?

ExtADXPeriod<<1

完整指标代码如下


//+------------------------------------------------------------------+
//|                                                          ADX.mq5 |
//|                             Copyright 2000-2023, MetaQuotes Ltd. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright   "Copyright 2000-2023, MetaQuotes Ltd."
#property link        "https://www.mql5.com"
#property description "Average Directional Movement Index"
#include <MovingAverages.mqh>

#property indicator_separate_window
#property indicator_buffers 6
#property indicator_plots   3
#property indicator_type1   DRAW_LINE
#property indicator_color1  LightSeaGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
#property indicator_type2   DRAW_LINE
#property indicator_color2  YellowGreen
#property indicator_style2  STYLE_DOT
#property indicator_width2  1
#property indicator_type3   DRAW_LINE
#property indicator_color3  Wheat
#property indicator_style3  STYLE_DOT
#property indicator_width3  1
#property indicator_label1  "ADX"
#property indicator_label2  "+DI"
#property indicator_label3  "-DI"
//--- input parameters
input int InpPeriodADX=14; // Period ADX
//--- indicator buffers
double    ExtADXBuffer[];
double    ExtPDIBuffer[];
double    ExtNDIBuffer[];
double    ExtPDBuffer[];
double    ExtNDBuffer[];
double    ExtTmpBuffer[];

int       ExtADXPeriod;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- check for input parameters
   if(InpPeriodADX>=100 || InpPeriodADX<=0)
     {
      ExtADXPeriod=14;
      PrintFormat("Incorrect value for input variable Period_ADX=%d. Indicator will use value=%d for calculations.",InpPeriodADX,ExtADXPeriod);
     }
   else
      ExtADXPeriod=InpPeriodADX;
//--- indicator buffers
   SetIndexBuffer(0,ExtADXBuffer);
   SetIndexBuffer(1,ExtPDIBuffer);
   SetIndexBuffer(2,ExtNDIBuffer);
   SetIndexBuffer(3,ExtPDBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(4,ExtNDBuffer,INDICATOR_CALCULATIONS);
   SetIndexBuffer(5,ExtTmpBuffer,INDICATOR_CALCULATIONS);
//--- indicator digits
   IndicatorSetInteger(INDICATOR_DIGITS,2);
//--- set draw begin
   PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ExtADXPeriod<<1);
   PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ExtADXPeriod);
   PlotIndexSetInteger(2,PLOT_DRAW_BEGIN,ExtADXPeriod);
//--- indicator short name
   string short_name="ADX("+string(ExtADXPeriod)+")";
   IndicatorSetString(INDICATOR_SHORTNAME,short_name);
   PlotIndexSetString(0,PLOT_LABEL,short_name);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//--- checking for bars count
   if(rates_total<ExtADXPeriod)
      return(0);
//--- detect start position
   int start;
   if(prev_calculated>1)
      start=prev_calculated-1;
   else
     {
      start=1;
      ExtPDIBuffer[0]=0.0;
      ExtNDIBuffer[0]=0.0;
      ExtADXBuffer[0]=0.0;
     }
//--- main cycle
   for(int i=start; i<rates_total && !IsStopped(); i++)
     {
      //--- get some data
      double high_price=high[i];
      double prev_high =high[i-1];
      double low_price =low[i];
      double prev_low  =low[i-1];
      double prev_close=close[i-1];
      //--- fill main positive and main negative buffers
      double tmp_pos=high_price-prev_high;
      double tmp_neg=prev_low-low_price;
      if(tmp_pos<0.0)
         tmp_pos=0.0;
      if(tmp_neg<0.0)
         tmp_neg=0.0;
      if(tmp_pos>tmp_neg)
         tmp_neg=0.0;
      else
        {
         if(tmp_pos<tmp_neg)
            tmp_pos=0.0;
         else
           {
            tmp_pos=0.0;
            tmp_neg=0.0;
           }
        }
      //--- define TR
      double tr=MathMax(MathMax(MathAbs(high_price-low_price),MathAbs(high_price-prev_close)),MathAbs(low_price-prev_close));
      if(tr!=0.0)
        {
         ExtPDBuffer[i]=100.0*tmp_pos/tr;
         ExtNDBuffer[i]=100.0*tmp_neg/tr;
        }
      else
        {
         ExtPDBuffer[i]=0.0;
         ExtNDBuffer[i]=0.0;
        }
      //--- fill smoothed positive and negative buffers
      ExtPDIBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtPDIBuffer[i-1],ExtPDBuffer);
      ExtNDIBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtNDIBuffer[i-1],ExtNDBuffer);
      //--- fill ADXTmp buffer
      double tmp=ExtPDIBuffer[i]+ExtNDIBuffer[i];
      if(tmp!=0.0)
         tmp=100.0*MathAbs((ExtPDIBuffer[i]-ExtNDIBuffer[i])/tmp);
      else
         tmp=0.0;
      ExtTmpBuffer[i]=tmp;
      //--- fill smoothed ADX buffer
      ExtADXBuffer[i]=ExponentialMA(i,ExtADXPeriod,ExtADXBuffer[i-1],ExtTmpBuffer);
     }
//--- OnCalculate done. Return new prev_calculated.
   return(rates_total);
  }
//+------------------------------------------------------------------+
Discover new MetaTrader 5 opportunities with MQL5 community and services
Discover new MetaTrader 5 opportunities with MQL5 community and services
  • 2023.11.30
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Novichokkk #:

如果

ExtADXPeriod=14

ExtADXPeriod<<1 等于值 9

等于 28(14<<1 相当于 14*2,只要有足够的位数)。

不用注意,反正编译器会在编译时计算常量表达式,它们不会进入代码。只有其结果

这可能是过早的优化,也可能是作者想显示自己很酷。

 
Maxim Kuznetsov #:

等于 28(14<<1 相当于 14*2,只要有足够的位数)。

不用注意,反正编译器会在编译时计算已知的常量表达式,它们不会进入代码。只有它们的结果

这可能是过早的优化,也可能是作者想显示自己很酷。

1-为什么是 28?

14 是二进制。是 1110。

向左移动一位,是 0111,转换回十进制,是 9。1*1+1+1*2+1*4=7(错,不是 9)。


2-我还是希望在这种情况下有一个具体的例子,在这样的结构中插入什么比ExtADXPeriod<<1 更正确?