Code for true strength index indicator

 

                                             Hi there? Please inform me how I can solve these 9 errors

 

                               Line 1:  OnCalculate function not found in the custom indicator

  Line 52: 'AbsMOMBuffer'- undeclared identifier

  Line:52:   ' AbsMOMBuffer'- variable expected

                                                         Line 52:  built-in:bool_SetIndexBuffer( int,double&[ ],ENUM_INDEXBUFFER_TYPE)

   Line 59: 'ema1'- undeclared identifier

    Line 59: ' ema2'-undeclared identifier

      Line 60:'ema1'-undeclared identifier

        Line 60:'ema2'-undeclared identifier

         Line 77:'{' - unbalanced parentheses

           Line 143:'  ;'-unexpected end of program

1.//+------------------------------------------------------------------+

2//|                          Second Indicator.mql5
3//|                            Kamau Muchiri
4//|                     https://www.mql5.com
5#property copyright "Kamau Muchiri"
6#property link      "https://www.mql5.com"
7#property version   "1.00"
8#property indicator_separate_window
9#property indicator_buffers 8
10#property indicator_plots  2
11//--- plot TSI_Line
12#property indicator_label1  "TSI_Line"
13#property indicator_type1   DRAW_LINE
14#property indicator_color1  clrRed
15#property indicator_style1  STYLE_SOLID
16#property indicator_width1  1
17#property indicator_applied_price PRICE_CLOSE
18
19// ..Plot TSI_Signal line
20#property indicator_label2  "TSI signal_Line"
21#property indicator_type2   DRAW_LINE
22#property indicator_color2  clrRed
23#property indicator_style2  STYLE_DASH
24property indicator_width2  1
25
26#include<MovingAverages.mqh>
27//--- input parameters
28input int      EMA1=25;
29input int      EMA2=13;
30
31//...Input parameters for signal line
32input int sMAp=10;
33input ENUM_MA_METHOD MAmode=MODE_EMA;
34//-- indicator buffers
35  double         TSI_LineBuffer[],
36             TSI_sLineBuffer[],
 37              MomBuffer[],
 38              AbsMomBuffer[],
  39             EMA_MOMBuffer[],
  40             EMA_EMAMomBuffer[],
  41            EMA_AbsMomBuffer[],
 42              EMA_EMAAbsMomBuffer[];
43//+------------------------------------------------------------------+
  44//| Custom indicator initialization function                         |
45//+------------------------------------------------------------------+
 46  int OnInit()
 47 {
48//--- indicator buffers mapping
 49  SetIndexBuffer(0,TSI_LineBuffer,INDICATOR_DATA);
 50 SetIndexBuffer(1,TSI_sLineBuffer,INDICATOR_DATA);
 51  SetIndexBuffer(2,MomBuffer,INDICATOR_CALCULATIONS);
 52  SetIndexBuffer(3,AbsMOMBuffer,INDICATOR_CALCULATIONS);
 53  SetIndexBuffer(4,EMA_MOMBuffer,INDICATOR_CALCULATIONS);
  54 SetIndexBuffer(5, EMA_EMAMomBuffer,INDICATOR_CALCULATIONS);
 55  SetIndexBuffer(6,EMA_AbsMomBuffer,INDICATOR_CALCULATIONS);
 56  SetIndexBuffer(7,EMA_EMAAbsMomBuffer,INDICATOR_CALCULATIONS);
57
  58 //Bar starting point
 59PlotIndexSetInteger(0,PLOT_DRAW_BEGIN,ema1+ema2-1);
  60PlotIndexSetInteger(1,PLOT_DRAW_BEGIN,ema1+ema2+sMAp);
61   
62//Set the accuracy of displaying indicator values
  63 IndicatorSetInteger(INDICATOR_DIGITS,2);
  64 string Shortname;
 65  
66//Set a name to show in the separate window
 67  PlotIndexSetString(0,PLOT_LABEL,Shortname);
 68 //---
 69  return(INIT_SUCCEEDED);
 70 }
 71//
 72// Custom indicator iteration function
73int OnCalculate(const int rates_total,
 74               const int prev_calculated,
  75            const int begin,
 76               const double &price[])
 77 {
  78  //If the size of the rates total is too small
 79  if(rates_total<ema1+ema2)
  80   {
  81    return(0);
  82   }
83//calculating the values of momentum
  84//if it is the first call
 85  {
   86  //Set zero values to zero indexes.
  87    MomBuffer[0]=0.0;
   88   AbsMomBuffer[0]=0.0;
   89  }
   90int first;
  91 if(prev_calculted==0)
   92{
   93   first=1;
   94  }
  95 else
   97 }
98
 99 for(int i; i<rates_total; i++)
  100   {
   101     {
   102      MomBuffer[i]=price[i]-price[i-1];
    103     AbsMomBuffer[i]=fabs(MomBuffer[i]);
      104  }
     105 //Calculating the values of the first Smoothing
    106  ExponentialMAOnBuffer(rates_total,prev_calculated,1,ema1,MomBuffer,EMA_MomBuffer);
    107  ExponentialMAOnBuffer(rates_total,prev_calculated,1,ema1,AbsMomBuffer,EMA_MomBuffer);
    108
    109  //Calculating the values of the second smoothing
    110  ExponentialMAOnBuffer(rates_total,prev_calculated,1,ema2,EMA_MomBuffer,EMA_MomBuffer);
    111  ExponentialMAOnBuffer(rates_total,prev_calculated,1,ema2,EMA_AbsMomBuffer,EMA_MomBuffer);
    112
     113 //  Calculating the values of our indicator
    114  if(previous_calculated==0)
     115   {
     116    first=ema1+ema2-1;
     117   }
     118   for(int i=ema1+ ema2; i<rates_total; i++){
      119  {
       120   {
       121    TSI_LineBuffer[i]=100*EMA_EMAMomBuffer[i]/EMA_EMAAbsMomBuffer[i];
        122   }
        123
        124 //Calculating the value of the signal line
        125 int begin2=begin+ema1+ema2-1;
         126 int lwmaws=2;
         127     switch(MAmode)
         128  {
          129    case MODE_EMA:
         130    LinearWeightedMAOnBuffer(rates_total,prev_calculated,begin2,sMAp,TSI_LineBuffer,TSI_sLineBuffer);
          131                break;
          132   case MODE_LWMA:
          133      LinearWeightMAOnBuffer(rates_total,prev_calculated,begin2,sMAp,TSI_LineBuffer,TSI_sLineBuffer);
          134                 break;
          135 case MODE_SMA: 
           136       SimpleMAOnBuffer(rates_total,prev_calculated,begin2,sMAp,TSI_LineBuffer,TSI_sLineBuffer);
            137      break;
            138   case MODE_SMMA:        
            139       SmoothedMAOnBuffer(rates_total,prev_calculated,begin2,sMAp,TSI_LineBuffer,TSI_sLineBuffer);
            140          break;
            141   Exponent
             142 //--- return value of prev_calculated for next call
             143  return(rates_total);
       144
       145   
        146 //+------------------------------------------------------------------+
        147
        148 //+------------------------------------------------------------------+

Descubra novos recursos para o MetaTrader 5 com a comunidade e os serviços MQL5
Descubra novos recursos para o MetaTrader 5 com a comunidade e os serviços MQL5
  • 2022.11.25
  • www.mql5.com
MQL5: linguagem de estratégias de negociação inseridas no Terminal do Cliente MetaTrader 5. A linguagem permite escrever seus próprios sistemas automáticos de negócios, indicadores técnicos, scripts e bibliotecas de funções
 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Are those line numbers actually in your code file?
  3.   }
      95 else   
       97 } 
    Else what?
 

Please delete your copy/paste code and attach the file properly instead.

Don't paste it as plain text, especially not with line numbers. It becomes unreadable, especially if it is so long.

Use the "+ Attach file" icon below the text field.

I would have suggested using the "</>" icon, but since you pasted it with line numbers it would not help either. So attach the original ".mq5" file.