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

state - behavioral design pattern - MetaTrader 5용 라이브러리

조회수:
2875
평가:
(12)
게시됨:
2020.11.25 07:24
State.mq5 (4.36 KB) 조회
\MQL5\Include\Mqh\Patterns\State\
State.mqh (0.5 KB) 조회
Context.mqh (2.04 KB) 조회
이 코드를 기반으로 한 로봇이나 지표가 필요하신가요? 프리랜스로 주문하세요 프리랜스로 이동
//+------------------------------------------------------------------+
//|                                                        State.mq5 |
//|                                    2019-2020, dimitri pecheritsa |
//|                                                 792112@gmail.com |
//+------------------------------------------------------------------+
//
//   state - behavioral design pattern
//   
//   from: design patterns: elements of reusable object-oriented software
//   by gof: erich gamma, richard helm, ralph johnson, john vlissides
//   published in 1994
//
//   intent
//
//   allow an object to alter its behavior when its internal state changes.
//the object will appear to change its class
//
//   applicability
//
//   an object's behavior depends on its state, and it must change its
//behavior at run-time depending on that state
//   operations have large, multipart conditional statements that depend
//on the object's state. this state is usually represented by one or more
//enumerated constants. often, several operations will contain this same
//conditional structure. the state pattern puts each branch of the conditional
//in a separate class. this lets you treat the object's state as an object
//in its own right that can vary independently from other objects
//
//   structure
//   
//                       state
//     |Context        |o------------------>|State   |
//     |---------------|                    |--------|
//     |Request()      |                    |Handle()|
//     | state.Handle()|                         |
//                          +--------------------+--- - - - -
//                          |                    |
//                  |ConcreteStateA|     |ConcreteStateB|
//                  |--------------|     |--------------|
//                  |Handle()      |     |Handle()      |
//
//   participants
//
//   context
//      defines the interface of interest to clients
//      maintains an instance of a concrete state subclass that defines
//the current state
//   state
//      defines an interface for encapsulating the behavior associated
//with a particular state of the context
//   concrete state subclasses
//      each subclass implements a behavior associated with a state of
//the context
//
//   collaborations
//   
//   context delegates state-specific requests to the current concrete
//state object
//   a context may pass itself as an argument to the state object handling
//the request. this lets the state object access the context if necessary
//   context is the primary interface for clients. clients can configure
//a context with state objects. once a context is configured, its clients
//don't have to deal with the state objects directly
//   either context or the concrete state subclasses can decide which
//state succeeds another and under what circumstances

//+------------------------------------------------------------------+
//| client                                                           |
//+------------------------------------------------------------------+
#include <Mqh\Patterns\State\State.mqh>
#include <Mqh\Patterns\State\Context.mqh>
#include <Mqh\Patterns\State\ConcreteStateA.mqh>
#include <Mqh\Patterns\State\ConcreteStateB.mqh>
void OnStart(void)
  {
   Context context(new ConcreteStateA);
   context.Request();
   context.Request();
  }

//   output
//   
//   context is requesting its state 2097152 which will handle this context
//   concrete state a (2097152) is handling context and changing the context state
//   context state changed to: 3145728
//   context is requesting its state 3145728 which will handle this context
//   concrete state b (3145728) is handling context and changing the context state
//   context state changed to: 4194304
//
//   consequences
//   
//   it localizes state-specific behavior and partitions behavior for
//different states
//   it makes state transitions explicit
//   state objects can be shared
//
//   implementation
//
//   who defines the state transitions?
//   a table-based alternative
//   creating and destroying state objects
//   using dynamic inheritance
//
//   related patterns
//
//   flyweight pattern explains when and how state objects can be shared
//   state objects are often singletons
//
//+------------------------------------------------------------------+


Doulble MA Cross Draw Histogram MT5 Doulble MA Cross Draw Histogram MT5

Doulble MA Cross Draw Histogram MT5

MQL Plus Enhanced Error Handler Support MQL Plus Enhanced Error Handler Support

An (optional) include file to enhance error code handling experience.

Universal Signals & Universal Trailing Modules Universal Signals & Universal Trailing Modules

This is a module for MQL5 Wizard and Standard Library, which allows you to generate expert adviser based on arbitrary set of indicators and conditions.

Fibonacci Potential Entry - MT5 Fibonacci Potential Entry - MT5

The 8 effective steps to build a robust day trading plan using Fibonacci retracement