Bitcoin Forum
May 05, 2024, 03:39:40 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Как считать RSI?  (Read 1021 times)
m0Ray (OP)
Sr. Member
****
Offline Offline

Activity: 868
Merit: 251


View Profile
March 20, 2014, 10:48:59 AM
 #1

Набрасываю тут самопальный инструмент для теханализа, потихоньку отписываю разные индикаторы. Так вот, затык вышел с сабжем, мои расчёты никак не похожи на те, что даёт bitcoincharts или MT4. Делал по педивикии, да и в других источника то же самое. А график - ну никак не похож.
Пробовал считать и по разностям закрытия, и по открытию-закрытию... Более-менее похоже получается только когда считаю по средневзвешенной цене (сумма произведений цена*объём, делённая на суммарный объём), но всё равно не то.
Может, кто-нибудь знает какой-то секрет в расчёте этого индикатора?
"Governments are good at cutting off the heads of a centrally controlled networks like Napster, but pure P2P networks like Gnutella and Tor seem to be holding their own." -- Satoshi
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1714880380
Hero Member
*
Offline Offline

Posts: 1714880380

View Profile Personal Message (Offline)

Ignore
1714880380
Reply with quote  #2

1714880380
Report to moderator
1714880380
Hero Member
*
Offline Offline

Posts: 1714880380

View Profile Personal Message (Offline)

Ignore
1714880380
Reply with quote  #2

1714880380
Report to moderator
izlevinv
Sr. Member
****
Offline Offline

Activity: 277
Merit: 250



View Profile
March 20, 2014, 02:21:31 PM
 #2

Может исходный код в МТ посмотреть, чтобы соориентироваться почему разница?
m0Ray (OP)
Sr. Member
****
Offline Offline

Activity: 868
Merit: 251


View Profile
March 20, 2014, 06:31:38 PM
 #3

Может исходный код в МТ посмотреть, чтобы соориентироваться почему разница?
Простите, а у вас есть исходный код MT4? Если б он у меня был, я б такими вопросами публично не позорился.
izlevinv
Sr. Member
****
Offline Offline

Activity: 277
Merit: 250



View Profile
March 20, 2014, 07:06:44 PM
 #4

Я написал "посмотреть в МТ".
Исправляю, смотреть можно в MetaEditor или любом текстовом редакторе.
В МТ есть индикаторы, идете в папку, где лежат индикаторы, находите в "Пользовательских индикаторах" RSI, жмете энтер, профит!

Ну или что-нибудь в таком духе http://codebase.mql4.com/ru/3423
m0Ray (OP)
Sr. Member
****
Offline Offline

Activity: 868
Merit: 251


View Profile
March 21, 2014, 03:49:19 AM
 #5

Очень, знаете ли, информативно:
Code:
rsiValue        =iRSI(NULL,TimeFrame,RSIPeriod,RSIPriceType,y);
izlevinv
Sr. Member
****
Offline Offline

Activity: 277
Merit: 250



View Profile
March 21, 2014, 04:42:03 AM
 #6

Вот этот стандартный тоже не нравится?
Code:
//+------------------------------------------------------------------+
//|                                                          RSI.mq4 |
//|                   Copyright 2005-2014, MetaQuotes Software Corp. |
//|                                              http://www.mql4.com |
//+------------------------------------------------------------------+
#property copyright   "2005-2014, MetaQuotes Software Corp."
#property link        "http://www.mql4.com"
#property description "Relative Strength Index"
#property strict

#property indicator_separate_window
#property indicator_minimum    0
#property indicator_maximum    100
#property indicator_buffers    1
#property indicator_color1     DodgerBlue
#property indicator_level1     30.0
#property indicator_level2     70.0
#property indicator_levelcolor clrSilver
#property indicator_levelstyle STYLE_DOT
//--- input parameters
input int InpRSIPeriod=14; // RSI Period
//--- buffers
double ExtRSIBuffer[];
double ExtPosBuffer[];
double ExtNegBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   string short_name;
//--- 2 additional buffers are used for counting.
   IndicatorBuffers(3);
   SetIndexBuffer(0,ExtRSIBuffer);
   SetIndexBuffer(1,ExtPosBuffer);
   SetIndexBuffer(2,ExtNegBuffer);
//--- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtRSIBuffer);
//--- name for DataWindow and indicator subwindow label
   short_name="RSI("+string(InpRSIPeriod)+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//--- check for input
   if(InpRSIPeriod<2)
     {
      Print("Incorrect value for input variable InpRSIPeriod = ",InpRSIPeriod);
      return(INIT_FAILED);
     }
//---
   SetIndexDrawBegin(0,InpRSIPeriod);
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
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,pos;
   double diff;
//---
   if(Bars<=InpRSIPeriod || InpRSIPeriod<2)
      return(0);
//--- counting from 0 to rates_total
   ArraySetAsSeries(ExtRSIBuffer,false);
   ArraySetAsSeries(ExtPosBuffer,false);
   ArraySetAsSeries(ExtNegBuffer,false);
   ArraySetAsSeries(close,false);
//--- preliminary calculations
   pos=prev_calculated-1;
   if(pos<=InpRSIPeriod)
     {
      //--- first RSIPeriod values of the indicator are not calculated
      ExtRSIBuffer[0]=0.0;
      ExtPosBuffer[0]=0.0;
      ExtNegBuffer[0]=0.0;
      double sump=0.0;
      double sumn=0.0;
      for(i=1; i<=InpRSIPeriod; i++)
        {
         ExtRSIBuffer[i]=0.0;
         ExtPosBuffer[i]=0.0;
         ExtNegBuffer[i]=0.0;
         diff=close[i]-close[i-1];
         if(diff>0)
            sump+=diff;
         else
            sumn-=diff;
        }
      //--- calculate first visible value
      ExtPosBuffer[InpRSIPeriod]=sump/InpRSIPeriod;
      ExtNegBuffer[InpRSIPeriod]=sumn/InpRSIPeriod;
      if(ExtNegBuffer[InpRSIPeriod]!=0.0)
         ExtRSIBuffer[InpRSIPeriod]=100.0-(100.0/(1.0+ExtPosBuffer[InpRSIPeriod]/ExtNegBuffer[InpRSIPeriod]));
      else
        {
         if(ExtPosBuffer[InpRSIPeriod]!=0.0)
            ExtRSIBuffer[InpRSIPeriod]=100.0;
         else
            ExtRSIBuffer[InpRSIPeriod]=50.0;
        }
      //--- prepare the position value for main calculation
      pos=InpRSIPeriod+1;
     }
//--- the main loop of calculations
   for(i=pos; i<rates_total && !IsStopped(); i++)
     {
      diff=close[i]-close[i-1];
      ExtPosBuffer[i]=(ExtPosBuffer[i-1]*(InpRSIPeriod-1)+(diff>0.0?diff:0.0))/InpRSIPeriod;
      ExtNegBuffer[i]=(ExtNegBuffer[i-1]*(InpRSIPeriod-1)+(diff<0.0?-diff:0.0))/InpRSIPeriod;
      if(ExtNegBuffer[i]!=0.0)
         ExtRSIBuffer[i]=100.0-100.0/(1+ExtPosBuffer[i]/ExtNegBuffer[i]);
      else
        {
         if(ExtPosBuffer[i]!=0.0)
            ExtRSIBuffer[i]=100.0;
         else
            ExtRSIBuffer[i]=50.0;
        }
     }
//---
   return(rates_total);
  }
m0Ray (OP)
Sr. Member
****
Offline Offline

Activity: 868
Merit: 251


View Profile
March 21, 2014, 04:55:41 AM
 #7

А вот это выглядит как то, что нужно, благодарствую.
Сам-то я в MT4 хреново разбираюсь, уж извините.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!