거래 로봇을 무료로 다운로드 하는 법을 시청해보세요
당사를 Facebook에서 찾아주십시오!
당사 팬 페이지에 가입하십시오
스크립트가 흥미로우신가요?
그렇다면 링크 to it -
하셔서 다른 이들이 평가할 수 있도록 해보세요
스크립트가 마음에 드시나요? MetaTrader 5 터미널에서 시도해보십시오
라이브러리

Design patterns - Builder - MetaTrader 5용 라이브러리

조회수:
3038
평가:
(11)
게시됨:
2020.07.22 07:04
Pattern.mq5 (0.1 KB) 조회
Builder.mqh (8.71 KB) 조회
Patterns.mqh (5.6 KB) 조회
SAList.mqh (0.96 KB) 조회
AList.mqh (3.28 KB) 조회
IAList.mqh (1.21 KB) 조회
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동
//----------------------------------------------------------------------------------------------
//BUILDER - A CREATIONAL PATTERN
// | INTENT
// |  | for a complex object
// |  |  | separate its construction from representation
// |  |  | same construction process
// |  |  |  | can create different representations
// | APPLICABILITY -----------------------------------------------------------------------------
// |  | algorithm for creating a complex object should be 
// |  |  | independent of the parts
// |  |  |  | that make up the object 
// |  |  |  | how they're assembled
// |  | construction
// |  |  | must allow different representations
// | STRUCTURE
// |  |                                         builder
// |  |         |           Director          |o------------>|  Builder  |
// |  |         |-----------------------------|              |-----------|
// |  |         |Construct()                  |              |BuildPart()|
// |  |         | for all objects in structure|                    ^
// |  |         |  builder.BuildPart()        |                    |
// |  |                                                    |ConcreteBuilder|- - - - ->|Product|
// |  |                                                    |---------------|
// |  |                                                    |BuildPart()    |
// |  |                                                    |GetResult()    |
// | PARTICIPANTS
// |  | Builder
// |  |  | abstract interface
// |  |  |  | for creating product parts
// |  | ConcreteBuilder
// |  |  | constructs and assembles product parts
// |  |  |  | by implementing the builder interface
// |  |  | defines and keeps track of the representation it creates
// |  |  | provides an interface for retrieving the product
// |  | Director
// |  |  | constructs an object
// |  |  |  | using the builder interface
// |  | Product
// |  |  | represents the complex object under construction
// |  |  |  | ConcreteBuilder
// |  |  |  |  | builds the product's internal representation
// |  |  |  |  | defines the process by which it's assembled
// |  |  | includes
// |  |  |  | classes that define the constituent parts
// |  |  |  | interfaces for assembling the parts into the final result
// | COLLABORATIONS ----------------------------------------------------------------------------
// |  | Client
// |  |  | creates the Director object
// |  |  | configures it with the desired Builder object
// |  | Director
// |  |  | notifies the builder whenever a part of the product should be built
// |  | Builder
// |  |  | handles requests from the director
// |  |  | adds parts to the product
// |  | Client
// |  |  | retrieves the product from the builder
// |  |
// |  |     aClient                               aDirector           aConcreteBuilder
// |  |        |                                      |                      |
// |  |       | |new ConcreteBuilder                                         | 
// |  |       | |- - - - - - - - - - - - - - - - - - -|- - - - - - - - - - >| |
// |  |       | |                                                           | |
// |  |       | |new Director(aConcreteBuilder)       |                      | 
// |  |       | |- - - - - - - - - - - - - - - - - ->| |                     |
// |  |       | |                                    | |                     |
// |  |       | |                                     |                      |
// |  |       | |Construct()                          |                      |
// |  |       | |----------------------------------->| |BuildPartA()         | 
// |  |       | |                                    | |------------------->| |
// |  |       | |                                    | |                    | |
// |  |       | |                                    | |                     |
// |  |       | |                                    | |BuildPartB()         | 
// |  |       | |                                    | |------------------->| |
// |  |       | |                                    | |                    | |
// |  |       | |                                    | |                     |
// |  |       | |                                    | |BuildPartC()         | 
// |  |       | |                                    | |------------------->| |
// |  |       | |                                    | |                    | |
// |  |       | |                                     |                      |
// |  |       | |GetResult()                          |                      | 
// |  |       | |-------------------------------------|-------------------->| |
// |  |       | |                                     |                     | |
// |  |        |                                      |                      |
// |  |
// | CONSEQUENCES
// |  | It lets you vary product's internal representation
// |  |  | define a new kind of builder
// |  | Isolates code for construction and representation
// |  |  | ConcreteBuilder
// |  |  |  | contains all the code
// |  |  |  |  | to create and assemble a product
// |  |  | code is written once
// |  |  |  | Directors can reuse it
// |  |  |  |  | same set of parts to build Product variants 
// |  | Finer control over the construction 
// |  |  | step by step
// |  |  |  | construction of the product under the director's control
// |  |  | finished product 
// |  |  |  | retrieved by the director from the builder
// | IMPLEMENTATION ----------------------------------------------------------------------------
// |  | Operation for each component defined by Builder
// |  |  | does nothing by default
// |  | Assembly and construction interface
// |  |  | step-by-step fashion
// |  |  | general interface for all kinds of concrete builders
// |  |  |  | a model where
// |  |  |  |  | construction results are appended to the product
// |  |  |  |  |  | is usually sufficient 
// |  |  |  | if parts constructed earlier must be accessed
// |  |  |  |  | director receives child nodes from the builder
// |  |  |  |  |  | passes them back to the builder to build the parent nodes
// |  | No abstract class for products
// |  |  | products differ greatly
// |  |  | client is in a position to know
// |  |  |  | concrete subclass of Builder in use
// |  |  |  | can handle its products accordingly
// |  | Empty methods as default in Builder
// |  |  | clients override operations they're interested in
// | CODE --------------------------------------------------------------------------------------
#include <SRC\Patterns\Patterns.mqh>
namespace Builder
{
class Product
  {
public:
   void              Add(string);
   void              Show();
protected:
   SAList            parts;
  };
void Product::Add(string part) {parts+=part;}
void Product::Show(void) {int c=parts.Count(); for(int i=0; i<c; i++) Print(parts[i]);}
//----------------------------------------------------------------------------------------------
interface Builder
  {
   void BuildPartA();
   void BuildPartB();
   void BuildPartC();
   Product* GetResult();
  };
//----------------------------------------------------------------------------------------------
class Director
  {
public:
   void              Construct();
                     Director(Builder*);
                    ~Director();
protected:
   Builder*          builder;
  };
void Director::Director(Builder *b) {builder=b;}
void Director::~Director(void) {delete builder;}
void Director::Construct(void)
  {
   builder.BuildPartA();
   builder.BuildPartB();
   builder.BuildPartC();
  }
//----------------------------------------------------------------------------------------------
class ConcreteBuilder:public Builder
  {
public:
   void              BuildPartA();
   void              BuildPartB();
   void              BuildPartC();
   Product*          GetResult();
protected:
   Product           product;
  };
//---
void ConcreteBuilder::BuildPartA(void) {product.Add("Part A");}
void ConcreteBuilder::BuildPartB(void) {product.Add("Part B");}
void ConcreteBuilder::BuildPartC(void) {product.Add("Part C");}
Product* ConcreteBuilder::GetResult(void) {return &product;}
//----------------------------------------------------------------------------------------------
class Client:public ClientExample {public: string Output(); void Run();};
string Client::Output() {return __FUNCTION__;}
void Client::Run()
  {
   Builder* builder=new ConcreteBuilder;
   Director director(builder);
   director.Construct();
   Product* product=builder.GetResult();
   product.Show();
  }
}
//OUTPUT ---------------------------------------------------------------------------------------
// | Creational::Builder::Client::Output
// | Part A
// | Part B
// | Part C 
    Step chart Step chart

    Step chart (upgraded version)

    Identify potential Trends/Range (Pivot Points) Identify potential Trends/Range (Pivot Points)

    When I start learning about trading, I remember the trading pioneer Shawn Lucas (founder of Apiary-fund) saying "trading is simple, you go from bound range market to breakout market and vice versa". I looked at few charts and he was right. So I told myself, I have to always eyeball ranging market and trending market but with the help of an indicator. There are plenty for indicator that help us eyeball these ranging/trending market and they work really well, but I like using Pivot Points.

    Range Follower Range Follower

    this expert opens trade in the direction of the trend when specific rate of average daily range has been passed.

    Random walk index Random walk index

    Random walk index (optimized version)