EA에 Martingale Function 추가관련


 

 


고수님의 도움을 청합니다.
EA빌더로 작성된 EA에 Martingale Function을 추가하려 합니다.
아래 자료는  Martingale과 역 Martingale을 프로그램밍한 것으로 책자에 나와있는 것입니다.
EA빌더와 변수호환 등의 문제를 해결해야할 것 같은데...
한수 지도를 청합니다
 
 
// External variables
extern int MartingaleType = 0; // 0: Martingale, 1: Anti-Martingale
extern int LotMultiplier = 2;
extern int MaxMartingale = 4;
extern double BaseLotSize = 0.1;
// Lot size calculation
if(MartingaleType == 0) int ConsecutiveCount = LossCount;
else if(MartingaleType = 1) ConsecutiveCount = WinCount;
if(ConsecutiveCount > MaxMartingale) ConsecutiveCount = MaxMartingale;
double LotSize = BaseLotSize * MathPow(LotMultiplier,ConsecutiveCount);
 
// External variables
extern int MartingaleType = 0; // 0: Martingale, 1: Anti-Martingale
extern int LotMultiplier = 2;
extern int MaxMartingale = 4;
extern double BaseLotSize = 0.1;
// Lot size calculation
if(MartingaleType == 0) int ConsecutiveCount = LossCount;
else if(MartingaleType = 1) ConsecutiveCount = WinCount;
if(ConsecutiveCount > MaxMartingale) ConsecutiveCount = MaxMartingale;
double LotSize = BaseLotSize * MathPow(LotMultiplier,ConsecutiveCount);
 

 


코멘트 (1)

블루아이

외부 변수 부분에 아래를 설정 합니다.

 

// External variables
extern int MartingaleType = 0; // 0: Martingale, 1: Anti-Martingale
extern int LotMultiplier = 2;
extern int MaxMartingale = 4;
extern double BaseLotSize = 0.1;
int WinCount, LossCount, CloseCount=0;

 

그리고 외부 변수 설정되는 부분중 LOTS였나 LOT이였나를 extern을 빼줍니다. 이건 외부 마틴게일 방식으로 자동 계산하기 위해서입니다.

 

그리고 Start()부분 맨 위에 랏 계산을 하는 부분을 넣어줍니다.

 

// Lot size calculation
if(MartingaleType == 0) int ConsecutiveCount = LossCount;
else if(MartingaleType = 1) ConsecutiveCount = WinCount;
if(ConsecutiveCount > MaxMartingale) ConsecutiveCount = MaxMartingale;
double LotSize = BaseLotSize * MathPow(LotMultiplier,ConsecutiveCount);

 

문제는 WinCount와 LossCount를 계산하는것인데 다음과 같이 처리하시면 됩니다.

init()함수에 아래 부분을 추가 합니다.

 

// Init
WinCount = 0;
LossCount = 0;
CloseCount = OrdersHistoryTotal();

 

 

그리고 Start()함수 맨 위에 다시 이걸 추가합니다.

// Check Loss Or Win
WinCount = 0;
LossCount = 0;
if(CloseCount < OrderHistoryCount()) {
    if(OrderSelect(0, SELECT_BY_POS, MODE_TRADE_HISTORY)) {
        if(OrderProfit() > 0) { WinCount++; LossCount=0; }
        else { LossCount++; WinCount=0; }
    }
}
CloseCount = OrderHistoryCount();

 

대충 이런방식으로 하시면 될거 같습니다.

 

소스편집기에서 작성한 코딩이 아니라 사소한 에러는 발생할수 있습니다. 어쩌면 크리티컬한 에러가 발생할수도 ^^

즐거운 트레이딩 하세요~~~