Watch how to download trading robots for free
Find us on Facebook!
Join our fan page
Interesting script?
So post a link to it -
let others appraise it
You liked the script? Try it in the MetaTrader 5 terminal
Libraries

Programming patterns - Facade - library for MetaTrader 5

Views:
3030
Rating:
(10)
Published:
2020.07.02 10:40
Facade.mq5 (0.54 KB) view
Facade.mqh (10.21 KB) view
Need a robot or indicator based on this code? Order it on Freelance Go to Freelance
/****************************************************************
Programming patterns - Facade 
Provide a unified interface to a set of interfaces in a subsystem. Facade defines a higher-
level interface that makes the subsystem easier to use.
/**/



/****************************************************************/
class SubSystemA {public:void OperationA() {Print("SubSystem A");}};
/**/
class SubSystemB {public:void OperationB() {Print("SubSystem B");}};
/**/
class SubSystemC {public:void OperationC() {Print("SubSystem C");}};
/****************************************************************/
class Facade
  {
public:
   void              OperationAB() {subSystemA.OperationA(); subSystemB.OperationB();}
   void              OperationBC() {subSystemB.OperationB(); subSystemC.OperationC();}
protected:
   SubSystemA        subSystemA;
   SubSystemB        subSystemB;
   SubSystemC        subSystemC;
  };


/****************************************************************
Applicability
   Use the Facade pattern when
      *you want to provide a simple interface to a complex subsystem. Subsystems
       often get more complex as they evolve. Most patterns, when applied, result in
       more and smaller classes. This makes the subsystem more reusable and easier to
       customize, but it also becomes harder to use for clients that don't need to
       customize it. A facade can provide a simple default view of the subsystem that is
       good enough for most clients. Only clients needing more customizability will
       need to look beyond the facade.
      *there are many dependencies between clients and the implementation classes of
       an abstraction. Introduce a facade to decouple the subsystem from clients and
       other subsystems, thereby promoting subsystem independence and portability.
      *you want to layer your subsystems. Use a facade to define an entry point to each
       subsystem level. If subsystems are dependent, then you can simplify the
       dependencies between them by making them communicate with each other
       solely through their facades.
Participants
   *Facade 
      *knows which subsystem classes are responsible for a request.
      *delegates client requests to appropriate subsystem objects.
   *subsystem classes 
      *implement subsystem functionality.
      *handle work assigned by the Facade object.
      *have no knowledge of the facade; that is, they keep no references to it.
Collaborations
   *Clients communicate with the subsystem by sending requests to Facade, which
    forwards them to the appropriate subsystem object(s). Although the subsystem
    objects perform the actual work, the facade may have to do work of its own to
    translate its interface to subsystem interfaces.
   *Clients that use the facade don't have to access its subsystem objects directly.
Consequences
   The Facade pattern offers the following benefits:
      1. It shields clients from subsystem components, thereby reducing the number of
       objects that clients deal with and making the subsystem easier to use.
      2. It promotes weak coupling between the subsystem and its clients. 
         Often the components in a subsystem are strongly coupled. Weak coupling lets you vary
          the components of the subsystem without affecting its clients. Facades help layer
          a system and the dependencies between objects. They can eliminate complex or
          circular dependencies. This can be an important consequence when the client
          and the subsystem are implemented independently.
         Reducing compilation dependencies is vital in large software systems. You want
          to save time by minimizing recompilation when subsystem classes change.
         Reducing compilation dependencies with facades can limit the recompilation
          needed for a small change in an important subsystem. A facade can also simplify
          porting systems to other platforms, because it's less likely that building one
          subsystem requires building all others.
      3. It doesn't prevent applications from using subsystem classes if they need to.
         Thus you can choose between ease of use and generality.
Related Patterns
   *Abstract Factory can be used with Facade to provide an interface for creating
    subsystem objects in a subsystem-independent way. Abstract Factory can also be used
    as an alternative to Facade to hide platform-specific classes.
   *Mediator is similar to Facade in that it abstracts functionality of existing classes.
    However, Mediator's purpose is to abstract arbitrary communication between colleague
    objects, often centralizing functionality that doesn't belong in any one of them. A
    mediator's colleagues are aware of and communicate with the mediator instead of
    communicating with each other directly. In contrast, a facade merely abstracts the
    interface to subsystem objects to make them easier to use; it doesn't define new
    functionality, and subsystem classes don't know about it.
    Usually only one Facade object is required. Thus Facade objects are often Singletons
/**/


/****************************************************************
Example of the Facade pattern usage. Client.
/****************************************************************/
void OnStart()
  {
   Facade facade;
   facade.OperationAB();
     {string s; for(int i=0; i<11; i++) {s+="-";} Print(s);}
   facade.OperationBC();
  }
/****************************************************************
Output:
   SubSystem A
   SubSystem B
   -----------
   SubSystem B
   SubSystem C
/**/


    Profit and Losses represented in Pips Profit and Losses represented in Pips

    Simple script to see your current Profit Losses in Pips.

    Programming patterns - Composite Programming patterns - Composite

    Compose objects into tree structures to represent part-whole hierarchies.

    Modify SL and/or TP Modify SL and/or TP

    I used to suffer from unnecessary losses and/or cutting my profit short since I wasn't fast enough to modify my SL and/or TP. That is why I've wrote these scripts that will allow me to react fast when I must modify my Sl and/or TP especially when I have many open and/or pending trades. I know there are plenty of Metatraders who also suffer from this and that is why I would like to share these scripts with you, hopefully it will be beneficial. Do not forget to send you comments as well as rate these scripts. Happy trading!

    ComeBacker Trading ComeBacker Trading

    short-term forex strategy for beginners.