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 OBV using ring buffer - MetaTrader 5 script | Forex indicator download - MT4/MT5 resources

author EAcpu | 5 reads | 0 comments |

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

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

The COBVOnRingBuffer class is designed to calculate the technical indicator On Balance Volume (OBV) ring buffer using the following algorithm.

 Class COBVOnRingBuffer: publicCArrayRing

title

 #include

Files 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:
#include COBVOnRingBuffer 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 .

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

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

The class for drawing the OBV using the ring buffer - indicator for MetaTrader 5
Working result of Test_OBV_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

📎 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

Classes for drawing OBVs using ring buffers - Important points before using MetaTrader 5 scripts

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 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.

Verification code Refresh