Download MetaTrader 5

Watch how to download trading robots for free

Interesting script?
So post a link to it -
let others appraise it

You liked the script? Try it in the MetaTrader 5 terminal

2015.11.18 10:20
Singleton Example

Singleton Example - expert for MetaTrader 4

| English Español Português Русский Deutsch 日本語

votes: 12

This is a working singleton code example. The sole purpose of this post is to provide a working code sample of a singleton object. A singleton object is created when there 'can be only one' of the object. This is accomplished by making an object's constructor private, and ensuring assignment and copy operations are also private.

I was working on an EA and identified that an object should never have more than one copy. I don't expect the EA to ever get large enough for it to actually matter that a singleton is used, but I like the clarity in the code for the object's type. Some programmers argue against the use of singletons, but I think the technical reasons for not using them are mostly resolved with newer compiler technology. It didn't seem like anyone had provided an example of this functionality in this environment — I found only an old reference in the Code Base from before private static variable initialization was supported by the compiler — as you can see in this example, this functionality works well today.

Comments or contributions for improving the code are always welcome.

Running Singleton Example

Accelerator Oscillator (AC) Accelerator Oscillator (AC)

The Acceleration/Deceleration Indicator (AC) measures acceleration and deceleration of the current driving force.

Average Directional Movement Index (ADX) Average Directional Movement Index (ADX)

The Average Directional Movement Index Indicator (ADX) helps to determine if there is a price trend.

LinesProfitLoss LinesProfitLoss

Calculates profit (loss) of the current orders on the symbol.

FFC - Forex Factory Calendar FFC - Forex Factory Calendar

Modified version of FF Calendar Indicator with new features.