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

 
MakarFX:

你比较的是错误的rsi而不是 "per"。

就这样了?

 int Signal(int i)
{
  // Снимем показания индикатора
   double Current   = iRSI(NULL, 0, per, PRICE_CLOSE, i);
   double Previous    = iRSI(NULL, 0, per, PRICE_CLOSE, i+1);
   
    double SCurrent   = iRSI(NULL, 0, per, PRICE_CLOSE, i);
     // Для предыдущего бара
   double SPrevious    = iRSI(NULL, 0, per, PRICE_CLOSE, i+1);
      // А теперь проверим всловия для наличия сигналов
   
   // есть сигнал на покупку?
   if(Current <= niz && Close[1]>Open[1])
   
   return(BUY);
   
   if(Current >= verx && Close[1]<Open[1])
    return(SELL);
   
   // Сигнала нет   
   return(-1);
 
jarikn:

就这样了?

是的,但你不能把一个指标改写成另一个。

建立指标的逻辑,然后编写。


在这种情况下,不是所有的逻辑都很清楚,或者有额外的数据没有被使用。
 
MakarFX:

是的,但你不能把一个指标改写成另一个。

建立指标的逻辑,然后编写。


在这种情况下,不是所有的逻辑都很清楚,或者有多余的数据没有被使用。

请看屏幕上的截图,我得到了什么。

我的想法是这样的。

如果RSI高于70水平,并且蜡烛收盘时低于开盘价--应该有一个卖出信号。

我有个想法,如果rsi低于30,并且蜡烛收盘时高于开盘价--这是一个买入信号。


不要评判,我只是想学习一下))))。

现在告诉我我做错了什么。

附加的文件:
 
jarikn:

看看我的截图吧。

我的想法是这样的。

如果RSI高于70,并且蜡烛收盘时低于开盘价--应该有一个卖出信号。

如果rsi低于30,并且蜡烛收于开盘价之上--是买入信号。


不要评判,我只是想学习一下))))。

我唯一想学的是这个。

1)使用按钮粘贴屏幕截图图片

2)根据你的情况--这是正确的。

//+------------------------------------------------------------------+
//|                                                   jarikn_RSI.mq4 |
//|                                           Copyright 2020, DrMak. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2020, DrMak."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_plots   2
//--- plot Покупаем
#property indicator_label1  "Продаём"
#property indicator_type1   DRAW_LINE
#property indicator_color1  clrGreen
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- plot Продаём
#property indicator_label2  "Покупаем"
#property indicator_type2   DRAW_LINE
#property indicator_color2  clrRed
#property indicator_style2  STYLE_SOLID
#property indicator_width2  1
//--- input parameters
input int   RSI_Period  =14;  //Период рассчета RSI
input int   AlertLevUp  =70;  //Уровень для покупок 
input int   AlertLevDn  =30;  //Уровень для продаж
//--- indicator buffers
double      Buy[];            // Буфер для покупок
double      Sell[];           // Буфер для продаж
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,Buy);
   SetIndexBuffer(1,Sell);  
   // Устанавливаем нулевые значения для индикатора, при которых не будет сигнальных стрелок
   SetIndexEmptyValue (0, 0);
   SetIndexEmptyValue (1, 0);
   //Определяем стиль отображения индикаторных линий - стрелка
   SetIndexStyle (0, DRAW_ARROW);
   SetIndexStyle (1, DRAW_ARROW); 
   // Установим значки "стрелки" для буферов
   SetIndexArrow(0, 234);  //Стрелка "вниз" для продаж
   SetIndexArrow(1, 233);  //Стрелка "вверх" для покупок
   //Устанавливаем текст описания стрелок индикатора для отображения информации в всплывающей подсказке.
   SetIndexLabel(0, "Продаём");
   SetIndexLabel(1, "Покупаем");
   //Определяем разрядность значений индикаторных линий - приравниваем разрядности фин. инструмента
   IndicatorDigits (Digits);
   //Строка с кратким названием индикатора выводится в сплывающей подсказке при наведении указателя мыши на стрелку
   IndicatorShortName ("Мой первый индикатор");
   
//---
   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 limit=rates_total-prev_calculated-1;
   if(limit<1) return(0);
   for(int i=limit;i>=0;i--)
     {
      // Снимем показания индикатора
      double RSI = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i);
      if(RSI>AlertLevUp&&open[i]>close[i])
         Buy[i]=high[i];
      if(RSI<AlertLevDn&&open[i]<close[i])
         Sell[i]=low[i];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
MakarFX:

1)使用按钮插入屏幕截图

2)根据你的情况--这是对的。

谢谢,我会研究的。

 
MakarFX:

1)使用按钮插入屏幕截图

2) 根据你的情况--这样就可以了

如何写条件*如果rsi从下往上越过AlertLevDn则买入? 是否可以或者我需要一个额外的滑块?

{
//---
   int limit=rates_total-prev_calculated-1;
   if(limit<1) return(0);
   for(int i=limit;i>=0;i--)
     {
      // Снимем показания индикатора
      double RSI = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i);
      if(RSI>AlertLevUp)
         Buy[i]=high[i];
      if(RSI<AlertLevDn)
         Sell[i]=low[i];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
jarikn:

如何写这个条件 *如果rsi从下到上越过AlertLevDn 则买入?

你的问题给了你答案...

如果rsi 从下往上交叉- 这意味着当前值较高,前一个值较低。

当前值

double RSI = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i);

应做的前值

double RSI2 = iRSI(NULL,0,RSI_Period,PRICE_CLOSE,i+1);

之后再比较

如果RSI2小于AlertLevDn和RSI大于AlertLevDn

你有一个买)。

 
MakarFX:

你的问题给了你答案...

如果rsi从下往上交叉,意味着当前值较高,前值较低。

当前值

必须完成前一个值

之后再比较

如果RSI2小于AlertLevDn和RSI大于AlertLevDn

你有一个买)。

明白了,谢谢)

 
jarikn:

明白了,谢谢你)。

正确的

int limit=rates_total-prev_calculated-2;
 

问候,你能给我一个提示吗? MT5。

我需要得到布林线 的数值。

我写道

#property strict

#include <Indicators\Trend.mqh>
CiBands       m_bands;

input int Magic = 778871;

int OnInit(){//////////////***OnInit()****///*************OnInit()*******/////////***/////////////////////////OnInit()


Print(m_bands.Create(Symbol(), PERIOD_CURRENT, 20, 0, 2, PRICE_CLOSE));
Print((string)m_bands.MaPeriod());
Print((string)m_bands.Base(Bars(NULL, PERIOD_CURRENT)));

return(INIT_SUCCEEDED);
} 

输出类似于double_max的东西。

同时,它还能获得周期、偏移和其他一切的正确性。