Discussion of article "MQL5: Create Your Own Indicator" - page 2

 
Tobias Johannes Zimmer #:
Does this exist in German? 
Searching for "Wie man einen eigenen Indikator erstellt" yielded a lot of results, however not from 2010.

From the article itself you can switch between the different available languages.

https://www.mql5.com/de/articles/10

MQL5: Erstellen Ihres eigenen Indikators
MQL5: Erstellen Ihres eigenen Indikators
  • www.mql5.com
Was ist ein Indikator? Es ist ein Satz berechneter Werte, die auf praktische Weise auf dem Bildschirm angezeigt werden sollen. Sätze von Werten werden in Programmen als Arrays dargestellt. Somit bedeutet das Erstellen eines Indikators, einen Algorithmus zu schreiben, der bestimmte Arrays bearbeitet (Preis-Arrays) und die Ergebnisse der Bearbeitung für andere Arrays (Indikator-Arrays) aufzeichnet. Durch die Beschreibung der Erstellung des True Strength Index zeigt der Autor, wie Indikatoren in MQL5 geschrieben werden.
 
okwh #:

   for(int i=1;i<rates_total;i++)
     {
      MTMBuffer[i]=price[i]-price[i-1];
      AbsMTMBuffer[i]=fabs(MTMBuffer[i]);
     }

 

Why use [i-1] to calculate [i] and start i=1 ?  no [0] ?

  MTMBuffer[i]=price[i]-price[i-1];


Hello.

Broadly speaking, if you use one of the native mql5 indicator functions that starts with "i", you don't need to pay attention to the route. The copybuffer will do it for you.

On the other hand if you go through a specific dev, you have to pay attention to the number of bars, especially for the first pass because otherwise you risk an out of range


look at the code of this rsi that uses Irsi, no position for the course and everything goes well.

On the other hand, this Rsi does not go through the function.

Everything is calculated by hand, so to speak, and you have to do the positioning well so that everything goes smoothly.

Rsi code for beginners by William210
Rsi code for beginners by William210
  • www.mql5.com
Rsi beginner tutorial to learn how to code in MQL5
 
//+------------------------------------------------------------------+
//|                                          True Strength Index.mq5 |
//|                        Copyright 2009, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "2009, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_plots   1
//---- plot TSI
#property indicator_label1  "TSI"
#property indicator_type1   DRAW_LINE
#property indicator_color1  Blue
#property indicator_style1  STYLE_SOLID
#property indicator_width1  1
//--- input parameters
input int      r=25;
input int      s=13;
//--- indicator buffers
double         TSIBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

   SetIndexBuffer(0,TSIBuffer,INDICATOR_DATA);
//---
   return(0);
  }
//+------------------------------------------------------------------+
//| 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[])
  {
//---
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

why in oninit
it needs to return 0?

Reason: