Welcome Forex EA downloads & MT4/MT5 auto-trading resources — EAs, Gold EAs, quant tools and real-world automation.
Sign In Sign Up

Class for drawing TEMA using ring buffer - MetaTrader 5 script | Forex indicator download - MT4/MT5 resources

author EAcpu | 5 reads | 0 comments |

The class for drawing the TEMA using the ring buffer - indicator for MetaTrader 5

The class for drawing the TEMA using the ring buffer - indicator for MetaTrader 5

The CTEMAOnRingBuffer class is designed for calculating the technical indicator Triple Exponential Moving Average ( Triple Exponential Moving Average , TEMA) using an algorithmic ring buffer .

 Class CTEMAOnRingBuffer: publicCArrayRing

title

 #include

Files of the CTEMAOnRingBuffer.mqh class must be placed in the IncOnRingBuffer folder that needs to be created in MQL5\Include\. Attached to the description are two files containing examples used by the classes in this folder. File with categories Ring Buffer , Demar and Moving Average Must be in this folder as well.

 //--- Initialization method:
boolean initialization ( // return false if error, true if success integer period = 12 , // TEMA period ENUM_MA_METHOD method = mode_EMA , // smoothing method integer buffer size = 256 , // size of ring buffer boolean as_series = false // true if time series, otherwise - false );
 //--- Calculation method based on time series or indicator buffer:
Integer MainOnArray( // Returns the number of elements processed constant integer rate_total, // the size of the array constant integer previously calculated, // the number of elements processed on the last call constant integer & prices[], // the array used for calculation );
 //--- Method for calculation based on individual series elements of an array
Double the main value ( // returns the TEMA value constant integer of the set element (bar) rate_total, // the size of the array constant integer previously calculated, // the processed array element constant integer start, // where the important data of the array begins
c double value, // element (bar) value
c Angst integer index // element (bar) index );
 //--- Methods to access data:
Integer BarRequired(); // Returns the number of bars required to draw the indicator
string name(); // returns the name of the indicator
integer period (); // returns period
integer size(); // Returns the size of the ring buffer
Double MA ( integer index); // Returns a moving average, indexed like a time series
double dema( integer index); // Returns dema value, indexed like time series

Calculated data of the indicator can be obtained from the ring buffer just like from a usual array. For example:

//--- Class with TEMA indicator calculation method:
#include CTEMAOnRingBuffer topic;

... //+----------------------------------------------------------------------------------+
//|Custom indicator iteration function |
//+------------------------------------------------------------------+
When integer calculation ( const integer rate_total, // size of array prices[] constant integer previously calculated, // constant integer start of bar processed at last call , // const double & price[] where important data starts ) // array for calculation { //--- calculation of indicators based on time series: tema.MainOnArray(rates_total,prev_calculated,price);

... //--- use data from the "tema" ring buffer,
// For example, copy the data in the indicator buffer: for ( integer i = start;i  Stopped();i++)
      TEMA_Buffer[i] = tema[rates_total- 1 -i]; // TEMA indicator line ... //--- Return the prev_calculated value for the next call: return (rates_total);
  }

When calculating TEMA, the same parameters are performed for moving averages and TEMA as well. We can use MA method to get data from MA ring buffer and DEMA( integer index) and DEMA( integer index) respectively:

 //--- use moving averages and data from the DEMA ring buffer,
// For example, copy them into the indicator buffer: for ( integer i = start;i  Stopped();i++)
    {
      MA_Buffer[i] = dema.MA(rates_total- 1 -i); // Moving average indicator DEMA_Buffer[i] = dema.DEMA(rates_total- 1 -i); // DEMA indicator line }

Note that the index in the ring buffer is the same as the time series .

The class for drawing the TEMA using the ring buffer - indicator for MetaTrader 5

Working result of Test_TEMA_OnArrayRB.mq5, ring buffer size is 256 elements

The class for drawing the TEMA using the ring buffer - indicator for MetaTrader 5
Working result of Test_TEMA_OnValueRB.mq5, ring buffer size is 256 elements

When writing code for the development of MetaQuotes Software Inc. , Integer and Godzilla were used.


Attachment download

📎 cdemaonringbuffer.mqh (7.98 KB)

📎 cmaonringbuffer.mqh (14.9 KB)

📎ctemaonringbuffer.mqh (8.44 KB)

📎 carrayring.mqh (6.64 KB)

📎test_tema_onarrayrb.mq5 (3.03 KB)

📎test_tema_onvaluerb.mq5 (3.44 KB)

Source: MQL5 #1417

Class for drawing TEMA using a ring buffer - Important points before using the MetaTrader 5 script

This page has been supplemented with structured instructions, focusing on the purpose of trading scripts, MT4/MT5 platform compatibility, testing procedures and risk control. Before downloading or deploying, it is recommended to first determine whether it is consistent with your own variety, cycle and account environment.

Suitable for who to use

  • Users who want to quickly screen trading scripts and are willing to do simulation verification first.
  • People who need to compare MT4/MT5 EAs, indicators, scripts or source code projects.
  • Traders who wish to record backtests, parameters and risk boundaries before placing a trade.

Testing and risk control suggestions

  • First verify the default parameters in the strategy tester or demo account, and then adjust the symbol, period, spread and trading period one by one.
  • Scalping, grid, martin, and high-frequency strategies should focus on observing maximum drawdowns, consecutive losses, slippage, and trading frequency.
  • It is not recommended to run any document directly on the real disk. At least observe the simulated disk performance for 2-4 weeks first.

FAQ

Can MT4 and MT5 be used interchangeably?
Usually cannot be used directly. EX4/MQ4 corresponds to MT4, EX5/MQ5 corresponds to MT5, and the source code needs to be compiled in the corresponding MetaEditor.

Is this resource guaranteed to be profitable?
cannot. EAs, indicators and scripts can only be used as trading tools, and the results depend on parameters, market environment, spreads, slippage and risk control.

What else can I continue to watch?
Forex EA download , foreign exchange indicator download , EA evaluation , MQL5 CodeBase .

English Search Notes

This page is also optimized for English search intent around Classes for drawing TEMA using ring buffer - MetaTrader 5 script . Related search terms include: trading script, MT4 script, MT5 script. Test any Forex EA, Expert Advisor, MT4/MT5 indicator, script or MQL source code with historical data and a demo account before live trading.

Verification code Refresh