初心者の方からの質問 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 #:

あなたの方向性は正しい。しかし、気配りが足りない

こんにちは、Alexei。プログラミング言語を学ぶ初心者をサポートし、私たちのような人を飽きさせないのは素晴らしいことです。ありがとうございます

初心者の主な問題は何ですか?私自身のことだけを話します。確かに、MQL5というプログラミング言語が提供するさまざまな可能性をどのように適用すればいいのか、いつも理解できているわけではありません。基本的な教育やトップレベルの言語でのプログラミングの実践がなければ、このトピックに入るのは非常に困難です。皆さんのようなフォーラムのメンバーだけが私を助けてくれます。突然フォーラムに現れた新参者に、常に催促し続けることに多くの人が疲れている(そして時には十分な時間や忍耐力がない)ことを実感しています。

このような私たちの些細な質問に答えてくださるすべての方々に、改めて感謝の意を表するとともに、皆様のご健康とご長寿、ご多幸とご繁栄をお祈りいたします!

ウラジーミル

 


最後のバーの終値で、赤色で売りのシグナル、緑色で買いのシグナル を出すAccelerator Oscillator インジケータの追加方法を教えてください。

ありがとうございます。

 
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 #:

もし

期間延長=14

であれば、ExtADXPeriod<< 1は値9に等しい

は28に等しい(14<<1は14*2のようなもので、十分な桁数がある限り)

コンパイラはコンパイル時にconst式を計算し、コードには取り込まない。その結果のみ

最適化が早まったか、作者がクールであることを示したかっただけかもしれない。

 
Maxim Kuznetsov #:

は28に等しい(14<<1は14*2のようなもので、十分な桁数がある限り)。

コンパイラはコンパイル時に既知のconst式をカウントし、コードには取り込まない。結果のみ

最適化が時期尚早だったのか、あるいは作者が自分がクールであることを示したかったのかもしれない。

1-なぜ28なのか?

14は2進数だ。1110だ。

左に1ビットシフトすると0111となり、10進数に戻すと9となる。1*1+1+1*2+1*4=7(9でないのは間違い)。


2-この場合、ExtADXPeriod<<1の 代わりに何を挿入するのが正しいのか、具体的な例が欲しい。

理由: