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


The COBVOnRingBuffer class is designed to calculate the technical indicator On Balance Volume (OBV) ring buffer using the following algorithm.
Class COBVOnRingBuffer: publicCArrayRing
title
#includeFiles of the COBVOnRingBuffer.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. A file ring buffer of class . must also be in this folder.
//--- Initialization method: boolean initialization ( // return false if error, true if success integer period = 0 , // OBV period integer buffer size = 256 , // size of ring buffer boolean as_series = false // true if time series, otherwise - false );
OBV periods are used as follows: Integer : If the value is 0 (default), the indicator works like the one included in the terminal - calculations will be performed for all bars of the chart. If there are any other positive values, the value of each chart bar is calculated using the specified number of bars (moving average principle).
//--- Calculation method based on time series or indicator buffer: Integer MainOnArray( // Returns the number of elements processed constant integer rate_total, // size of the array constant integer previously calculated, // the number of elements processed on the last call constant double & price[], // price constant long & volume[]); // volume );
//--- Calculation method based on individual elements of the array Double the main value ( // returns the OBV 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 onst double the price, // price c Angst long volume, // volume c Angst integer index // element (column) 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
Calculated data of the indicator can be obtained from the ring buffer just like from a usual array. For example:
//--- Class with OBV indicator calculation method: #includeCOBVOnRingBuffer obv; ... //+----------------------------------------------------------------------------------+ //|Custom indicator iteration function | //+------------------------------------------------------------------+ integer calculation ( const integer rate_total, constant integer previously calculated, const datetime &time[], const double & open[], const double &high[], const double &low[], const double &close[], constant long &scale[], const long &volume[], const int & spread[]) { //--- Indicator calculation based on time series: obv.MainOnArray(rates_total,prev_calculated,close,tick_volume); ... //--- use data from ring buffer "obv", // For example, copy the data in the indicator buffer: for ( integer i = start;i Stopped();i++) OBV_Buffer[i] = obv[rates_total- 1 -i]; // Indicator line ... //--- Return the prev_calculated value of the next call: return (rates_total); }
Note that the index in the ring buffer is the same as the time series .
Working result of Test_OBV_OnArrayRB.mq5, ring buffer size is 256 elements When writing code for the development of MetaQuotes Software Inc. , Integer and Godzilla were used. 📎 test_obv_onarrayrb.mq5 (3.21 KB) 📎 test_obv_onvaluerb.mq5 (3.75 KB) 📎 carrayring.mqh (6.64 KB) 📎 cobvonringbuffer.mqh (9.13 KB) Source: MQL5 #1402 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. Can MT4 and MT5 be used interchangeably? Is this resource guaranteed to be profitable? What else can I continue to watch? This page is also optimized for English search intent around Classes for drawing OBV 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.

Working result of Test_OBV_OnValueRB.mq5, ring buffer size is 256 elements Attachment download
Classes for drawing OBVs using ring buffers - Important points before using MetaTrader 5 scripts
Suitable for who to use
Testing and risk control suggestions
FAQ
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.
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.
Forex EA download , foreign exchange indicator download , EA evaluation , MQL5 CodeBase . English Search Notes
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •