대부분의 통화에서 기준일수 최대격차와 현재위치값을 기준으로 통화간 이격도가 큰 경우 헤지하는 전략이다.
//+------------------------------------------------------------------+
//| gguri_convergence_V0.2 |
//| Copyright @ 2012 Gguriru Project |
//+------------------------------------------------------------------+
//+------------------------------------------------------------------+
//| Trading EA(Multi Pair Hedge Strategies) |
//+------------------------------------------------------------------+
/*
- 기준일수 최대격차와 현재위치값을 기준으로 통화간 이격도가 큰 경우 헤지하는 전략
- 통화는 경쟁력있는 Spread확보를 할 수 있는
EURUSD, GBPUSD, USDJPY, USDCHF, EURGBP, AUDUSD, NZDUSD USDCAD 등(브로커별로 확인요망)
*/
#import "stdlib.ex4"
string ErrorDescription(int a0);
//+------------------------------------------------------------------+
//| 외생변수 및 기타 내생변수 |
//+------------------------------------------------------------------+
extern double FixLot = 0.1; // 진입 랏사이즈 설정
extern double slippage = 3.0; // 슬리피지 허용 변수
extern int MaxOrders = 2; // 진입시 하나의 전략당 Max Order 설정
extern bool EntryEnabled = TRUE; // 진입가능 여부
extern bool ConVerFilter01 = TRUE; // 전략 1
extern int TargetProfit = 10; // 청산기준 전략당 수익 설정
extern int TargetRatio = 60; // 진입기준 이격도 설정
extern double TargetSpread = 1.5; // 진입기준 Pip설정
extern string Sym01 = "EURUSD"; // 적용 대상 통화 1
extern string Sym02 = "GBPUSD"; // 적용 대상 통화 2
extern string Sym03 = "EURGBP"; // 스프레드 적용 대상 통화
extern int HL_Days = 76; // 최대값 최저값 기준일수
extern int TimeFrame = 240; // TF : PERIOD_M1(1), PERIOD_M5(5), PERIOD_M15(15), PERIOD_M30(30), PERIOD_H1(60), PERIOD_H4(240), PERIOD_D1(1440), 0(Timeframe used on the chart.)
// 거래가능 요일 선택
extern bool TimeFilter = FALSE; // Time Filter 적용 여부
extern bool MON = TRUE;
extern bool TUE = TRUE;
extern bool WED = TRUE;
extern bool THU = TRUE;
extern bool FRI = TRUE;
extern bool SAT = TRUE;
extern bool SUN = TRUE;
extern int Start_Time = 16; // Local Time 기준(한국시간 기준), 24시간제
extern int Finish_Time = 2; // Local Time 기준(한국시간 기준), 24시간제
extern int Servers_GMT = 2; // Server 시간(GMT + ?)
extern int Locals_GMT = 9; // Local 시간(GMT + ?)
extern string Commentary = "gguri_convergence_V0.2"; // Initial Entry 주문시 비고
// 내생변수
int shifts = 1; // 계산 기준 이전바 (1 = 바로 이전바)
int indexs = 1;
bool ECN = FALSE; // 주문시 ECN 여부 확인(OrderModify)
int mypoint; // 4 digit, 5digit broker에 대한 point 설정변수
datetime PreviousBarTime1;
datetime PreviousBarTime2;
//+------------------------------------------------------------------+
//| 초기화 |
//+------------------------------------------------------------------+
int init()
{ // 초기화 시작
// Day 및 Time Filter 설정
DAYS_2TRADE();
} // 초기화 종료
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| EA Start |
//+------------------------------------------------------------------+
int start()
{ // EA Start
// 전략별 Magic Number부여
int magic1 = 11085290;
int magic2 = 22085290;
// 거래 조건 설정
//+------------------------------------------------------------------+
//| 매수 및 매도조건 설정함수 |
//+------------------------------------------------------------------+
/*
매수/매도조건 : 기준일 최대 격차값을 계산하고, 현재가와의 이격도를 계산한 후, 지정 이격도를 초과하는 경우 진입
*/
bool BaseBUY = FALSE;
bool BaseSell = FALSE;
double HMax01 = iHigh(Sym01,TimeFrame,iHighest(Sym01,TimeFrame,MODE_HIGH,HL_Days,shifts)) ; // 기준기간내 최고가
double LMin01 = iLow(Sym01,TimeFrame,iLowest(Sym01,TimeFrame,MODE_LOW,HL_Days,shifts)) ; // 기준기간내 최저가
double HLAvg01 = NormalizeDouble((HMax01 + LMin01)/2.0, Digits); // 기준기간내 중간값
double HMax02 = iHigh(Sym02,TimeFrame,iHighest(Sym02,TimeFrame,MODE_HIGH,HL_Days,shifts)); // 기준기간내 최고가
double LMin02 = iLow(Sym02,TimeFrame,iLowest(Sym02,TimeFrame,MODE_LOW,HL_Days,shifts)) ; // 기준기간내 최저가
double HLAvg02 = NormalizeDouble((HMax02 + LMin02)/2.0, Digits); // 기준기간내 중간값
double BPrice01 = iClose(Sym01, 1, shifts); // 기준바의 현재 종가
double BPrice02 = iClose(Sym02, 1, shifts); // 기준바의 현재 종가
double BaseRatio01 = NormalizeDouble( (BPrice01 - LMin01)/(HMax01 - LMin01), 4) * 100; // 개별 이격도 계산
double BaseRatio02 = NormalizeDouble( (BPrice02 - LMin02)/(HMax02 - LMin02), 4) * 100; // 개별 이격도 계산
double ConvergenceRatio01 = BaseRatio01 - BaseRatio02; // 이격도 계산
double HMax_01 = iHigh(Sym01,TimeFrame,iHighest(Sym01,TimeFrame,MODE_HIGH,HL_Days-indexs,shifts+indexs)) ; // 이전 기준기간내 최고가
double LMin_01 = iLow(Sym01,TimeFrame,iLowest(Sym01,TimeFrame,MODE_LOW,HL_Days-indexs,shifts+indexs)) ; // 이전 기준기간내 최저가
double HLAvg_01 = NormalizeDouble((HMax_01 + LMin_01)/2.0, Digits); // 이전 기준기간내 중간값
double HMax_02 = iHigh(Sym02,TimeFrame,iHighest(Sym02,TimeFrame,MODE_HIGH,HL_Days-indexs,shifts+indexs)) ; // 이전 기준기간내 최고가
double LMin_02 = iLow(Sym02,TimeFrame,iLowest(Sym02,TimeFrame,MODE_LOW,HL_Days-indexs,shifts+indexs)) ; // 이전 기준기간내 최저가
double HLAvg_02 = NormalizeDouble((HMax_02 + LMin_02)/2.0, Digits); // 이전 기준기간내 중간값
double BPrice_01 = iClose(Sym01, 1, shifts+indexs); // 이전 기준바의 현재 종가
double BPrice_02 = iClose(Sym02, 1, shifts+indexs); // 이전 기준바의 현재 종가
double BaseRatio_01 = NormalizeDouble( (BPrice_01 - LMin_01)/(HMax_01 - LMin_01), 4) * 100; // 개별 이격도 계산
double BaseRatio_02 = NormalizeDouble( (BPrice_02 - LMin_02)/(HMax_02 - LMin_02), 4) * 100; // 개별 이격도 계산
double ConvergenceRatio_01 = BaseRatio_01 - BaseRatio_02;
// Symbol간 Gap Spread 산정
// *** EURGBP = EURUSD / GBPUSD
bool SpdGapBuy = False;
bool SpdGapSell = False;
double ask01 = MarketInfo(Sym01,MODE_ASK);
double ask02 = MarketInfo(Sym02,MODE_ASK);
double ask03 = MarketInfo(Sym03,MODE_ASK);
double bid01 = MarketInfo(Sym01,MODE_BID);
double bid02 = MarketInfo(Sym02,MODE_BID);
double bid03 = MarketInfo(Sym03,MODE_BID);
double TargetGap = TargetSpread*MarketInfo(Sym03,MODE_POINT)*PointValue(Sym03);
if ( NormalizeDouble(bid03,5) - NormalizeDouble(ask01/ask02,5) > TargetGap ) SpdGapSell = true;
else SpdGapSell = False;
if ( NormalizeDouble(bid03,5) - NormalizeDouble(ask01/ask02,5) < -TargetGap ) SpdGapBuy = true;
else SpdGapBuy = False;
if( SpdGapSell && ConvergenceRatio01 > TargetRatio ) BaseSell = TRUE;
else BaseSell = FALSE;
if( SpdGapBuy && ConvergenceRatio01 < -TargetRatio ) BaseBUY = TRUE;
else BaseBUY = FALSE;
//+------------------------------------------------------------------+
//| 매수/매도 주문 설정 |
//+------------------------------------------------------------------+
int ticket1=0;
int ticket2=0;
if (EntryEnabled) { // Entry 시작
if (ConVerFilter01) { // ConVerFilter01 시작
if ( NewBarBuy() && TotalOrders(magic1) < MaxOrders && BaseBUY ) { // 주문 시작
ticket1 = OpenOrder( Sym01,OP_BUY,FixLot,slippage, 0, 0, magic1 );
} // 주문 종료
if ( NewBarSell() && TotalOrders(magic1) < MaxOrders && BaseBUY ) { // 주문 시작
ticket2 = OpenOrder( Sym02,OP_SELL,FixLot,slippage, 0, 0, magic1 );
} // 주문 종료
else
if ( NewBarSell() && TotalOrders(magic2) < MaxOrders && BaseSell ) { // 주문 시작
ticket1 = OpenOrder( Sym01,OP_SELL,FixLot,slippage, 0, 0, magic2 );
} // 주문 종료
if ( NewBarBuy() && TotalOrders(magic2) < MaxOrders && BaseSell ) { // 주문 시작
ticket2 = OpenOrder( Sym02,OP_BUY,FixLot,slippage, 0, 0, magic2 );
} // 주문 종료
} // ConVerFilter01 종료
} // Entry 종료
//+------------------------------------------------------------------+
//| 청산처리 Logic |
//+------------------------------------------------------------------+
// 현재 청산조건 충족시 일괄 청산
if ( Profit(magic1) > TargetProfit ) { // magic1 Close 시작
CloseAllOpens(magic1);
return(0);
} // magic1 Close 끝
if ( Profit(magic2) > TargetProfit ) { // magic2 Close 시작
CloseAllOpens(magic2);
return(0);
} // magic2 Close 끝
//+------------------------------------------------------------------+
//| 전송 데이타와 전송받은 데이타 화면표시 |
//+------------------------------------------------------------------+
string ScreenStr; // 화면표시 문자열
int digit01 = MarketInfo(Sym01, MODE_DIGITS);
int digit02 = MarketInfo(Sym02, MODE_DIGITS);
string SHMax01 = DoubleToStr(HMax01,digit01);
string SHMax02 = DoubleToStr(HMax02,digit02);
string SLMin01 = DoubleToStr(LMin01,digit01);
string SLMin02 = DoubleToStr(LMin02,digit02);
string SHLAvg01 = DoubleToStr(HLAvg01,digit01);
string SHLAvg02 = DoubleToStr(HLAvg02,digit02);
string SBPrice01 = DoubleToStr(BPrice01,digit01);
string SBPrice02 = DoubleToStr(BPrice02,digit02);
ScreenStr = StringConcatenate("Server : ",AccountServer()," , Time : ",TimeToStr(TimeCurrent(),TIME_SECONDS)," 평가잔액 = ",AccountEquity()," , Order Lot : ",FixLot,", MinLot : ",MarketInfo(Symbol(), MODE_MINLOT),", LotStep ",MarketInfo(Symbol(), MODE_LOTSTEP)," Time Frame_",TimeFrame,"분")+"\n";
ScreenStr = ScreenStr + StringConcatenate("New Entry : ",EntryEnabled," , StopLevel : ",MarketInfo(Symbol(), MODE_STOPLEVEL)," , Freeze Level : ",MarketInfo(Symbol(), MODE_FREEZELEVEL)," , StopOut : ",AccountStopoutLevel(),"%",", Target Profit : ",TargetProfit," BuySig : ",BaseBUY,"_SellSig : ",BaseSell," Target Ratio : ",TargetRatio)+"\n";
ScreenStr = ScreenStr + StringConcatenate("Target Spread : ",DoubleToStr(TargetGap,5)," Market Spread : ",DoubleToStr(NormalizeDouble(bid03,5) - NormalizeDouble(ask01/ask02,5),5)," GapBuy : ",SpdGapBuy," GapSell : ",SpdGapSell)+"\n";
ScreenStr = ScreenStr + StringConcatenate("기준일수 : ",HL_Days," 통화 : ",Sym01,"_최고 : ",SHMax01,"_최저 : ",SLMin01," 중간값 : ",SHLAvg01," 현재가 : ",SBPrice01," 현재위치(%) : ",BaseRatio01," 현재이격도 : ",ConvergenceRatio01)+"\n";
ScreenStr = ScreenStr + StringConcatenate("기준일수 : ",HL_Days," 통화 : ",Sym02,"_최고 : ",SHMax02,"_최저 : ",SLMin02," 중간값 : ",SHLAvg02," 현재가 : ",SBPrice02," 현재위치(%) : ",BaseRatio02," 이전이격도 : ",ConvergenceRatio_01)+"\n";
ScreenStr = ScreenStr + StringConcatenate("전략1 : Buy_",Sym01," Sell_",Sym02," 현수익 = $",Profit(magic1)," , 현매매 = ",TotalOrders(magic1),"건, 총수익 = $",HistoryProfit(magic1)," , 총매매 = ",HistoryOrders(magic1),"건") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략2 : Buy_",Sym02," Sell_",Sym01," 현수익 = $",Profit(magic2)," , 현매매 = ",TotalOrders(magic2),"건, 총수익 = $",HistoryProfit(magic2)," , 총매매 = ",HistoryOrders(magic2),"건") + "\n";
ScreenStr = ScreenStr +"==============================================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("총전략 : 현수익 = $",Profit(magic1)+Profit(magic2)," , 현매매 = ",TotalOrders(magic1)+TotalOrders(magic2),"건, 총수익 = $",HistoryProfit(magic1)+HistoryProfit(magic2)," , 총매매 = ",HistoryOrders(magic1)+HistoryOrders(magic2),"건") + "\n";
Comment(ScreenStr);
return(0);
} // EA Start is Ended
//+------------------------------------------------------------------+
//| 통화별 Point조정 설정 |
//+------------------------------------------------------------------+
// 5 digit broker adjustment
int PointValue(string Symbolnames)
{
if(MarketInfo(Symbolnames, MODE_DIGITS)==3 || MarketInfo(Symbolnames, MODE_DIGITS)==5)
{
mypoint = 10;
}
else
{
mypoint = 1;
}
return(mypoint);
}
//+------------------------------------------------------------------+
//| 거래가능 요일 선택 함수 |
//+------------------------------------------------------------------+
void DAYS_2TRADE() {
if ((MON && DayOfWeek() == 1) || (TUE && DayOfWeek() == 2) || (WED && DayOfWeek() == 3) || (THU && DayOfWeek() == 4) || (FRI && DayOfWeek() == 5) || (SAT && DayOfWeek() == 6) || (SUN && DayOfWeek() == 0)) TimeTrade();
}
//+------------------------------------------------------------------+
//| 거래가능 시간 선택 함수(Time Filter) |
//+------------------------------------------------------------------+
void TimeTrade() {
// only allow trading between Start_Time and Finish_Time
int Current_Time = TimeHour(TimeCurrent());
int start_time = GMT_TimeAdjust(Start_Time, Servers_GMT, Locals_GMT);
int finish_time = GMT_TimeAdjust(Finish_Time, Servers_GMT, Locals_GMT);
if (start_time == 0) start_time = 24;
if (finish_time == 0) finish_time = 24;
if (Current_Time == 0) Current_Time = 24;
if ( TimeFilter && start_time < finish_time )
{
if ( (Current_Time < start_time) || (Current_Time >= finish_time) ) EntryEnabled = FALSE;
}
if ( TimeFilter && start_time > Finish_Time )
{
if ( (Current_Time < start_time) && (Current_Time >= finish_time) ) EntryEnabled = FALSE;
}
}
//+------------------------------------------------------------------+
//| Local Time 기준으로 Server Time 환산 함수 |
//+------------------------------------------------------------------+
// HourTime : 변환대상 Local Hour, Server_GMT : Server GMT, Local_GMT : Local GMT
int GMT_TimeAdjust(int HourTime, int Server_GMT, int Local_GMT) {
int AdjustTime = HourTime + Server_GMT - Local_GMT;
if ( AdjustTime == 0 || AdjustTime == 24 ) AdjustTime = 24;
if ( AdjustTime < 0 ) AdjustTime = 24 + AdjustTime;
if ( AdjustTime > 24 ) AdjustTime = AdjustTime-24;
return (AdjustTime);
}
//+------------------------------------------------------------------+
//| Allow One Action Per Bar |
//+------------------------------------------------------------------+
// 현재 바에서 하나만 주문할때 사용하는 함수
bool NewBarBuy()
{ // 0
if(PreviousBarTime1<Time[0])
{ // 1
PreviousBarTime1=Time[0];
return(true);
} // 1
return(false);
} // 0
bool NewBarSell()
{ // 2
if(PreviousBarTime2<Time[0])
{ // 3
PreviousBarTime2=Time[0];
return(true);
} // 3
return(false);
} // 2
/*
bool NewBar()
{ // 4
static datetime lastbar = 0;
if(lastbar!=Time[0])
{ // 5
lastbar=Time[0];
return (true);
} // 5
return(false);
} // 4
*/
//+------------------------------------------------------------------+
//| 주문 함수 (OpenOrder) |
//+------------------------------------------------------------------+
int OpenOrder( string SymbolName, int CmdType, double Lots, int Slippages, double StopLosses, double TakeProfit, int magic)
{ // 함수 시작
static string OrderTypeToString[6] = {"OP_BUY", "OP_SELL", "OP_BUYLIMIT", "OP_SELLLIMIT", "OP_BUYSTOP", "OP_SELLSTOP"};
int Ticket = -1;
int ErrorCodes;
double ask00 = MarketInfo(Symbol(),MODE_ASK);
double bid00 = MarketInfo(Symbol(),MODE_BID);
int Slips = 0;
double Vol = 0;
string Comments;
color CLRs;
RefreshRates();
double stopbuy = NormalizeDouble(ask00-(StopLosses*PointValue(Symbol())*Point),Digits);
double stopsell = NormalizeDouble(bid00+(StopLosses*PointValue(Symbol())*Point),Digits);
double tpbuy = NormalizeDouble(ask00+(TakeProfit*PointValue(Symbol())*Point),Digits);
double tpsell = NormalizeDouble(bid00-(TakeProfit*PointValue(Symbol())*Point),Digits);
if (StopLosses == 0) {
stopbuy = 0;
stopsell = 0;
}
if (TakeProfit == 0) {
tpbuy = 0;
tpsell = 0;
}
if (CmdType == OP_BUY) { // Buy 시작
Comments = "샀어_"+Commentary;
CLRs = Red;
if (ECN == true) { // ECN 시작
Ticket = OrderSend(SymbolName, CmdType, Lots, ask00, Slippages, 0, 0,Comments,magic,0,CLRs);
if(Ticket == -1) { // check for errors
ErrorCodes = GetLastError();
Print("아씨!, Error: " + ErrorDescription(ErrorCodes));
return(-1);
} // check for errors
OrderSelect(Ticket, SELECT_BY_TICKET);
if (!OrderSelect(Ticket, SELECT_BY_TICKET)) { // check for errors
ErrorCodes = GetLastError();
Print("아씨!, Error: " + ErrorDescription(ErrorCodes));
return(-1);
} // check for errors
OrderModify(Ticket,OrderOpenPrice(),stopbuy,tpbuy,0,CLRs);
return(0);
} // ECN 종료
else
{ // ECN 이 아니면
Ticket = OrderSend(SymbolName, CmdType, Lots, ask00, Slippages, stopbuy, tpbuy,Comments,magic,0,CLRs);
if(Ticket == -1) { // check for errors
ErrorCodes = GetLastError();
Print("아씨!, Error: " + ErrorDescription(ErrorCodes));
return(-1);
} // check for errors
return(0);
} // ECN 이 아니면 종료
} // Buy 종료
else
if (CmdType == OP_SELL) { // Sell 시작
Comments = "팔았어_"+Commentary;
CLRs = Blue;
if (ECN == true) { // ECN 시작
Ticket = OrderSend(SymbolName, CmdType, Lots, bid00, Slippages, 0, 0,Comments,magic,0,CLRs);
if(Ticket == -1) { // check for errors
ErrorCodes = GetLastError();
Print("아씨!, Error: " + ErrorDescription(ErrorCodes));
return(-1);
} // check for errors
OrderSelect(Ticket, SELECT_BY_TICKET);
if (!OrderSelect(Ticket, SELECT_BY_TICKET)) { // check for errors
ErrorCodes = GetLastError();
Print("아씨!, Error: " + ErrorDescription(ErrorCodes));
return(-1);
} // check for errors
OrderModify(Ticket,OrderOpenPrice(),stopsell, tpsell,0,CLRs);
return(0);
} // ECN 종료
else
{ // ECN 이 아니면
Ticket = OrderSend(SymbolName, CmdType, Lots, bid00, Slippages, stopsell, tpsell,Comments,magic,0,CLRs);
if(Ticket == -1) { // check for errors
ErrorCodes = GetLastError();
Print("아씨!, Error: " + ErrorDescription(ErrorCodes));
return(-1);
} // check for errors
return(0);
} // ECN 이 아니면 종료
} // Sell 종료
OrderSelect(OrdersTotal() - 1, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == SymbolName)
{
Slips = OrderSlipPage(OrderOpenPrice());
Ticket = OrderTicket();
Vol = OrderLots();
}
Print(Ticket, " = OrderSend( ", Comments,", ", SymbolName, ", ", OrderTypeToString[CmdType], ", ", Lots, ", ", DoubleToStr(OrderOpenPrice(), MarketInfo(SymbolName, MODE_DIGITS)),
", ", Slippages, ", ", StopLosses, ", ", TakeProfit, ") - ", ErrorDescription(ErrorCodes), ", SlipPage = ", Slips, ", Lots = ", Vol);
return(Ticket);
} // 함수 종료
//+------------------------------------------------------------------+
//| Slippage 계산 함수 |
//+------------------------------------------------------------------+
int OrderSlipPage( double OriginalPrice )
{
double Tmp;
int Res;
if (OrderCloseTime() == 0)
{
if (OrderType() == OP_BUY)
Tmp = OriginalPrice - OrderOpenPrice();
else if (OrderType() == OP_SELL)
Tmp = OrderOpenPrice() - OriginalPrice;
}
else
{
if (OrderType() == OP_BUY)
Tmp = OrderClosePrice() - OriginalPrice;
else if (OrderType() == OP_SELL)
Tmp = OriginalPrice - OrderClosePrice();
}
if (Tmp > 0)
Res = Tmp / MarketInfo(OrderSymbol(), MODE_POINT) + 0.1;
else
Res = Tmp / MarketInfo(OrderSymbol(), MODE_POINT) - 0.1;
return(Res);
}
//+------------------------------------------------------------------+
//| Close All By Magic Number |
//+------------------------------------------------------------------+
void CloseAllOpens(int Magic)
{ // 함수 시작
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{ // Loop 시작
OrderSelect(i, SELECT_BY_POS);
int type = OrderType();
bool result = false;
if (OrderMagicNumber() == Magic) {
RefreshRates();
switch(type)
{ // Order Type 검색 및 처리
//Close opened long positions
case OP_BUY : result = OrderClose( OrderTicket(), OrderLots(), NormalizeDouble(MarketInfo(OrderSymbol(), MODE_BID),MarketInfo(OrderSymbol(), MODE_POINT)), slippage, Blue );
break;
//Close opened short positions
case OP_SELL : result = OrderClose( OrderTicket(), OrderLots(), NormalizeDouble(MarketInfo(OrderSymbol(), MODE_ASK),MarketInfo(OrderSymbol(), MODE_POINT)), slippage, Red );
} // Order Type 검색 및 처리 종료
if(result == false)
{ // 에러 처리
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
} // 에러 처리 종료
}
} // Loop 종료
} // 함수 종료
//+------------------------------------------------------------------+
//| Profit Calculate Function(수익 계산 함수) |
//+------------------------------------------------------------------+
double Profit(int Magic)
{ // 0
double Prof=0;
for (int k=0; k < OrdersTotal(); k++)
{ // 1
if (OrderSelect(k, SELECT_BY_POS, MODE_TRADES))
{ // 2
if (OrderMagicNumber()==Magic)
{ // 3
Prof = Prof + OrderProfit();
} // 3
} // 2
} // 1
return(Prof);
} // 0
//+------------------------------------------------------------------+
//| Total order Calculate Function(총오더수 계산 함수) |
//+------------------------------------------------------------------+
double TotalOrders(int MAGIC)
{ // 0
int cnt=0;
for (int i=0; i < OrdersTotal(); i++)
{ // 1
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{ // 2
if (OrderMagicNumber()==MAGIC)
{ // 3
cnt++;
} // 3
} // 2
} // 1
return(cnt);
} // 0
//+------------------------------------------------------------------+
//| 총수익 계산 함수(과거치 포함) |
//+------------------------------------------------------------------+
double HistoryProfit(int Magic)
{ // 0
double Prof=0;
for (int k=0; k < OrdersHistoryTotal(); k++)
{ // 1
if (OrderSelect(k, SELECT_BY_POS, MODE_HISTORY))
{ // 2
if (OrderMagicNumber()==Magic)
{ // 3
Prof = Prof + OrderProfit();
} // 3
} // 2
} // 1
return(Prof);
} // 0
//+------------------------------------------------------------------+
//| 총오더수 계산 함수(과거치 포함) |
//+------------------------------------------------------------------+
double HistoryOrders(int MAGIC)
{ // 0
int cnt=0;
for (int i=0; i < OrdersHistoryTotal(); i++)
{ // 1
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{ // 2
if (OrderMagicNumber()==MAGIC)
{ // 3
cnt++;
} // 3
} // 2
} // 1
return(cnt);
} // 0
/*
//+------------------------------------------------------------------+
//| Total Buy order Calculate Function(총매수 계약 계산 함수) |
//+------------------------------------------------------------------+
int TotalBuyOrders(int MAGIC)
{ // 0
int cnt=0;
for (int i=0; i < OrdersTotal(); i++)
{ // 1
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{ // 2
if ( OrderMagicNumber()==MAGIC && OrderType()==OP_BUY )
{ // 3
cnt++;
} // 3
} // 2
} // 1
return(cnt);
} // 0
//+------------------------------------------------------------------+
//| Total Sell order Calculate Function(총매도 계약 계산 함수) |
//+------------------------------------------------------------------+
int TotalSellOrders(int MAGIC)
{ // 0
int cnt=0;
for (int i=0; i < OrdersTotal(); i++)
{ // 1
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{ // 2
if ( OrderMagicNumber()==MAGIC && OrderType()==OP_SELL )
{ // 3
cnt++;
} // 3
} // 2
} // 1
return(cnt);
} // 0
//+------------------------------------------------------------------+
//| 총매수수익 계산 함수(과거치 포함) |
//+------------------------------------------------------------------+
double HBProfit(int Magic)
{ // 0
double Prof=0;
for (int k=0; k < OrdersHistoryTotal(); k++)
{ // 1
if (OrderSelect(k, SELECT_BY_POS, MODE_HISTORY))
{ // 2
if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType()==OP_BUY)
{ // 3
Prof = Prof + OrderProfit();
} // 3
} // 2
} // 1
return(Prof);
} // 0
//+------------------------------------------------------------------+
//| 총매도수익 계산 함수(과거치 포함) |
//+------------------------------------------------------------------+
double HSProfit(int Magic)
{ // 0
double Prof=0;
for (int k=0; k < OrdersHistoryTotal(); k++)
{ // 1
if (OrderSelect(k, SELECT_BY_POS, MODE_HISTORY))
{ // 2
if (OrderSymbol()==Symbol() && OrderMagicNumber()==Magic && OrderType()==OP_SELL)
{ // 3
Prof = Prof + OrderProfit();
} // 3
} // 2
} // 1
return(Prof);
} // 0
//+------------------------------------------------------------------+
//| 총Buy오더수 계산 함수(과거치 포함) |
//+------------------------------------------------------------------+
int HBuyOrders(int MAGIC)
{ // 0
int cnt=0;
for (int i=0; i < OrdersHistoryTotal(); i++)
{ // 1
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{ // 2
if (OrderMagicNumber()==MAGIC && OrderType()==OP_BUY)
{ // 3
cnt++;
} // 3
} // 2
} // 1
return(cnt);
} // 0
//+------------------------------------------------------------------+
//| 총Sell오더수 계산 함수(과거치 포함) |
//+------------------------------------------------------------------+
int HSellOrders(int MAGIC)
{ // 0
int cnt=0;
for (int i=0; i < OrdersHistoryTotal(); i++)
{ // 1
if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))
{ // 2
if (OrderMagicNumber()==MAGIC && OrderType()==OP_SELL)
{ // 3
cnt++;
} // 3
} // 2
} // 1
return(cnt);
} // 0
//+------------------------------------------------------------------+
//| Symbol Profit Calculate Function(통화당 수익 계산 함수) |
//+------------------------------------------------------------------+
// 매직넘버내의 대상 통화의 수익
double SymbolProfit(int Magic, string Syms)
{ // 0
double Prof=0;
for (int k=0; k < OrdersTotal(); k++)
{ // 1
if (OrderSelect(k, SELECT_BY_POS, MODE_TRADES))
{ // 2
if ( OrderSymbol()==Syms && OrderMagicNumber()==Magic)
{ // 3
Prof = Prof + OrderProfit();
} // 3
} // 2
} // 1
return(Prof);
} // 0
*/
'IT관련' 카테고리의 다른 글
메타트레이더 EA - BaseCurrency_RSI 2. Reverse Version (0) | 2019.09.10 |
---|---|
메타트레이더 EA - BaseCurrency_RSI 1. 기본 버전 (0) | 2019.09.09 |
메타트레이더 EA - USDCHF_Reverse (0) | 2019.09.08 |
메타트레이더 EA 4 (2) | 2019.08.30 |
메타트레이더 EA 3 (0) | 2019.08.30 |