☞ MA, WPR, RSI, CCI, Stochastic, ATR 등의 지표들을 조합하여 Buy, Sell 각각에 대하여 MA, WPR, RSI, Stochastic, CCI조건적용 및 ATR필터를 적용한 후, 5분봉에서 매매하는 EA이다.
Time Frame : M5/M15
Pairs : EURUSD, GBPUSD, USDJPY, EURGBP, AUDUSD, USDCAD 등(브로커별로 확인요망)
Based Indicator : MA, WPR, RSI, CCI, Stochastic, ATR
Start Date : 2012-08-21
Logic : Buy, Sell 각각에 대하여 MA, WPR, RSI, Stochastic, CCI조건적용 및 ATR필터 적용
Attach : M5 Chart
Eas : Trendy + X-Bars + Sigma 통합 EA
Version 0.1
- Day Filter수정
- Money Management 기능추가
- 오류처리 기능강화
- Money Management 기능강화
- 총 매매건수 < MaxTrades
Version 0.2
- MaxTrades 선택 기능 추가
Version 0.3
- 개별EA와의 검증 확인
//******************************************************************************
//| YS_Combination_V0.7 |
//| Copyright @ 2012 Gguri FX LAB |
//******************************************************************************
/*
Time Frame : M5
Pairs : EURUSD, GBPUSD, USDJPY, EURGBP, AUDUSD, USDCAD 등(브로커별로 확인요망)
Based Indicator : MA, WPR, RSI, CCI, Stochastic, ATR
Logic : Buy, Sell 각각에 대하여 MA, WPR, RSI, Stochastic, CCI조건적용 및 ATR필터 적용
Attach : M5 Chart
EAs : YS_KTFC + YS_X-Bars + YS_Yoido 통합 EA
//******************************************************************************
//| Version History |
//******************************************************************************
Version 0.1
- Day Filter수정
- Money Management 기능추가
- 오류처리 기능강화
- Money Management 기능강화
- 총 매매건수 < MaxTrades
Version 0.2
- MaxTrades 선택 기능 추가
Version 0.3
- 개별EA와의 검증 확인
Version 0.4
- Test나 최적화시 부하감소(화면표시 이전 Exit)
- Close정보 화면표시
- Money Management 선택기능추가(0,1,2,3)
Version 0.5
- M5 차트 제한 기능추가(Period Protection)
- 주문시 사운드 사용기능 추가
- 화면표시기능 수정
- Sigma Additional 기능 추가
Version 0.6
- Trendy EA 교체 => KTFC
- Add Filter 추가(KTFC, Sigma)
- 개별 Money Management Filter 추가
Version 0.7
- Sigma EA 교체 => Yoido
- 수익계산에 수수료, Swap 포함
- 승률반영 화면표시
- DataFilter 정보 강화
*/
//******************************************************************************
//| 상수설정 |
//******************************************************************************
#define EA_NAME "YS_Combination_V0.7"
#define Copyrights "Y.S.Park"
#define Create_Date "2012-08-31"
//******************************************************************************
//| Import Library |
//******************************************************************************
#import "stdlib.ex4"
string ErrorDescription(int a0);
//******************************************************************************
//| 공통 변수 설정 |
//******************************************************************************
extern string order_set_string = "Order&Close Settings";
// 주문관련 변수설정
extern bool ECN = TRUE; // ECN Broker 주문처리 가능여부
extern double FixLot=0.1 ; // 진입 랏사이즈 설정
extern double slippage = 3.0; // 슬리피지 허용 변수
string Commentary = EA_NAME; // Entry 주문시 비고
// 일괄청산관련 설정
extern double StopOutBalance = 500; // 모든 거래 종료 잔고 설정
extern bool CloseAllFilter = TRUE; // Close All 가능여부
extern int All_SL = 200; // 1개 이상시 CloseAll StopLoss
extern int All_TP = 100; // 1개 이상시 CloseAll TakeProfit
// Sound 관련
extern bool SoundEnabled1 = TRUE; // Buy 주문시 소리 사용여부
extern bool SoundEnabled2 = TRUE; // Sell 주문시 소리 사용여부
extern bool SoundEnabled3 = TRUE; // Close Buy시 소리 사용여부
extern bool SoundEnabled4 = TRUE; // Close Sell시 소리 사용여부
string sound1 = "st1order.wav"; // Buy 주문시 사용 소리파일
string sound2 = "st2order.wav"; // Sell 주문시 사용 소리파일
string sound3 = "st3order.wav"; // Close Buy 시 사용 소리파일
string sound4 = "st4order.wav"; // Close Sell시 사용 소리파일
extern bool SimpleScreen = TRUE; // 화면표시 단순화
//******************************************************************************
//| 전략1 일반 변수설정(KTFC) |
//******************************************************************************
extern string Strategy1_set = "Strategy1_Order&Close Settings";
extern bool Strategy1 = TRUE; // 전략1 사용여부
extern int XSL1 = 80; // StopLoss
extern int XTP1 = 70; // TakeProfit
extern bool AddFilter1 = TRUE; // Additional Entry 가능여부
extern double AddLotMultiplier1 = 2; // Additional Lot Multiplier
extern int AddLossPip1 = 5; // Additional Entry Loss Pips
string Com1 = "KTFC_Init"; // Entry 주문시 비고
string Com12 = "KTFC_Add"; // Entry 주문시 비고
int magic1, magic12;
// Trailing Stop/Break Even 관련 설정
extern double TrailingStop1 = 7.0; // Trailing Stop 설정시 > 0
extern double TrailingGap1 = 5.0; // Trailing Stop 설정시 가격과의 Gap
extern double BreakEven1 = 5.0; // Break Even 설정시 > 0
extern double BreakPoint1 = 2.0; // Break Even 설정시 손절치(본전 + 손절치)
// Money Management 설정
extern string MM_set_string1 = "MM = 0:FixLot,1:Percent,2:Conservative,3:Aggresive";
extern int DynamicMM1 = 0; // Money Management 설정 0:FixLot,1:Percent,2:Conservative,3:Aggresive
extern double RiskPercent1 = 5.0; // MM = 1일때 0보다 큰 숫자 설정
//******************************************************************************
//| 전략2 일반 변수설정( X-Bars) |
//******************************************************************************
extern string Strategy2_set = "Strategy2_Order&Close Settings";
extern bool Strategy2 = FALSE; // 전략2 사용여부
extern int XSL2 = 60; // StopLoss
extern int XTP2 = 40; // TakeProfit
string Com2 = "X-Bars"; // Entry 주문시 비고
int magic2;
// Trailing Stop/Break Even 관련 설정
extern double TrailingStop2 = 18.0; // Trailing Stop 설정시 > 0
extern double TrailingGap2 = 13.0; // Trailing Stop 설정시 가격과의 Gap
extern double BreakEven2 = 12.0; // Break Even 설정시 > 0
extern double BreakPoint2 = 5.0; // Break Even 설정시 손절치(본전 + 손절치)
// Money Management 설정
extern string MM_set_string2 = "MM = 0:FixLot,1:Percent,2:Conservative,3:Aggresive";
extern int DynamicMM2 = 0; // Money Management 설정 0:FixLot,1:Percent,2:Conservative,3:Aggresive
extern double RiskPercent2 = 5.0; // MM = 1일때 0보다 큰 숫자 설정
//******************************************************************************
//| 전략3 일반 변수설정(Yoido) |
//******************************************************************************
extern string Strategy3_set = "Strategy3_Order&Close Settings";
extern bool Strategy3 = TRUE; // 전략3 사용여부
extern int XSL3 = 120; // StopLoss
extern int XTP3 = 100; // TakeProfit
extern bool AddFilter3 = TRUE; // Additional Entry 가능여부
extern double AddLotMultiplier3 = 2; // Additional Lot Multiplier
extern int AddLossPip3 = 5; // Additional Entry Loss Pips
string Com3 = "Yoido_Init"; // Entry 주문시 비고
string Com31 = "Yoido_Add"; // Entry 주문시 비고
int magic3, magic31;
// Trailing Stop/Break Even 관련 설정
extern double TrailingStop3 = 20.0; // Trailing Stop 설정시 > 0
extern double TrailingGap3 = 15.0; // Trailing Stop 설정시 가격과의 Gap
extern double BreakEven3 = 12.0; // Break Even 설정시 > 0
extern double BreakPoint3 = 3.0; // Break Even 설정시 손절치(본전 + 손절치)
extern bool CloseFilter3 = TRUE; // 청산시 지표사용
// Money Management 설정
extern string MM_set_string3 = "MM = 0:FixLot,1:Percent,2:Conservative,3:Aggresive";
extern int DynamicMM3 = 0; // Money Management 설정 0:FixLot,1:Percent,2:Conservative,3:Aggresive
extern double RiskPercent3 = 5.0; // MM = 1일때 0보다 큰 숫자 설정
//******************************************************************************
//| 제한조건 관련 설정(Max Spread, Max Trades, Day/Time Filter 등) |
//******************************************************************************
extern string limit_set_string = "Limitation Settings";
extern int MaxSpreads = 4; // 최대 허용 Spread(Pip)
extern bool OrderTotalControl = FALSE; // Ture : 총 허용거래수, False : 각 Type별 허용 거래수
extern int MaxTrades = 1; // 최대 허용 거래수
extern int MinBars = 100; // 최소 다운로드 Bar의 수
extern int MoneyEnable = 300; // 최소 거래 가능 금액 설정
extern bool DateFilter = FALSE; // Day Filter설정, False시 Day/Time Filter off
extern bool TimeFilter = TRUE; // Time Filter 설정
extern bool MON = TRUE; // 월요일 거래허용 여부
extern bool TUE = TRUE; // 화요일 거래허용 여부
extern bool WED = TRUE; // 수요일 거래허용 여부
extern bool THU = TRUE; // 목요일 거래허용 여부
extern bool FRI = TRUE; // 금요일 거래허용 여부
extern string timesetting_str = "finish time을 23:59로 하고자 하는 경우 finish time을 25로 설정";
extern int mon_start_time = 9; // 월요일 거래시작시간
extern int mon_finish_time = 25; // 월요일 거래종료시간
extern int tue_start_time = 9; // 화요일 거래시작시간
extern int tue_finish_time = 25; // 화요일 거래종료시간
extern int wed_start_time = 9; // 수요일 거래시작시간
extern int wed_finish_time = 25; // 수요일 거래종료시간
extern int thu_start_time = 9; // 목요일 거래시작시간
extern int thu_finish_time = 25; // 목요일 거래종료시간
extern int fri_start_time = 9; // 금요일 거래시작시간
extern int fri_finish_time = 19; // 금요일 거래종료시간
//******************************************************************************
//| 전략1 Entry Logic 관련 변수 설정(KTFC) |
//******************************************************************************
// KTFC
extern string strat1_entry_string = "Strategy1_Entry Settings";
// Common Condition Parameter
extern int KTFC_TF = 5;
extern int KTFC_Shift = 1;
// ATR Condition Parameter
extern bool ATRFilter = TRUE;
extern int ATR_Period = 18;
extern int ATR_Frontier = 4;
// MA Condition Parameter
extern int MA_Period = 95;
extern int Add_MA = 25;
// WPR Condition Parameter
extern bool WPRFilter = TRUE;
extern int Williams_Period = 21;
extern int WPR_High = 5;
extern int WPR_Low = 95;
// CCI Condition Parameter
extern bool CCIFilter = TRUE;
extern int CCI_Period = 16;
extern int CCI_High = 90;
extern int CCI_Low = -110;
// Stochastic Parameter
extern bool StoFilter = TRUE;
extern int Sto_Period = 11;
extern int StoDperiod = 1;
extern int StoSlowingValue = 1;
extern int Sto_Limit_Value = 5;
//******************************************************************************
//| 전략2 Entry Logic 관련 변수 설정(X-Bars) |
//******************************************************************************
// X-Bars
extern string strat2_entry_string = "Strategy2_Entry Settings";
extern bool StochasticFilter = TRUE;
extern bool RSIFilter2 = TRUE;
extern int MA_TimeFrame = 60;
extern int MA_Period2 = 7;
extern int MA_Mode = 2;
extern int MA_Shift2 = 0;
extern int X_Bars = 15;
extern int RSI_TimeFrame = 5;
extern int RSI_Period = 7;
extern int RSI_Min = 27;
extern int RSI_Max = 69;
extern int Stoch_TimeFrame = 5;
extern int K_Period = 9;
extern int D_Period = 12;
extern int SlowingValue = 18;
extern int StochMinValue = 30;
extern int StochMaxValue = 70;
extern int TimeShifts = 0;
//******************************************************************************
//| 전략3 Entry Logic 관련 변수 설정(Yoido) |
//******************************************************************************
// Yoido(TimeFrame3 = 15, 15분봉 Setting)
extern string strat3_entry_string = "Strategy3_Entry Settings";
extern int TimeFrame3 = 15;
extern int PriceTimeFrame = 1;
extern int ShiftTime3 = 1;
extern int iMA_PeriodLONG = 55;
extern int iMA_ShiftTime = 0;
extern int iMA_LONG_Open_a = 18;
extern int iMA_LONG_Open_b = 39;
extern int iMA_PeriodShort = 55;
extern int iMA_Short_Open_a = 15;
extern int iMA_Short_Open_b = 39;
extern double WPR_1_Open = 70.0;
extern double WPR_5_Open = 60.0;
extern int iCCI_PeriodLONG = 18;
extern int iCCI_PeriodShort = 18;
extern double iCCI_OpenFilter = 150.0;
extern bool ATRFilter3 = TRUE;
int ATR_Buy_Period3 = 14;
int ATR_Sell_Period3 = 14;
int iStoDperiod = 1;
int iStoSlowingValue = 1;
extern int iWPR_PeriodLONG = 11;
extern int iWPR_PeriodShort = 11;
extern int iWPR_LONG_Open_a = 1;
extern int iWPR_LONG_Open_b = 5;
extern int iWPR_Short_Open_a = 1;
extern int iWPR_Short_Open_b = 5;
extern int iWPR_Filter_Close = 90;
extern int FilterATR3 = 6;
extern int Price_Filter_Close = 14;
extern int MinProfit = 5;
//******************************************************************************
//| 기타 내생 변수 설정 |
//******************************************************************************
int mypoint; // 4 digit, 5digit broker에 대한 point 설정변수
string NowSym, StartDay; // EA 시작일 및 심볼 조정변수
int error_code; // 에러코드
datetime S1Time1,S1Time2; // Strategy1 NewBar 시간변수
datetime S12Time1,S12Time2; // Strategy1-2 NewBar 시간변수
datetime S2Time1,S2Time2; // Strategy2 NewBar 시간변수
datetime S3Time1,S3Time2; // Strategy3 NewBar 시간변수
datetime S31Time1,S31Time2; // Strategy3-2 NewBar 시간변수
// MarketInfo 정보를 받는 변수
string broker,servername,mytime,ScreenStr;
double equity,reqmargin,stopout,minlot,maxlot,lotstep;
double accfree,sympoint,ask00,bid00,spread,tickvalue,ticksize;
int leverage,mydigit,stoplevel,freeze;
//******************************************************************************
//| 초기화 |
//******************************************************************************
int init() { // 초기화 시작
// Period Protection
if(Period() != PERIOD_M5) {
Alert("5분봉 차트에 붙이셔야 합니다.");
return(0);
}
// 거래 가능여부 확인
if(IsTradeAllowed()) {
Print("거래 가능합니다!");
}
// 데이타 다운로드 미비에 의한 오류계산 방지 로직
if(!DataFilter()) {
return(0);
}
// Money Management 정확한 설정확인
if((DynamicMM1 == 1 && RiskPercent1 == 0) || (DynamicMM2 == 1 && RiskPercent2 == 0) || (DynamicMM3 == 1 && RiskPercent3 == 0)) {
Alert("RiskPercent값을 0 이상으로 설정하세요.");
return(0);
}
if(DynamicMM1 > 3 || DynamicMM2 > 3 || DynamicMM3 > 3) {
Alert("DynamicMM값을 3 이하값으로 설정하세요.");
return(0);
}
// 전략1,2,3 사용가능 체크
if(!Strategy1 && !Strategy2 && !Strategy3) {
Alert("적어도 하나의 전략은 사용가능해야 합니다.");
return(0);
}
// EA 시작일 설정
StartDay = TimeToStr(TimeCurrent(),TIME_DATE);
// 통화별 매직넘버 가져오기
getmagic();
magic12 = magic1+500;
magic2 = magic1+1000;
magic3 = magic2+1000;
magic31 = magic3+500;
// 5 digit broker adjustment
if(MarketInfo(Symbol(), MODE_DIGITS)==3 || MarketInfo(Symbol(), MODE_DIGITS)==5) {
mypoint = 10;
}
else
{
mypoint = 1;
}
} // 초기화 종료
//******************************************************************************
//| 종료시 설정 |
//******************************************************************************
int deinit() {
return(0);
}
//******************************************************************************
//| EA Start |
//******************************************************************************
int start() { // EA 시작
//******************************************************************************
// Error 검출후 메세지 출력
// Server와 연결이 안된 경우
if(!IsConnected()) {
Print("연결해주세요!");
return(0);
}
// EA 거래를 막아놓은 경우
if(!IsTesting()) {
if(!IsDllsAllowed() || !IsExpertEnabled()) {
Print("DLL 사용할 수 있게 옵션에서 풀어주세요. 혹은 EA아이콘 확인요망!");
return(0);
}
}
//******************************************************************************
// MarketInfo 정보를 받는 변수 설정
broker = AccountCompany();
servername = AccountServer();
mytime = TimeToStr(TimeCurrent(),TIME_SECONDS);
equity = AccountEquity();
leverage = AccountLeverage();
reqmargin = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
accfree = NormalizeDouble(AccountFreeMargin(),2);
ask00 = MarketInfo(Symbol(),MODE_ASK);
bid00 = MarketInfo(Symbol(),MODE_BID);
stoplevel = MarketInfo(Symbol(), MODE_STOPLEVEL);
freeze = MarketInfo(Symbol(), MODE_FREEZELEVEL);
stopout = AccountStopoutLevel();
mydigit = MarketInfo(Symbol(), MODE_DIGITS);
sympoint = MarketInfo(Symbol(),MODE_POINT);
minlot = MarketInfo(Symbol(), MODE_MINLOT);
maxlot = MarketInfo(Symbol(), MODE_MAXLOT);
lotstep = MarketInfo(Symbol(), MODE_LOTSTEP);
spread = NormalizeDouble(ask00-bid00,mydigit);
tickvalue = MarketInfo(Symbol(), MODE_TICKVALUE);
ticksize = MarketInfo(Symbol(), MODE_TICKSIZE);
//******************************************************************************
// StopOut Balance도달시 강제청산함수 가져오기
StopOutClose();
//******************************************************************************
// Trailing Stop / Break Even 함수 가져오기
if(TrailingStop1>0) MoveTrailingStop(magic1,TrailingStop1,TrailingGap1);
if(BreakEven1>0) MoveBreakEven(magic1,BreakEven1,BreakPoint1);
if(TrailingStop1>0) MoveTrailingStop(magic12,TrailingStop1,TrailingGap1);
if(BreakEven1>0) MoveBreakEven(magic12,BreakEven1,BreakPoint1);
if(TrailingStop2>0) MoveTrailingStop(magic2,TrailingStop2,TrailingGap2);
if(BreakEven2>0) MoveBreakEven(magic2,BreakEven2,BreakPoint2);
if(TrailingStop3>0) MoveTrailingStop(magic3,TrailingStop3,TrailingGap3);
if(BreakEven3>0) MoveBreakEven(magic3,BreakEven3,BreakPoint3);
if(TrailingStop3>0) MoveTrailingStop(magic31,TrailingStop3,TrailingGap3);
if(BreakEven3>0) MoveBreakEven(magic31,BreakEven3,BreakPoint3);
//******************************************************************************
//| Date/Time Filter |
//******************************************************************************
// Day/Time Filter충족여부 검토
bool DateEnabled = FALSE;
if (DayFilter()) DateEnabled = TRUE;
else DateEnabled = FALSE;
//******************************************************************************
// Spread 조건 충족여부 검토
bool SpreadEnabled = FALSE;
if (TradeEnable()==FALSE) {
Print ("아! Spread가 너무 쎄!ㅠㅠ..");
SpreadEnabled = FALSE;
}
else SpreadEnabled = TRUE;
//******************************************************************************
// 잔고가 일정액 이하인 경우 EA 진입금지
bool EnoughMoney = TRUE;
if(accfree<MoneyEnable) {
Print("돈이 없어. 현잔고 = ", accfree);
EnoughMoney = FALSE;
}
else EnoughMoney = TRUE;
//******************************************************************************
// Spread조건 및 Day/Time Filter충족여부 검토
bool EntryEnabled = FALSE;
if (DateEnabled && SpreadEnabled && EnoughMoney) EntryEnabled = TRUE;
else EntryEnabled = FALSE;
//******************************************************************************
//| Strategy1 Buy / Sell Condition(KTFC) |
//******************************************************************************
bool EntryCondBuy = FALSE;
bool EntryCondSell = FALSE;
bool CommonCon1 = FALSE;
bool BuyCon1 = FALSE;
bool BuyCon2 = FALSE;
bool BuyCon3 = FALSE;
bool BuyCon4 = FALSE;
bool SellCon1 = FALSE;
bool SellCon2 = FALSE;
bool SellCon3 = FALSE;
bool SellCon4 = FALSE;
double LastClose = iClose(NULL, KTFC_TF, KTFC_Shift);
double MA_Cond = iMA(NULL, KTFC_TF, MA_Period, 0, MODE_SMMA, PRICE_CLOSE, KTFC_Shift);
double WPR_Cond = iWPR(NULL, KTFC_TF, Williams_Period, KTFC_Shift);
double ATR_Cond = iATR(NULL, KTFC_TF, ATR_Period, KTFC_Shift);
double CCI_Cond = iCCI(NULL, KTFC_TF, CCI_Period, PRICE_TYPICAL, KTFC_Shift);
double Stochastic_Cond = iStochastic(NULL, KTFC_TF, Sto_Period, StoDperiod, StoSlowingValue, MODE_SMA, 0, MODE_MAIN, KTFC_Shift);
int Sto_Limit_Reverse = 100 - Sto_Limit_Value;
// Common Condition
if (ATRFilter == FALSE || (ATRFilter && ATR_Cond > ATR_Frontier*mypoint*sympoint)) CommonCon1 =TRUE;
else CommonCon1 = FALSE;
// Buy Condition
if (LastClose > (MA_Cond + Add_MA*mypoint*sympoint)) BuyCon1 = TRUE;
else BuyCon1 = FALSE;
if (WPRFilter == FALSE || (WPRFilter && WPR_Cond < (-1 * WPR_Low))) BuyCon2 = TRUE;
else BuyCon2 = FALSE;
if (CCIFilter == FALSE || (CCIFilter && CCI_Cond < CCI_Low)) BuyCon3 = TRUE;
else BuyCon3 = FALSE;
if (StoFilter == FALSE || (StoFilter && Sto_Limit_Value > Stochastic_Cond)) BuyCon4 = TRUE;
else BuyCon4 = FALSE;
// Sell Condition
if (LastClose < (MA_Cond - Add_MA*mypoint*sympoint)) SellCon1 = TRUE;
else SellCon1 = FALSE;
if (WPRFilter == FALSE || (WPRFilter && WPR_Cond > (-1 * WPR_High))) SellCon2 = TRUE;
else SellCon2 = FALSE;
if (CCIFilter == FALSE || (CCIFilter && CCI_Cond > CCI_High)) SellCon3 = TRUE;
else SellCon3 = FALSE;
if (StoFilter == FALSE || (StoFilter && Sto_Limit_Reverse < Stochastic_Cond)) SellCon4 = TRUE;
else SellCon4 = FALSE;
if(CommonCon1 && BuyCon1 && BuyCon2 && BuyCon3 && BuyCon4) EntryCondBuy = TRUE;
else EntryCondBuy = FALSE;
if(CommonCon1 && SellCon1 && SellCon2 && SellCon3 && SellCon4) EntryCondSell = TRUE;
else EntryCondSell = FALSE;
//******************************************************************************
//| Order 주문처리 Logic |
//******************************************************************************
bool Entry_1 = FALSE;
int ticketbuy1, ticketsell1;
if(EntryEnabled && Strategy1) Entry_1 = TRUE;
else Entry_1 = FALSE;
bool S1NewBarBuy = FALSE;
bool S1NewBarSell = FALSE;
if(S1Time1 < Time[0]) { // 1
S1Time1 = Time[0];
S1NewBarBuy = TRUE;
} // 1
else S1NewBarBuy = FALSE;
if(S1Time2 < Time[0]) { // 1
S1Time2 = Time[0];
S1NewBarSell = TRUE;
} // 1
else S1NewBarSell = FALSE;
//******************************************************************************
// Strategy 1 Order Processing
double orderlots = NormalizeDouble(MoneyManagement(DynamicMM1,RiskPercent1),2);
// Buy Order
if(OrderTotalControl) {
if(Entry_1 && TotalOrders(magic1) < MaxTrades && S1NewBarBuy) {
if(EntryCondBuy) {
ticketbuy1 = OpenOrder(Symbol(),OP_BUY,orderlots,slippage,XSL1,XTP1,Com1,magic1);
}
}
}
else
if(!OrderTotalControl) {
if(Entry_1 && TotalBuyOrders(magic1) < MaxTrades && S1NewBarBuy) {
if(EntryCondBuy) {
ticketbuy1 = OpenOrder(Symbol(),OP_BUY,orderlots,slippage,XSL1,XTP1,Com1,magic1);
}
}
}
// Sell Order
if(OrderTotalControl) {
if(Entry_1 && TotalOrders(magic1) < MaxTrades && S1NewBarSell) {
if(EntryCondSell) {
ticketsell1 = OpenOrder(Symbol(),OP_SELL,orderlots,slippage,XSL1,XTP1,Com1,magic1);
}
}
}
else
if(!OrderTotalControl) {
if(Entry_1 && TotalSellOrders(magic1) < MaxTrades && S1NewBarSell) {
if(EntryCondSell) {
ticketsell1 = OpenOrder(Symbol(),OP_SELL,orderlots,slippage,XSL1,XTP1,Com1,magic1);
}
}
}
//******************************************************************************
//| Strategy 1-2 Buy/Sell Condition Function |
//******************************************************************************
//******************************************************************************
// Buy/Sell Additional
bool Buy12Con = FALSE;
bool Sell12Con = FALSE;
if ( TotalBuyOrders(magic1)>0 && EntryCondBuy && ask00 < FindLastBuyPrice(magic1) - AddLossPip1 * mypoint * sympoint ) Buy12Con = TRUE;
else Buy12Con = FALSE;
if ( TotalSellOrders(magic1)>0 && EntryCondSell && bid00 > FindLastSellPrice(magic1) + AddLossPip1 * mypoint * sympoint ) Sell12Con = TRUE;
else Sell12Con = FALSE;
//******************************************************************************
// Strategy 1-2 Order
bool S12NewBarBuy = FALSE;
bool S12NewBarSell = FALSE;
if(S12Time1 < Time[0]) { // 1
S12Time1 = Time[0];
S12NewBarBuy = TRUE;
} // 1
else S12NewBarBuy = FALSE;
if(S12Time2 < Time[0]) { // 1
S12Time2 = Time[0];
S12NewBarSell = TRUE;
} // 1
else S12NewBarSell = FALSE;
//******************************************************************************
// Strategy 1-2 Order Processing
double orderlot12 = NormalizeDouble(MoneyManagement(DynamicMM1,RiskPercent1)*AddLotMultiplier1,2);
int ticketbuy12, ticketsell12;
// Buy Order
if(OrderTotalControl) {
if(Entry_1 && AddFilter1 && TotalOrders(magic12) < MaxTrades && S12NewBarBuy) {
if(Buy12Con) {
ticketbuy12 = OpenOrder(Symbol(),OP_BUY,orderlot12,slippage,XSL1,XTP1,Com12,magic12);
}
}
}
else
if(!OrderTotalControl) {
if(Entry_1 && AddFilter1 && TotalBuyOrders(magic12) < MaxTrades && S12NewBarBuy) {
if(Buy12Con) {
ticketbuy12 = OpenOrder(Symbol(),OP_BUY,orderlot12,slippage,XSL1,XTP1,Com12,magic12);
}
}
}
// Sell Order
if(OrderTotalControl) {
if(Entry_1 && AddFilter1 && TotalOrders(magic12) < MaxTrades && S12NewBarSell) {
if(Sell12Con) {
ticketsell12 = OpenOrder(Symbol(),OP_SELL,orderlot12,slippage,XSL1,XTP1,Com12,magic12);
}
}
}
else
if(!OrderTotalControl) {
if(Entry_1 && AddFilter1 && TotalSellOrders(magic12) < MaxTrades && S12NewBarSell) {
if(Sell12Con) {
ticketsell12 = OpenOrder(Symbol(),OP_SELL,orderlot12,slippage,XSL1,XTP1,Com12,magic12);
}
}
}
//******************************************************************************
//| Strategy 2 Buy/Sell Condition Function (X-Bars) |
//******************************************************************************
//******************************************************************************
// Buy Condition
double MA_2Condition = iMA(NULL, MA_TimeFrame, MA_Period2, MA_Shift2, MA_Mode, PRICE_CLOSE, TimeShifts);
int BuyConMA_XBars = 0;
int TotalParameter;
for (TotalParameter = 1; TotalParameter <= X_Bars; TotalParameter++) {
if (MA_2Condition >= iMA(NULL, MA_TimeFrame, MA_Period2, MA_Shift2, MA_Mode, PRICE_CLOSE, TotalParameter))
if (MA_2Condition > iMA(NULL, MA_TimeFrame, MA_Period2, MA_Shift2, MA_Mode, PRICE_CLOSE, TotalParameter)) BuyConMA_XBars++;
}
double RSI_2Con = iRSI(NULL, RSI_TimeFrame, RSI_Period, PRICE_CLOSE, TimeShifts);
double Stochastic_2Con = iStochastic(NULL, Stoch_TimeFrame, K_Period, D_Period, SlowingValue, MODE_SMA, 0, MODE_MAIN, TimeShifts);
bool Buy2Con = FALSE;
bool Buy2Con1 = FALSE;
bool Buy2Con2 = FALSE;
bool Buy2Con3 = FALSE;
if(BuyConMA_XBars == X_Bars) Buy2Con1 = TRUE;
else Buy2Con1 = FALSE;
if(RSIFilter2 == FALSE || (RSIFilter2 && RSI_2Con <= RSI_Min)) Buy2Con2 = TRUE;
else Buy2Con2 = FALSE;
if(StochasticFilter == FALSE || (StochasticFilter && Stochastic_2Con <= StochMinValue)) Buy2Con3 = TRUE;
else Buy2Con3 = FALSE;
if( Buy2Con1 && Buy2Con2 && Buy2Con3 ) Buy2Con = TRUE;
else Buy2Con = FALSE;
//******************************************************************************
// Sell Condition
bool Sell2Con = FALSE;
bool Sell2Con1 = FALSE;
bool Sell2Con2 = FALSE;
bool Sell2Con3 = FALSE;
int SellConMA_XBars = 0;
int TotalParameters;
for (TotalParameters = 1; TotalParameters <= X_Bars; TotalParameters++) {
if (MA_2Condition <= iMA(NULL, MA_TimeFrame, MA_Period2, MA_Shift2, MA_Mode, PRICE_CLOSE, TotalParameters))
if (MA_2Condition < iMA(NULL, MA_TimeFrame, MA_Period2, MA_Shift2, MA_Mode, PRICE_CLOSE, TotalParameters)) SellConMA_XBars++;
}
if(SellConMA_XBars == X_Bars) Sell2Con1 = TRUE;
else Sell2Con1 = FALSE;
if(RSIFilter2 == FALSE || (RSIFilter2 && RSI_2Con >= RSI_Max)) Sell2Con2 = TRUE;
else Sell2Con2 = FALSE;
if(StochasticFilter == FALSE || (StochasticFilter && Stochastic_2Con >= StochMaxValue)) Sell2Con3 = TRUE;
else Sell2Con3 = FALSE;
if( Sell2Con1 && Sell2Con2 && Sell2Con3 ) Sell2Con = TRUE;
else Sell2Con = FALSE;
//******************************************************************************
// Strategy 2 Order
bool Entry_2 = FALSE;
int ticketbuy2, ticketsell2;
if(EntryEnabled && Strategy2) Entry_2 = TRUE;
else Entry_2 = FALSE;
bool S2NewBarBuy = FALSE;
bool S2NewBarSell = FALSE;
if(S2Time1 < Time[0]) { // 1
S2Time1 = Time[0];
S2NewBarBuy = TRUE;
} // 1
else S2NewBarBuy = FALSE;
if(S2Time2 < Time[0]) { // 1
S2Time2 = Time[0];
S2NewBarSell = TRUE;
} // 1
else S2NewBarSell = FALSE;
//******************************************************************************
// Strategy 2 Order Processing
double orderlot2 = NormalizeDouble(MoneyManagement(DynamicMM2,RiskPercent2),2);
// Buy Order
if(OrderTotalControl) {
if(Entry_2 && TotalOrders(magic2) < MaxTrades && S2NewBarBuy) {
if(Buy2Con) {
ticketbuy2 = OpenOrder(Symbol(),OP_BUY,orderlot2,slippage,XSL2,XTP2,Com2,magic2);
}
}
}
else
if(!OrderTotalControl) {
if(Entry_2 && TotalBuyOrders(magic2) < MaxTrades && S2NewBarBuy) {
if(Buy2Con) {
ticketbuy2 = OpenOrder(Symbol(),OP_BUY,orderlot2,slippage,XSL2,XTP2,Com2,magic2);
}
}
}
// Sell Order
if(OrderTotalControl) {
if(Entry_2 && TotalOrders(magic2) < MaxTrades && S2NewBarSell) {
if(Sell2Con) {
ticketsell2 = OpenOrder(Symbol(),OP_SELL,orderlot2,slippage,XSL2,XTP2,Com2,magic2);
}
}
}
else
if(!OrderTotalControl) {
if(Entry_2 && TotalSellOrders(magic2) < MaxTrades && S2NewBarSell) {
if(Sell2Con) {
ticketsell2 = OpenOrder(Symbol(),OP_SELL,orderlot2,slippage,XSL2,XTP2,Com2,magic2);
}
}
}
//******************************************************************************
//| Strategy 3 Buy/Sell Condition Function(Yoido) |
//******************************************************************************
//******************************************************************************
// Buy Condition
bool Buy3Con = FALSE;
bool BuyCon01 = FALSE;
bool BuyCon02 = FALSE;
bool BuyCon03 = FALSE;
bool BuyCon04 = FALSE;
bool BuyCon05 = FALSE;
double Base3Close = iClose(NULL, TimeFrame3, ShiftTime3);
double MA_Buy_3Condition = iMA(NULL, TimeFrame3, iMA_PeriodLONG, iMA_ShiftTime, MODE_SMMA, PRICE_HIGH, ShiftTime3);
double Stochastic_Buy_3Condition = iStochastic(NULL, TimeFrame3, iWPR_PeriodLONG, iStoDperiod, iStoSlowingValue, MODE_SMA, 0, MODE_MAIN, ShiftTime3);
double CCI_Buy_3Condition = iCCI(NULL, TimeFrame3, iCCI_PeriodLONG, PRICE_TYPICAL, ShiftTime3);
double ATR_Buy_3Condition = iATR(NULL, TimeFrame3, ATR_Buy_Period3, ShiftTime3);
double WPR_1_Long = iWPR(NULL,1,iWPR_PeriodLONG,0);
double WPR_5_Long = iWPR(NULL,5,iWPR_PeriodLONG,0);
double CCI_1_Long = iCCI(NULL,1,iCCI_PeriodLONG,PRICE_CLOSE,0);
double CCI_5_Long = iCCI(NULL,5,iCCI_PeriodLONG,PRICE_CLOSE,0);
double iMA_Buy01 = NormalizeDouble(iMA_LONG_Open_a*mypoint*sympoint, mydigit);
double iMA_Buy02 = NormalizeDouble(iMA_LONG_Open_b*mypoint*sympoint, mydigit);
if (ATRFilter3 && ATR_Buy_3Condition <= FilterATR3 * mypoint * sympoint) return (0);
if (WPR_1_Long < -WPR_1_Open && WPR_5_Long < -WPR_5_Open) BuyCon01 = TRUE;
else BuyCon01 = FALSE;
if (CCI_1_Long < -iCCI_OpenFilter && CCI_5_Long < -iCCI_OpenFilter) BuyCon02 = TRUE;
else BuyCon02 = FALSE;
if (Base3Close - MA_Buy_3Condition > iMA_Buy01 && Base3Close - bid00 >= (-mypoint * sympoint) && iWPR_LONG_Open_a > Stochastic_Buy_3Condition) BuyCon03 = TRUE;
else BuyCon03 = FALSE;
if (Base3Close - MA_Buy_3Condition > iMA_Buy02 && Base3Close - bid00 >= (-mypoint * sympoint) && (-iCCI_OpenFilter) > CCI_Buy_3Condition) BuyCon04 = TRUE;
else BuyCon04 = FALSE;
if (Base3Close - MA_Buy_3Condition > iMA_Buy02 && Base3Close - bid00 >= (-mypoint * sympoint) && iWPR_LONG_Open_b > Stochastic_Buy_3Condition) BuyCon05 = TRUE;
else BuyCon05 = FALSE;
if (BuyCon01 || BuyCon02 && (BuyCon03 || BuyCon04 || BuyCon05)) Buy3Con = TRUE;
else Buy3Con = FALSE;
//******************************************************************************
// Sell Condition
bool Sell3Con = FALSE;
bool SellCon01 = FALSE;
bool SellCon02 = FALSE;
bool SellCon03 = FALSE;
bool SellCon04 = FALSE;
bool SellCon05 = FALSE;
double BaseClose = iClose(NULL, TimeFrame3, ShiftTime3);
double MA_Sell_3Condition = iMA(NULL, TimeFrame3, iMA_PeriodShort, iMA_ShiftTime, MODE_SMMA, PRICE_LOW, ShiftTime3);
double Stochastic_Sell_3Condition = iStochastic(NULL, TimeFrame3, iWPR_PeriodShort, iStoDperiod, iStoSlowingValue, MODE_SMA, 0, MODE_MAIN, ShiftTime3);
double CCI_Sell_3Condition = iCCI(NULL, TimeFrame3, iCCI_PeriodShort, PRICE_TYPICAL, ShiftTime3);
double ATR_Sell_3Condition = iATR(NULL, TimeFrame3, ATR_Sell_Period3, ShiftTime3);
double WPR_1_Short = iWPR(NULL,1,iWPR_PeriodShort,0);
double WPR_5_Short = iWPR(NULL,5,iWPR_PeriodShort,0);
double CCI_1_Short = iCCI(NULL,1,iCCI_PeriodShort,PRICE_CLOSE,0);
double CCI_5_Short = iCCI(NULL,5,iCCI_PeriodShort,PRICE_CLOSE,0);
double iMA_Sell01 = NormalizeDouble(iMA_Short_Open_a*mypoint*sympoint, mydigit);
double iMA_Sell02 = NormalizeDouble(iMA_Short_Open_b*mypoint*sympoint, mydigit);
int iWPR_Short_ReverseA = 100 - iWPR_Short_Open_a;
int iWPR_Short_ReverseB = 100 - iWPR_Short_Open_b;
if (ATRFilter3 && ATR_Sell_3Condition <= FilterATR3 * mypoint * sympoint) return (0);
if (MA_Sell_3Condition - BaseClose > iMA_Sell01 && BaseClose - bid00 <= (mypoint * sympoint) && Stochastic_Sell_3Condition > iWPR_Short_ReverseA) SellCon01 = TRUE;
else SellCon01 = FALSE;
if (MA_Sell_3Condition - BaseClose > iMA_Sell02 && BaseClose - bid00 <= (mypoint * sympoint) && CCI_Sell_3Condition > iCCI_OpenFilter) SellCon02 = TRUE;
else SellCon02 = FALSE;
if (MA_Sell_3Condition - BaseClose > iMA_Sell02 && BaseClose - bid00 <= (mypoint * sympoint) && Stochastic_Sell_3Condition > iWPR_Short_ReverseB) SellCon03 = TRUE;
else SellCon03 = FALSE;
if (WPR_1_Short > -(100-WPR_1_Open) && WPR_5_Short > -(100-WPR_5_Open)) SellCon04 = TRUE;
else SellCon04 = FALSE;
if (CCI_1_Short > iCCI_OpenFilter && CCI_5_Short > iCCI_OpenFilter) SellCon05 = TRUE;
else SellCon05 = FALSE;
if (SellCon04 || SellCon05 && (SellCon01 || SellCon02 || SellCon03)) Sell3Con = TRUE;
else Sell3Con = FALSE;
//******************************************************************************
// Strategy 3 Order
bool Entry_3 = FALSE;
int ticketbuy3, ticketsell3;
if(EntryEnabled && Strategy3) Entry_3 = TRUE;
else Entry_3 = FALSE;
bool S3NewBarBuy = FALSE;
bool S3NewBarSell = FALSE;
if(S3Time1 < Time[0]) { // 1
S3Time1 = Time[0];
S3NewBarBuy = TRUE;
} // 1
else S3NewBarBuy = FALSE;
if(S3Time2 < Time[0]) { // 1
S3Time2 = Time[0];
S3NewBarSell = TRUE;
} // 1
else S3NewBarSell = FALSE;
//******************************************************************************
// Strategy 3 Order Processing
double orderlot3 = NormalizeDouble(MoneyManagement(DynamicMM3,RiskPercent3),2);
// Buy Order
if(OrderTotalControl) {
if(Entry_3 && TotalOrders(magic3) < MaxTrades && S3NewBarBuy) {
if(Buy3Con) {
ticketbuy3 = OpenOrder(Symbol(),OP_BUY,orderlot3,slippage,XSL3,XTP3,Com3,magic3);
}
}
}
else
if(!OrderTotalControl) {
if(Entry_3 && TotalBuyOrders(magic3) < MaxTrades && S3NewBarBuy) {
if(Buy3Con) {
ticketbuy3 = OpenOrder(Symbol(),OP_BUY,orderlot3,slippage,XSL3,XTP3,Com3,magic3);
}
}
}
// Sell Order
if(OrderTotalControl) {
if(Entry_3 && TotalOrders(magic3) < MaxTrades && S3NewBarSell) {
if(Sell3Con) {
ticketsell3 = OpenOrder(Symbol(),OP_SELL,orderlot3,slippage,XSL3,XTP3,Com3,magic3);
}
}
}
else
if(!OrderTotalControl) {
if(Entry_3 && TotalSellOrders(magic3) < MaxTrades && S3NewBarSell) {
if(Sell3Con) {
ticketsell3 = OpenOrder(Symbol(),OP_SELL,orderlot3,slippage,XSL3,XTP3,Com3,magic3);
}
}
}
//******************************************************************************
//| Strategy 3-2 Buy/Sell Condition Function |
//******************************************************************************
//******************************************************************************
// Buy/Sell Additional
bool Buy31Con = FALSE;
bool Sell31Con = FALSE;
if ( TotalBuyOrders(magic3)>0 && Buy3Con && ask00 < FindLastBuyPrice(magic3) - AddLossPip3 * mypoint * sympoint ) Buy31Con = TRUE;
else Buy31Con = FALSE;
if ( TotalSellOrders(magic3)>0 && Sell3Con && bid00 > FindLastSellPrice(magic3) + AddLossPip3 * mypoint * sympoint ) Sell31Con = TRUE;
else Sell31Con = FALSE;
//******************************************************************************
// Strategy 3-2 Order
bool S31NewBarBuy = FALSE;
bool S31NewBarSell = FALSE;
if(S31Time1 < Time[0]) { // 1
S31Time1 = Time[0];
S31NewBarBuy = TRUE;
} // 1
else S31NewBarBuy = FALSE;
if(S31Time2 < Time[0]) { // 1
S31Time2 = Time[0];
S31NewBarSell = TRUE;
} // 1
else S31NewBarSell = FALSE;
//******************************************************************************
// Strategy 3-2 Order Processing
double orderlot31 = NormalizeDouble(MoneyManagement(DynamicMM3,RiskPercent3)*AddLotMultiplier3,2);
int ticketbuy31, ticketsell31;
// Buy Order
if(OrderTotalControl) {
if(Entry_3 && AddFilter3 && TotalOrders(magic31) < MaxTrades && S31NewBarBuy) {
if(Buy31Con) {
ticketbuy31 = OpenOrder(Symbol(),OP_BUY,orderlot31,slippage,XSL3,XTP3,Com31,magic31);
}
}
}
else
if(!OrderTotalControl) {
if(Entry_3 && AddFilter3 && TotalBuyOrders(magic31) < MaxTrades && S31NewBarBuy) {
if(Buy31Con) {
ticketbuy31 = OpenOrder(Symbol(),OP_BUY,orderlot31,slippage,XSL3,XTP3,Com31,magic31);
}
}
}
// Sell Order
if(OrderTotalControl) {
if(Entry_3 && AddFilter3 && TotalOrders(magic31) < MaxTrades && S31NewBarSell) {
if(Sell31Con) {
ticketsell31 = OpenOrder(Symbol(),OP_SELL,orderlot31,slippage,XSL3,XTP3,Com31,magic31);
}
}
}
else
if(!OrderTotalControl) {
if(Entry_3 && AddFilter3 && TotalSellOrders(magic31) < MaxTrades && S31NewBarSell) {
if(Sell31Con) {
ticketsell31 = OpenOrder(Symbol(),OP_SELL,orderlot31,slippage,XSL3,XTP3,Com31,magic31);
}
}
}
//******************************************************************************
//| Strategy 3 Close Condition Function |
//******************************************************************************
//******************************************************************************
// CloseBuy Condition
bool CloseBuy = FALSE;
bool CloseBuyCon01 = FALSE;
bool CloseBuyCon02 = FALSE;
bool CBC3_1_1 = FALSE;
bool CBC3_1_2 = FALSE;
bool CBC3_1_3 = FALSE;
bool CBC3_2_1 = FALSE;
bool CBC3_2_2 = FALSE;
//******************************************************************************
double Stochastic_CloseBuyCondition = iStochastic(NULL, TimeFrame3, iWPR_PeriodLONG, iStoDperiod, iStoSlowingValue, MODE_SMA, 0, MODE_SIGNAL, ShiftTime3);
double Close_BaseClose = iClose(NULL, TimeFrame3, ShiftTime3);
double Close_NowOpen = iOpen(NULL, PriceTimeFrame, ShiftTime3);
double Close_NowClose = iClose(NULL, PriceTimeFrame, ShiftTime3);
double StopPoint = NormalizeDouble(MinProfit * mypoint * sympoint, mydigit);
double ClosePricePoint = NormalizeDouble(Price_Filter_Close*mypoint*sympoint, mydigit);
//******************************************************************************
if(FindLastBuyPrice(magic3) - bid00 <= StopPoint) CBC3_1_1 = TRUE;
else CBC3_1_1 = FALSE;
if( Close_BaseClose - bid00 <= (mypoint*sympoint) ) CBC3_1_2 = TRUE;
else CBC3_1_2 = FALSE;
if(Stochastic_CloseBuyCondition > iWPR_Filter_Close) CBC3_1_3 = TRUE;
else CBC3_1_3 = FALSE;
if (CBC3_1_1 && CBC3_1_2 && CBC3_1_3 ) CloseBuyCon01 = TRUE;
else CloseBuyCon01 = FALSE;
//******************************************************************************
if(Close_NowOpen > Close_NowClose) CBC3_2_1 = TRUE;
else CBC3_2_1 = FALSE;
if( bid00 - FindLastBuyPrice(magic3) >= ClosePricePoint ) CBC3_2_2 = TRUE;
else CBC3_2_2 = FALSE;
if (CBC3_2_1 && CBC3_2_2 ) CloseBuyCon02 = TRUE;
else CloseBuyCon02 = FALSE;
//******************************************************************************
if (CloseBuyCon01 || CloseBuyCon02) CloseBuy = TRUE;
else CloseBuy = FALSE;
//******************************************************************************
// CloseSell Condition
bool CloseSell = FALSE;
bool CloseSellCon01 = FALSE;
bool CloseSellCon02 = FALSE;
bool CSC3_1_1 = FALSE;
bool CSC3_1_2 = FALSE;
bool CSC3_1_3 = FALSE;
bool CSC3_2_1 = FALSE;
bool CSC3_2_2 = FALSE;
//******************************************************************************
double Stochastic_CloseSellCondition = iStochastic(NULL, TimeFrame3, iWPR_PeriodShort, iStoDperiod, iStoSlowingValue, MODE_SMA, 0, MODE_SIGNAL, ShiftTime3);
int WPR_Reverse = 100 - iWPR_Filter_Close;
//******************************************************************************
if(ask00 - FindLastSellPrice(magic3) <= StopPoint) CSC3_1_1 = TRUE;
else CSC3_1_1 = FALSE;
if(Close_BaseClose - bid00 >= (-mypoint*sympoint)) CSC3_1_2 = TRUE;
else CSC3_1_2 = FALSE;
if(Stochastic_CloseSellCondition < WPR_Reverse) CSC3_1_3 = TRUE;
else CSC3_1_3 = FALSE;
if (CSC3_1_1 && CSC3_1_2 && CSC3_1_3) CloseSellCon01 = TRUE;
else CloseSellCon01 = FALSE;
//******************************************************************************
if(Close_NowOpen < Close_NowClose) CSC3_2_1 = TRUE;
else CSC3_2_1 = FALSE;
if(FindLastSellPrice(magic3) - ask00 >= ClosePricePoint) CSC3_2_2 = TRUE;
else CSC3_2_2 = FALSE;
if (CSC3_2_1 && CSC3_2_2) CloseSellCon02 = TRUE;
else CloseSellCon02 = FALSE;
if (CloseSellCon01 || CloseSellCon02) CloseSell = TRUE;
else CloseSell = FALSE;
//******************************************************************************
// 지표사용시 Close 조건 충족시 청산(전략3 해당)
if(CloseFilter3 && TotalBuyOrders(magic3)>0) {
if(CloseBuy) {
CloseBuyOpens(magic3);
}
}
if(CloseFilter3 && TotalSellOrders(magic3)>0) {
if(CloseSell) {
CloseSellOpens(magic3);
}
}
//******************************************************************************
//| Strategy 3-2 Close Condition Function |
//******************************************************************************
//******************************************************************************
// CloseBuy Condition
bool CloseBuy31 = FALSE;
bool CloseBuyCon31 = FALSE;
bool CloseBuyCon32 = FALSE;
bool CBC31_1_1 = FALSE;
bool CBC31_2_1 = FALSE;
//******************************************************************************
if(FindLastBuyPrice(magic31) - bid00 <= StopPoint) CBC31_1_1 = TRUE;
else CBC31_1_1 = FALSE;
if (CBC31_1_1 && CBC3_1_2 && CBC3_1_3 ) CloseBuyCon31 = TRUE;
else CloseBuyCon31 = FALSE;
//******************************************************************************
if( bid00 - FindLastBuyPrice(magic31) >= ClosePricePoint ) CBC31_2_1 = TRUE;
else CBC31_2_1 = FALSE;
if (CBC3_2_1 && CBC31_2_1) CloseBuyCon32 = TRUE;
else CloseBuyCon32 = FALSE;
//******************************************************************************
if (CloseBuyCon31 || CloseBuyCon32) CloseBuy31 = TRUE;
else CloseBuy31 = FALSE;
//******************************************************************************
// CloseSell Condition
//******************************************************************************
bool CloseSell31 = FALSE;
bool CloseSellCon31 = FALSE;
bool CloseSellCon32 = FALSE;
bool CSC31_1_1 = FALSE;
bool CSC31_2_1 = FALSE;
if(ask00 - FindLastSellPrice(magic31) <= StopPoint) CSC31_1_1 = TRUE;
else CSC31_1_1 = FALSE;
if (CSC31_1_1 && CSC3_1_2 && CSC3_1_3) CloseSellCon31 = TRUE;
else CloseSellCon31 = FALSE;
if(FindLastSellPrice(magic31) - ask00 >= ClosePricePoint) CSC31_2_1 = TRUE;
else CSC31_2_1 = FALSE;
if (CSC3_2_1 && CSC31_2_1) CloseSellCon32 = TRUE;
else CloseSellCon32 = FALSE;
if (CloseSellCon31 || CloseSellCon32) CloseSell31 = TRUE;
else CloseSell31 = FALSE;
//******************************************************************************
//| Close 3-2 Function |
//******************************************************************************
//******************************************************************************
// 지표사용시 Close 조건 충족시 청산(전략3-2 해당)
if(CloseFilter3 && TotalBuyOrders(magic31)>0) {
if(CloseBuy31) {
CloseBuyOpens(magic31);
}
}
if(CloseFilter3 && TotalSellOrders(magic31)>0) {
if(CloseSell31) {
CloseSellOpens(magic31);
}
}
//******************************************************************************
//| Close All Function |
//******************************************************************************
//******************************************************************************
// 전체수익이나 손실이 설정치 이상인 경우 Close All
double profits = Profit(magic1)+Profit(magic12)+Profit(magic2)+Profit(magic3)+Profit(magic31);
double TlLots = TotalLot(magic1)+TotalLot(magic12)+TotalLot(magic2)+TotalLot(magic3)+TotalLot(magic31);
// Close All TP, SL을 Lot수에 따라 조정
double All_SLs = NormalizeDouble(All_SL*(TlLots/FixLot),0);
double All_TPs = NormalizeDouble(All_TP*(TlLots/FixLot),0);
if((TotalOrders(magic1)+TotalOrders(magic12)+TotalOrders(magic2)+TotalOrders(magic3)+TotalOrders(magic31) > 2) && CloseAllFilter && (profits>All_TPs || profits<-All_SLs)) {
if(TotalBuyOrders(magic1)>0) CloseBuyOpens(magic1);
if(TotalSellOrders(magic1)>0) CloseSellOpens(magic1);
if(TotalBuyOrders(magic12)>0) CloseBuyOpens(magic12);
if(TotalSellOrders(magic12)>0) CloseSellOpens(magic12);
if(TotalBuyOrders(magic2)>0) CloseBuyOpens(magic2);
if(TotalSellOrders(magic2)>0) CloseSellOpens(magic2);
if(TotalBuyOrders(magic3)>0) CloseBuyOpens(magic3);
if(TotalSellOrders(magic3)>0) CloseSellOpens(magic3);
if(TotalBuyOrders(magic31)>0) CloseBuyOpens(magic31);
if(TotalSellOrders(magic31)>0) CloseSellOpens(magic31);
}
//******************************************************************************
//| 화면표시 함수 |
//******************************************************************************
// 화면표시 함수처리에 시간이 많이 걸려 BackTest나 최적화작업시 시간이 많이 걸리므로 이 작업시 이전에 Exit
if(IsTesting()) return(0);
// 화면표시 변수 정의
double hprofit = HistoryProfit(magic1)+HistoryProfit(magic12)+HistoryProfit(magic2)+HistoryProfit(magic3)+HistoryProfit(magic31);
int orders = TotalOrders(magic1)+TotalOrders(magic12)+TotalOrders(magic2)+TotalOrders(magic3)+TotalOrders(magic31);
int borders = TotalBuyOrders(magic1)+TotalBuyOrders(magic12)+TotalBuyOrders(magic2)+TotalBuyOrders(magic3)+TotalBuyOrders(magic31);
int sorders = TotalSellOrders(magic1)+TotalSellOrders(magic12)+TotalSellOrders(magic2)+TotalSellOrders(magic3)+TotalSellOrders(magic31);
int hborders = HBuyOrders(magic1)+HBuyOrders(magic12)+HBuyOrders(magic2)+HBuyOrders(magic3)+HBuyOrders(magic31);
int hsorders = HSellOrders(magic1)+HSellOrders(magic12)+HSellOrders(magic2)+HSellOrders(magic3)+HSellOrders(magic31);
int horders = hborders+hsorders;
int hwborders = HWBuyOrders(magic1)+HWBuyOrders(magic12)+HWBuyOrders(magic2)+HWBuyOrders(magic3)+HWBuyOrders(magic31);
int hwsorders = HWSellOrders(magic1)+HWSellOrders(magic12)+HWSellOrders(magic2)+HWSellOrders(magic3)+HWSellOrders(magic31);
int hworders = hwborders+hwsorders;
double bprofits = BProfit(magic1)+BProfit(magic12)+BProfit(magic2)+BProfit(magic3)+BProfit(magic31);
double sprofits = SProfit(magic1)+SProfit(magic12)+SProfit(magic2)+SProfit(magic3)+SProfit(magic31);
double hbprofit = HBProfit(magic1)+HBProfit(magic12)+HBProfit(magic2)+HBProfit(magic3)+HBProfit(magic31);
double hsprofit = HSProfit(magic1)+HSProfit(magic12)+HSProfit(magic2)+HSProfit(magic3)+HSProfit(magic31);
double HTLots = HTotalLot(magic1)+HTotalLot(magic12)+HTotalLot(magic2)+HTotalLot(magic3)+HTotalLot(magic31);
string symbolpoint = DoubleToStr(sympoint,Digits);
string strspread = DoubleToStr(spread,Digits);
string maxspread = DoubleToStr(MaxSpreads*mypoint*sympoint,Digits);
if(SimpleScreen) {
ScreenStr = StringConcatenate("EA Name : ",EA_NAME," , Copyright : ",Copyrights," , EA제작일_",Create_Date," , 현재시간 : ",mytime," 평가잔액 = $",equity," Leverage_",leverage,":1, 1Lot당 필요증거금 : $",reqmargin)+"\n";
ScreenStr = ScreenStr + StringConcatenate("Broker : ",broker," Server : ",servername," EA시작일_",StartDay," Next Order Lot_",orderlots," StopLevel_",stoplevel," Freeze Level_",freeze," Stop Out_",stopout,"%, Digit_",mydigit,", Entry_", EntryEnabled)+"\n";
ScreenStr = ScreenStr + StringConcatenate("Account Free Margin_",accfree," TickValue_",DoubleToStr(tickvalue,Digits),", TickSize_",DoubleToStr(ticksize,Digits),", Point_",symbolpoint," Min Lot_",minlot," Max Lot_",maxlot," Lot Step_",lotstep," Max Spread_",maxspread," Spread_",strspread)+"\n";
ScreenStr = ScreenStr + "===========================================================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("Filters : MM1_",DynamicMM1,", ", RiskPercent1,"%, MM2_",DynamicMM2,", ",RiskPercent2,"%, MM3_",DynamicMM3,", ",RiskPercent3) + "\n";
ScreenStr = ScreenStr + StringConcatenate("Close All Filter_",CloseAllFilter,", CloseAll_TP_",All_TPs,", CloseAll_SL_",All_SLs,", Date Filter_",DateFilter," , Time Filter_",TimeFilter,", Close Filter3_",CloseFilter3," Data_",DataFilter()) + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략별 Filter : 전략1_",Strategy1,", 전략2_",Strategy2,", 전략3_",Strategy3)+"\n";
if(Strategy1) {
ScreenStr = ScreenStr + "***** 전략 1 KTFC(And) On "+"Magic Number "+magic1+" ******************" + "\n";
ScreenStr = ScreenStr + StringConcatenate("MM_Lot_",orderlots," TP_",XTP1," SL_",XSL1," Trailing_", TrailingStop1,", Gap_",TrailingGap1,", Break Even_",BreakEven1,", Break Point_",BreakPoint1)+"\n";
ScreenStr = ScreenStr + StringConcatenate("Buy Condition : ",BuyCon1," And ",BuyCon2," And ",BuyCon3," And ",BuyCon4," And ",CommonCon1)+"\n";
ScreenStr = ScreenStr + StringConcatenate("Sell Condition : ",SellCon1," And ",SellCon2," And ",SellCon3," And ",SellCon4," And ",CommonCon1)+"\n";
}
else
{
ScreenStr = ScreenStr + "***** 전략 1 KTFC(And) Off "+"Magic Number "+magic1+" ******************" + "\n";
}
if(Strategy2) {
ScreenStr = ScreenStr + "***** 전략 2 X-Bars(And) On "+"Magic Number "+magic2+" ******************" + "\n";
ScreenStr = ScreenStr + StringConcatenate("MM_Lot_",orderlot2," TP_",XTP2," SL_",XSL2," Trailing_", TrailingStop2,", Gap_",TrailingGap2,", Break Even_",BreakEven2,", Break Point_",BreakPoint2)+"\n";
ScreenStr = ScreenStr + StringConcatenate("Buy Condition : ",Buy2Con1," And ",Buy2Con2," And ",Buy2Con3)+"\n";
ScreenStr = ScreenStr + StringConcatenate("Sell Condition : ",Sell2Con1," And ",Sell2Con2," And ",Sell2Con3)+"\n";
}
else
{
ScreenStr = ScreenStr + "***** 전략 2 X-Bars(And) Off "+"Magic Number "+magic2+" ******************" + "\n";
}
if(Strategy3) {
ScreenStr = ScreenStr + "***** 전략 3 Yoido(Or) On "+"Magic Number "+magic3+" *********************" + "\n";
ScreenStr = ScreenStr + StringConcatenate("MM_Lot_",orderlot3," TP_",XTP3," SL_",XSL3," Trailing_", TrailingStop3,", Gap_",TrailingGap3,", Break Even_",BreakEven3,", Break Point_",BreakPoint3)+"\n";
ScreenStr = ScreenStr + StringConcatenate("ATR_Buy/Sell_Filter : 필터사용_",ATRFilter3,", 조건_",ATR_Buy_3Condition," > ",FilterATR3*mypoint*sympoint) + "\n";
ScreenStr = ScreenStr + StringConcatenate("Buy Condition : (",BuyCon01," Or ",BuyCon02,") And (",BuyCon03," Or ",BuyCon04," Or ",BuyCon05,")")+"\n";
ScreenStr = ScreenStr + StringConcatenate("Sell Condition : (",SellCon04," Or ",SellCon05,") And (",SellCon01," Or ",SellCon02," Or ",SellCon03,")")+"\n";
}
else
{
ScreenStr = ScreenStr + "***** 전략 3 Yoido(Or) Off "+"Magic Number "+magic3+" *********************" + "\n";
}
ScreenStr = ScreenStr + "================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략1 : ",Profit(magic1),", New Orders : ",TotalLot(magic1),"Lot_",TotalOrders(magic1),"건 = Buy $",BProfit(magic1),"_",TotalBuyOrders(magic1),"건 / Sell $",SProfit(magic1),"_",TotalSellOrders(magic1),"건") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략1-2 : ",Profit(magic12),", New Orders : ",TotalLot(magic12),"Lot_",TotalOrders(magic12),"건 = Buy $",BProfit(magic12),"_",TotalBuyOrders(magic12),"건 / Sell $",SProfit(magic12),"_",TotalSellOrders(magic12),"건") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략2 : ",Profit(magic2),", New Orders : ",TotalLot(magic2),"Lot_",TotalOrders(magic2),"건 = Buy $",BProfit(magic2),"_",TotalBuyOrders(magic2),"건 / Sell $",SProfit(magic2),"_",TotalSellOrders(magic2),"건") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략3 : ",Profit(magic3),", New Orders : ",TotalLot(magic3),"Lot_",TotalOrders(magic3),"건 = Buy $",BProfit(magic3),"_",TotalBuyOrders(magic3),"건 / Sell $",SProfit(magic3),"_",TotalSellOrders(magic3),"건") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략3-2 : ",Profit(magic31),", New Orders : ",TotalLot(magic31),"Lot_",TotalOrders(magic31),"건 = Buy $",BProfit(magic31),"_",TotalBuyOrders(magic31),"건 / Sell $",SProfit(magic31),"_",TotalSellOrders(magic31),"건") + "\n";
ScreenStr = ScreenStr + "================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("총현재오더 : ",profits,", New Orders : ",TlLots,"Lot_",orders,"건 = Buy $",bprofits,"_",borders,"건 / Sell $",sprofits,"_",sorders,"건") + "\n";
ScreenStr = ScreenStr + "==========================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략1 과거 : ",HistoryProfit(magic1),", New Orders : ",HTotalLot(magic1),"Lot_",HWBuyOrders(magic1)+HWSellOrders(magic1),"/",HOrders(magic1),"건 = Buy $",HBProfit(magic1),"_",HWBuyOrders(magic1),"/",HBuyOrders(magic1),"건 / Sell $",HSProfit(magic1),"_",HWSellOrders(magic1),"/",HSellOrders(magic1),"건, 승률_",NormalizeDouble(((HWBuyOrders(magic1)+HWSellOrders(magic1))/HOrders(magic1))*100,1),"%") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략1-2 과거 : ",HistoryProfit(magic12),", New Orders : ",HTotalLot(magic12),"Lot_",HWBuyOrders(magic12)+HWSellOrders(magic12),"/",HOrders(magic12),"건 = Buy $",HBProfit(magic12),"_",HWBuyOrders(magic12),"/",HBuyOrders(magic12),"건 / Sell $",HSProfit(magic12),"_",HWSellOrders(magic12),"/",HSellOrders(magic12),"건, 승률_",NormalizeDouble(((HWBuyOrders(magic12)+HWSellOrders(magic12))/HOrders(magic12))*100,1),"%") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략2 과거 : ",HistoryProfit(magic2),", New Orders : ",HTotalLot(magic2),"Lot_",HWBuyOrders(magic2)+HWSellOrders(magic2),"/",HOrders(magic2),"건 = Buy $",HBProfit(magic2),"_",HWBuyOrders(magic2),"/",HBuyOrders(magic2),"건 / Sell $",HSProfit(magic2),"_",HWSellOrders(magic2),"/",HSellOrders(magic2),"건, 승률_",NormalizeDouble(((HWBuyOrders(magic2)+HWSellOrders(magic2))/HOrders(magic2))*100,1),"%") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략3 과거 : ",HistoryProfit(magic3),", New Orders : ",HTotalLot(magic3),"Lot_",HWBuyOrders(magic3)+HWSellOrders(magic3),"/",HOrders(magic3),"건 = Buy $",HBProfit(magic3),"_",HWBuyOrders(magic3),"/",HBuyOrders(magic3),"건 / Sell $",HSProfit(magic3),"_",HWSellOrders(magic3),"/",HSellOrders(magic3),"건, 승률_",NormalizeDouble(((HWBuyOrders(magic3)+HWSellOrders(magic3))/HOrders(magic3))*100,1),"%") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략3-2 과거 : ",HistoryProfit(magic31),", New Orders : ",HTotalLot(magic31),"Lot_",HWBuyOrders(magic31)+HWSellOrders(magic31),"/",HOrders(magic31),"건 = Buy $",HBProfit(magic31),"_",HWBuyOrders(magic31),"/",HBuyOrders(magic31),"건 / Sell $",HSProfit(magic31),"_",HWSellOrders(magic31),"/",HSellOrders(magic31),"건, 승률_",NormalizeDouble(((HWBuyOrders(magic31)+HWSellOrders(magic31))/HOrders(magic31))*100,1),"%") + "\n";
ScreenStr = ScreenStr + "==========================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("Total Profits(과거) : $",hprofit,", Buy : $",hbprofit,", Sell : $",hsprofit,", Total Orders : ",HTLots,"Lot_",hwborders+hwsorders,"/",horders,"건 = Total Buy ",hwborders,"/",hborders,"건 / Total Sell",hwsorders,hsorders,"건, 승률_",NormalizeDouble(((hwborders+hwsorders)/horders)*100,1),"%");
Comment(ScreenStr);
}
else
{
ScreenStr = StringConcatenate("EA Name : ",EA_NAME," , Copyright : ",Copyrights," , EA제작일_",Create_Date," , 현재시간 : ",mytime," 평가잔액 = $",equity," Leverage_",leverage,":1, 1Lot당 필요증거금 : $",reqmargin)+"\n";
ScreenStr = ScreenStr + StringConcatenate("Broker : ",broker," Server : ",servername," EA시작일_",StartDay," Next Order Lot_",orderlots," StopLevel_",stoplevel," Freeze Level_",freeze," Stop Out_",stopout,"%, Digit_",mydigit,", Entry_", EntryEnabled)+"\n";
ScreenStr = ScreenStr + StringConcatenate("Account Free Margin_",accfree," TickValue_",DoubleToStr(tickvalue,Digits),", TickSize_",DoubleToStr(ticksize,Digits),", Point_",symbolpoint," Min Lot_",minlot," Max Lot_",maxlot," Lot Step_",lotstep," Max Spread_",maxspread," Spread_",strspread)+"\n";
ScreenStr = ScreenStr + "===========================================================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("Filters : MM1_",DynamicMM1,", ", RiskPercent1,"%, MM2_",DynamicMM2,", ",RiskPercent2,"%, MM3_",DynamicMM3,", ",RiskPercent3) + "\n";
ScreenStr = ScreenStr + StringConcatenate("Close All Filter_",CloseAllFilter,", CloseAll_TP_",All_TPs,", CloseAll_SL_",All_SLs,", Date Filter_",DateFilter," , Time Filter_",TimeFilter,", Close Filter3_",CloseFilter3," Data_",DataFilter()) + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략별 Filter : 전략1_",Strategy1,", 전략2_",Strategy2,", 전략3_",Strategy3)+"\n";
if(Strategy1) {
ScreenStr = ScreenStr + "***** 전략 1 KTFC(And) On "+"Magic Number "+magic1+" ******************" + "\n";
ScreenStr = ScreenStr + StringConcatenate("MM_Lot_",orderlots," TP_",XTP1," SL_",XSL1," Trailing_", TrailingStop1,", Gap_",TrailingGap1,", Break Even_",BreakEven1,", Break Point_",BreakPoint1)+"\n";
ScreenStr = ScreenStr + StringConcatenate(CommonCon1," ATR Filter_",ATRFilter,", Condition ", ATR_Cond," > ",ATR_Frontier*mypoint*sympoint)+"\n";
ScreenStr = ScreenStr + StringConcatenate(BuyCon1," Buy 1 : ",LastClose," > ",MA_Cond + Add_MA*mypoint*sympoint)+"\n";
ScreenStr = ScreenStr + StringConcatenate(BuyCon2," Buy 2 : WPR Filter_",WPRFilter,", Condition ", WPR_Cond," < ",(-1 * WPR_Low))+"\n";
ScreenStr = ScreenStr + StringConcatenate(BuyCon3," Buy 3 : CCI Filter_",CCIFilter,", Condition ", CCI_Cond," < ",CCI_Low)+"\n";
ScreenStr = ScreenStr + StringConcatenate(BuyCon4," Buy 4 : Stochastic Filter_",StoFilter,", Condition ", Sto_Limit_Value," > ",Stochastic_Cond)+"\n";
ScreenStr = ScreenStr + "==============================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate(SellCon1," Sell 1 : ",LastClose," < ",MA_Cond + Add_MA*mypoint*sympoint)+"\n";
ScreenStr = ScreenStr + StringConcatenate(SellCon2," Sell 2 : WPR Filter_",WPRFilter,", Condition ", WPR_Cond," > ",(-1 * WPR_High))+"\n";
ScreenStr = ScreenStr + StringConcatenate(SellCon3," Sell 3 : CCI Filter_",CCIFilter,", Condition ", CCI_Cond," > ",CCI_High)+"\n";
ScreenStr = ScreenStr + StringConcatenate(SellCon4," Sell 4 : Stochastic Filter_",StoFilter,", Condition ", Sto_Limit_Reverse," < ",Stochastic_Cond)+"\n";
}
else
{
ScreenStr = ScreenStr + "***** 전략 1 KTFC(And) Off "+"Magic Number "+magic1+" ******************" + "\n";
}
if(Strategy2) {
ScreenStr = ScreenStr + "***** 전략 2 X-Bars(And) On "+"Magic Number "+magic2+" ******************" + "\n";
ScreenStr = ScreenStr + StringConcatenate("MM_Lot_",orderlot2," TP_",XTP2," SL_",XSL2," Trailing_", TrailingStop2,", Gap_",TrailingGap2,", Break Even_",BreakEven2,", Break Point_",BreakPoint2)+"\n";
ScreenStr = ScreenStr + StringConcatenate(Buy2Con1,"_Buy_XBars = X_Bars_",BuyConMA_XBars," = ",X_Bars)+"\n";
ScreenStr = ScreenStr + StringConcatenate(Buy2Con2,"_Buy RSI_Filter : 필터사용_",RSIFilter2,", 조건_",RSI_2Con," <= ",RSI_Min) + "\n";
ScreenStr = ScreenStr + StringConcatenate(Buy2Con3,"_Buy Stochastic_Filter : 필터사용_",StochasticFilter,", 조건_",Stochastic_2Con," <= ",StochMinValue) + "\n";
ScreenStr = ScreenStr + "===============================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate(Sell2Con1,"_Sell_XBars = X_Bars_",SellConMA_XBars," = ",X_Bars)+"\n";
ScreenStr = ScreenStr + StringConcatenate(Sell2Con2,"_Sell RSI_Filter : 필터사용_",RSIFilter2,", 조건_",RSI_2Con," >= ",RSI_Max) + "\n";
ScreenStr = ScreenStr + StringConcatenate(Sell2Con3,"_Sell Stochastic_Filter : 필터사용_",StochasticFilter,", 조건_",Stochastic_2Con," >= ",StochMaxValue) + "\n";
}
else
{
ScreenStr = ScreenStr + "***** 전략 2 X-Bars(And) Off "+"Magic Number "+magic2+" ******************" + "\n";
}
if(Strategy3) {
ScreenStr = ScreenStr + "***** 전략 3 Yoido(Or) On "+"Magic Number "+magic3+" *********************" + "\n";
ScreenStr = ScreenStr + StringConcatenate("MM_Lot_",orderlot3," TP_",XTP3," SL_",XSL3," Trailing_", TrailingStop3,", Gap_",TrailingGap3,", Break Even_",BreakEven3,", Break Point_",BreakPoint3)+"\n";
ScreenStr = ScreenStr + StringConcatenate("ATR_Buy/Sell_Filter : 필터사용_",ATRFilter3,", 조건_",ATR_Buy_3Condition," > ",FilterATR3*mypoint*sympoint) + "\n";
ScreenStr = ScreenStr + StringConcatenate(BuyCon01," Buy 3-1 : (1) ",WPR_1_Long," < ",-WPR_1_Open,", (2) ",WPR_5_Long," < ",-WPR_5_Open)+"\n";
ScreenStr = ScreenStr + StringConcatenate(BuyCon02," Buy 3-2 : (1) ",CCI_1_Long," < ",-iCCI_OpenFilter,", (2) ",CCI_5_Long," < ",-iCCI_OpenFilter)+"\n";
ScreenStr = ScreenStr + StringConcatenate(BuyCon03," Buy 3-3 : (1) ",Base3Close - MA_Buy_3Condition," > ",iMA_Buy01,", (2) ",Base3Close - bid00," >= ",(-mypoint * sympoint),", (3) ",iWPR_LONG_Open_a," > ",Stochastic_Buy_3Condition)+"\n";
ScreenStr = ScreenStr + StringConcatenate(BuyCon04," Buy 3-4 : (1) ",Base3Close - MA_Buy_3Condition," > ",iMA_Buy02,", (2) ",Base3Close - bid00," >= ",(-mypoint * sympoint),", (3) ",(-iCCI_OpenFilter)," > ",CCI_Buy_3Condition)+"\n";
ScreenStr = ScreenStr + StringConcatenate(BuyCon05," Buy 3-5 : (1) ",Base3Close - MA_Buy_3Condition," > ",iMA_Buy02,", (2) ",Base3Close - bid00," >= ",(-mypoint * sympoint),", (3) ",iWPR_LONG_Open_b," > ",Stochastic_Buy_3Condition)+"\n";
ScreenStr = ScreenStr + "================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate(SellCon04," Sell 3-1 : (1) ",WPR_1_Short," > ",-(100-WPR_1_Open),", (2) ",WPR_5_Short," > ",-(100-WPR_5_Open))+"\n";
ScreenStr = ScreenStr + StringConcatenate(SellCon05," Sell 3-2 : (1) ",CCI_1_Short," > ",iCCI_OpenFilter,", (2) ",CCI_5_Short," > ",iCCI_OpenFilter)+"\n";
ScreenStr = ScreenStr + StringConcatenate(SellCon01," Sell 3-3 : (1) ",MA_Sell_3Condition - BaseClose," > ",iMA_Sell01,", (2) ",BaseClose - bid00," <= ",(mypoint * sympoint),", (3) ",Stochastic_Sell_3Condition," > ",iWPR_Short_ReverseA)+"\n";
ScreenStr = ScreenStr + StringConcatenate(SellCon02," Sell 3-4 : (1) ",MA_Sell_3Condition - BaseClose," > ",iMA_Sell02,", (2) ",BaseClose - bid00," <= ",(mypoint * sympoint),", (3) ",CCI_Sell_3Condition," > ",iCCI_OpenFilter)+"\n";
ScreenStr = ScreenStr + StringConcatenate(SellCon03," Sell 3-5 : (1) ",MA_Sell_3Condition - BaseClose," > ",iMA_Sell02,", (2) ",BaseClose - bid00," <= ",(mypoint * sympoint),", (3) ",Stochastic_Sell_3Condition," > ",iWPR_Short_ReverseB)+"\n";
ScreenStr = ScreenStr + "================================================================" + "\n";
ScreenStr = ScreenStr + "***** 전략 3 청산조건 Yoido(Or) *********************" + "\n";
ScreenStr = ScreenStr + StringConcatenate("Close_Buy 1-1_",CloseBuyCon01,", Close_Buy 1-2_",CloseBuyCon02,", Close_Sell 1-1_",CloseSellCon01,", Close_Sell 1-2_",CloseSellCon02) + "\n";
ScreenStr = ScreenStr + StringConcatenate("Close_Buy 1-1_",CBC3_1_1,", Close_Buy 1-2_",CBC3_1_2,", Close_Buy 1-3_",CBC3_1_3,", Close_Buy 2-1_",CBC3_2_1,", Close_Buy 2-2_",CBC3_2_2) + "\n";
ScreenStr = ScreenStr + StringConcatenate("Close_Sell 1-1_",CSC3_1_1,", Close_Sell 1-2_",CSC3_1_2,", Close_Sell 1-3_",CSC3_1_3,", Close_Sell 2-1_",CSC3_2_1,", Close_Sell 2-2_",CSC3_2_2) + "\n";
ScreenStr = ScreenStr + StringConcatenate("Close_Buy 2-1_",CloseBuyCon31,", Close_Buy 2-2_",CloseBuyCon32,", Close_Sell 2-1_",CloseSellCon31,", Close_Sell 2-2_",CloseSellCon32) + "\n";
ScreenStr = ScreenStr + StringConcatenate("Close_Buy 1-1_",CBC31_1_1,", Close_Buy 1-2_",CBC3_1_2,", Close_Buy 1-3_",CBC3_1_3,", Close_Buy 2-1_",CBC3_2_1,", Close_Buy 2-2_",CBC31_2_1) + "\n";
ScreenStr = ScreenStr + StringConcatenate("Close_Sell 1-1_",CSC31_1_1,", Close_Sell 1-2_",CSC3_1_2,", Close_Sell 1-3_",CSC3_1_3,", Close_Sell 2-1_",CSC3_2_1,", Close_Sell 2-2_",CSC31_2_1) + "\n";
}
else
{
ScreenStr = ScreenStr + "***** 전략 3 Yoido(Or) Off "+"Magic Number "+magic3+" *********************" + "\n";
}
ScreenStr = ScreenStr + "================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략1 : ",Profit(magic1),", New Orders : ",TotalLot(magic1),"Lot_",TotalOrders(magic1),"건 = Buy $",BProfit(magic1),"_",TotalBuyOrders(magic1),"건 / Sell $",SProfit(magic1),"_",TotalSellOrders(magic1),"건") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략1-2 : ",Profit(magic12),", New Orders : ",TotalLot(magic12),"Lot_",TotalOrders(magic12),"건 = Buy $",BProfit(magic12),"_",TotalBuyOrders(magic12),"건 / Sell $",SProfit(magic12),"_",TotalSellOrders(magic12),"건") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략2 : ",Profit(magic2),", New Orders : ",TotalLot(magic2),"Lot_",TotalOrders(magic2),"건 = Buy $",BProfit(magic2),"_",TotalBuyOrders(magic2),"건 / Sell $",SProfit(magic2),"_",TotalSellOrders(magic2),"건") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략3 : ",Profit(magic3),", New Orders : ",TotalLot(magic3),"Lot_",TotalOrders(magic3),"건 = Buy $",BProfit(magic3),"_",TotalBuyOrders(magic3),"건 / Sell $",SProfit(magic3),"_",TotalSellOrders(magic3),"건") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략3-2 : ",Profit(magic31),", New Orders : ",TotalLot(magic31),"Lot_",TotalOrders(magic31),"건 = Buy $",BProfit(magic31),"_",TotalBuyOrders(magic31),"건 / Sell $",SProfit(magic31),"_",TotalSellOrders(magic31),"건") + "\n";
ScreenStr = ScreenStr + "================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("총현재오더 : ",profits,", New Orders : ",TlLots,"Lot_",orders,"건 = Buy $",bprofits,"_",borders,"건 / Sell $",sprofits,"_",sorders,"건") + "\n";
ScreenStr = ScreenStr + "==========================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략1 과거 : ",HistoryProfit(magic1),", New Orders : ",HTotalLot(magic1),"Lot_",HWBuyOrders(magic1)+HWSellOrders(magic1),"/",HOrders(magic1),"건 = Buy $",HBProfit(magic1),"_",HWBuyOrders(magic1),"/",HBuyOrders(magic1),"건 / Sell $",HSProfit(magic1),"_",HWSellOrders(magic1),"/",HSellOrders(magic1),"건, 승률_",NormalizeDouble(((HWBuyOrders(magic1)+HWSellOrders(magic1))/HOrders(magic1))*100,1),"%") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략1-2 과거 : ",HistoryProfit(magic12),", New Orders : ",HTotalLot(magic12),"Lot_",HWBuyOrders(magic12)+HWSellOrders(magic12),"/",HOrders(magic12),"건 = Buy $",HBProfit(magic12),"_",HWBuyOrders(magic12),"/",HBuyOrders(magic12),"건 / Sell $",HSProfit(magic12),"_",HWSellOrders(magic12),"/",HSellOrders(magic12),"건, 승률_",NormalizeDouble(((HWBuyOrders(magic12)+HWSellOrders(magic12))/HOrders(magic12))*100,1),"%") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략2 과거 : ",HistoryProfit(magic2),", New Orders : ",HTotalLot(magic2),"Lot_",HWBuyOrders(magic2)+HWSellOrders(magic2),"/",HOrders(magic2),"건 = Buy $",HBProfit(magic2),"_",HWBuyOrders(magic2),"/",HBuyOrders(magic2),"건 / Sell $",HSProfit(magic2),"_",HWSellOrders(magic2),"/",HSellOrders(magic2),"건, 승률_",NormalizeDouble(((HWBuyOrders(magic2)+HWSellOrders(magic2))/HOrders(magic2))*100,1),"%") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략3 과거 : ",HistoryProfit(magic3),", New Orders : ",HTotalLot(magic3),"Lot_",HWBuyOrders(magic3)+HWSellOrders(magic3),"/",HOrders(magic3),"건 = Buy $",HBProfit(magic3),"_",HWBuyOrders(magic3),"/",HBuyOrders(magic3),"건 / Sell $",HSProfit(magic3),"_",HWSellOrders(magic3),"/",HSellOrders(magic3),"건, 승률_",NormalizeDouble(((HWBuyOrders(magic3)+HWSellOrders(magic3))/HOrders(magic3))*100,1),"%") + "\n";
ScreenStr = ScreenStr + StringConcatenate("전략3-2 과거 : ",HistoryProfit(magic31),", New Orders : ",HTotalLot(magic31),"Lot_",HWBuyOrders(magic31)+HWSellOrders(magic31),"/",HOrders(magic31),"건 = Buy $",HBProfit(magic31),"_",HWBuyOrders(magic31),"/",HBuyOrders(magic31),"건 / Sell $",HSProfit(magic31),"_",HWSellOrders(magic31),"/",HSellOrders(magic31),"건, 승률_",NormalizeDouble(((HWBuyOrders(magic31)+HWSellOrders(magic31))/HOrders(magic31))*100,1),"%") + "\n";
ScreenStr = ScreenStr + "==========================================================================" + "\n";
ScreenStr = ScreenStr + StringConcatenate("Total Profits(과거) : $",hprofit,", Buy : $",hbprofit,", Sell : $",hsprofit,", Total Orders : ",HTLots,"Lot_",hwborders+hwsorders,"/",horders,"건 = Total Buy ",hwborders,"/",hborders,"건 / Total Sell",hwsorders,hsorders,"건, 승률_",NormalizeDouble(((hwborders+hwsorders)/horders)*100,1),"%");
Comment(ScreenStr);
}
return(0);
} // EA 종료
//******************************************************************************
//| Data Filter Function |
//******************************************************************************
// 데이타 다운로드 미비에 의한 오류계산 방지 로직
bool DataFilter() {
bool M5_Data = FALSE;
bool M15_Data = FALSE;
if(iBars(Symbol(),PERIOD_M5)>MathMax(MathMax(MathMax(MathMax(MA_Period,Williams_Period),ATR_Period),CCI_Period),Sto_Period)) M5_Data = TRUE;
else M5_Data = FALSE;
if(iBars(Symbol(),PERIOD_M15)>MathMax(MathMax(MathMax(iMA_PeriodLONG,iWPR_PeriodLONG),ATR_Buy_Period3),iCCI_PeriodLONG)) M15_Data = TRUE;
else M15_Data = FALSE;
if(!M5_Data || !M15_Data) {
Print("Found Bars : M5_"+iBars(Symbol(),PERIOD_M5)+", M15_"+iBars(Symbol(),PERIOD_M15)+" Bar가 모자라, ㅠㅠ");
return(FALSE);
}
else
Print("Found Bars : M5_"+iBars(Symbol(),PERIOD_M5)+", M15_"+iBars(Symbol(),PERIOD_M15)+"거래시작");
return(TRUE);
}
//******************************************************************************
// Max Spread Limitation 설정함수 |
//******************************************************************************
bool TradeEnable() {
if(ask00-bid00 > MaxSpreads*mypoint*sympoint) return(false);
else return(true);
}
//******************************************************************************
//| 주문 함수 (OpenOrder) |
//******************************************************************************
int OpenOrder(string SymbolName, int CmdType, double Lots, int Slippages, double StopLosses, double TakeProfit, string Commented, int magic) { // 함수 시작
static string OrderTypeToString[6] = {"OP_BUY", "OP_SELL", "OP_BUYLIMIT", "OP_SELLLIMIT", "OP_BUYSTOP", "OP_SELLSTOP"};
int Ticket = -1;
int ErrorCodes;
int Slips = 0;
double Vol = 0;
string Comments;
color CLRs;
double stopbuy = ask00-(StopLosses*mypoint*sympoint);
double stopsell = bid00+(StopLosses*mypoint*sympoint);
double tpbuy = ask00+(TakeProfit*mypoint*sympoint);
double tpsell = bid00-(TakeProfit*mypoint*sympoint);
if (StopLosses == 0) {
stopbuy = 0;
stopsell = 0;
}
else
if (StopLosses < MathMax(stoplevel,freeze)) {
stopbuy = MathMax(stoplevel,freeze);
stopsell = MathMax(stoplevel,freeze);
}
if (TakeProfit == 0) {
tpbuy = 0;
tpsell = 0;
}
else
if (TakeProfit < MathMax(stoplevel,freeze)) {
tpbuy = MathMax(stoplevel,freeze);
tpsell = MathMax(stoplevel,freeze);
}
if (StopLosses == 0 && TakeProfit == 0) ECN = FALSE;
if (CmdType == OP_BUY) { // Buy 시작
Comments = Commentary+"_"+Commented+"_샀어";
CLRs = Red;
if (ECN == true) { // ECN 시작
double execution = GetTickCount();
Ticket = OrderSend(SymbolName, CmdType, Lots, ask00, Slippages, 0, 0,Comments,magic,0,CLRs);
if(SoundEnabled1) PlaySound(sound1);
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);
execution = GetTickCount()-execution;
return(0);
} // ECN 종료
else
{ // No ECN
execution = GetTickCount();
Ticket = OrderSend(SymbolName, CmdType, Lots, ask00, Slippages, stopbuy, tpbuy,Comments,magic,0,CLRs);
if(SoundEnabled1) PlaySound(sound1);
if(Ticket == -1) { // check for errors
ErrorCodes = GetLastError();
Print("아씨!, Error: " + ErrorDescription(ErrorCodes));
return(-1);
} // check for errors
execution = GetTickCount()-execution;
return(0);
} // No ECN 종료
} // Buy 종료
else
if (CmdType == OP_SELL) { // Sell 시작
Comments = Commentary+"_"+Commented+"_팔았어";
CLRs = Blue;
if (ECN == true) { // ECN 시작
execution = GetTickCount();
Ticket = OrderSend(SymbolName, CmdType, Lots, bid00, Slippages, 0, 0,Comments,magic,0,CLRs);
if(SoundEnabled2) PlaySound(sound2);
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);
execution = GetTickCount()-execution;
return(0);
} // ECN 종료
else
{ // No ECN
execution = GetTickCount();
Ticket = OrderSend(SymbolName, CmdType, Lots, bid00, Slippages, stopsell, tpsell,Comments,magic,0,CLRs);
if(SoundEnabled2) PlaySound(sound2);
if(Ticket == -1) { // check for errors
ErrorCodes = GetLastError();
Print("아씨!, Error: " + ErrorDescription(ErrorCodes));
return(-1);
} // check for errors
execution = GetTickCount()-execution;
return(0);
} // No 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)),", Execution : ",execution,"ms",
", ", 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);
}
//******************************************************************************
//| OrderLot Calculate Function(총Lot 계산 함수) |
//******************************************************************************
double TotalLot(int Magic) { // 0
double TLot=0;
for (int k=0; k < OrdersTotal(); k++) { // 1
if (OrderSelect(k, SELECT_BY_POS, MODE_TRADES)) { // 2
if (OrderMagicNumber()==Magic) { // 3
TLot = NormalizeDouble(TLot + OrderLots(),2);
} // 3
} // 2
} // 1
return(TLot);
} // 0
//******************************************************************************
//| Historical OrderLot Calculate Function(과거 총Lot 계산 함수) |
//******************************************************************************
double HTotalLot(int Magic) { // 0
double TLot=0;
for (int k=0; k < OrdersHistoryTotal(); k++) { // 1
if (OrderSelect(k, SELECT_BY_POS, MODE_HISTORY)) { // 2
if (OrderMagicNumber()==Magic) { // 3
TLot = NormalizeDouble(TLot + OrderLots(),2);
} // 3
} // 2
} // 1
return(TLot);
} // 0
//******************************************************************************
//| 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 = NormalizeDouble(Prof + OrderProfit()+OrderSwap()+OrderCommission(),2);
} // 3
} // 2
} // 1
return(Prof);
} // 0
//******************************************************************************
//| 총매수수익 계산 함수 |
//******************************************************************************
double BProfit(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 && OrderType()==OP_BUY) { // 3
Prof = NormalizeDouble(Prof + OrderProfit()+OrderSwap()+OrderCommission(),2);
} // 3
} // 2
} // 1
return(Prof);
} // 0
//******************************************************************************
//| 총매도수익 계산 함수 |
//******************************************************************************
double SProfit(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 && OrderType()==OP_SELL) { // 3
Prof = NormalizeDouble(Prof + OrderProfit()+OrderSwap()+OrderCommission(),2);
} // 3
} // 2
} // 1
return(Prof);
} // 0
//******************************************************************************
//| Total order Calculate Function(총오더수 계산 함수) |
//******************************************************************************
int 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 && (OrderType()==OP_BUY || OrderType()==OP_SELL)) { // 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 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 = NormalizeDouble(Prof + OrderProfit()+OrderSwap()+OrderCommission(),2);
} // 3
} // 2
} // 1
return(Prof);
} // 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 (OrderMagicNumber()==Magic && OrderType()==OP_BUY) { // 3
Prof = NormalizeDouble(Prof + OrderProfit()+OrderSwap()+OrderCommission(),2);
} // 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 (OrderMagicNumber()==Magic && OrderType()==OP_SELL) { // 3
Prof = NormalizeDouble(Prof + OrderProfit()+OrderSwap()+OrderCommission(),2);
} // 3
} // 2
} // 1
return(Prof);
} // 0
//******************************************************************************
//| Total order Calculate Function(총오더수 계산 함수,과거치 포함) |
//******************************************************************************
int HOrders(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 || OrderType()==OP_SELL)) { // 3
cnt++;
} // 3
} // 2
} // 1
return(cnt);
} // 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
//******************************************************************************
//| 총Winning Buy오더수 계산 함수(과거치 포함) |
//******************************************************************************
int HWBuyOrders(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
if(OrderProfit()+OrderSwap()+OrderCommission() >= 0) { // 4
cnt++;
} // 4
} // 3
} // 2
} // 1
return(cnt);
} // 0
//******************************************************************************
//| 총Winning Sell오더수 계산 함수(과거치 포함) |
//******************************************************************************
int HWSellOrders(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
if(OrderProfit()+OrderSwap()+OrderCommission() >= 0) { // 4
cnt++;
} // 4
} // 3
} // 2
} // 1
return(cnt);
} // 0
//******************************************************************************
//| Trailing Stop Function |
//******************************************************************************
void MoveTrailingStop(int Magics,double TrailingStop,double TrailingGap) {
int ct,totl=OrdersTotal();
if (OrdersTotal() > 0) {
for(ct=0;ct<totl;ct++) {
OrderSelect(ct,SELECT_BY_POS,MODE_TRADES);
if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==Magics) {
if( TrailingStop>0 && bid00 > NormalizeDouble(OrderOpenPrice()+TrailingStop*mypoint*sympoint,Digits) ) {
if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(bid00-TrailingGap*mypoint*sympoint,Digits))||(OrderStopLoss()==0)) {
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(bid00-TrailingGap*mypoint*sympoint,Digits),OrderTakeProfit(),0,Blue);
return(0);
}
}
}
if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==Magics) {
if( TrailingStop>0 && ask00 < NormalizeDouble(OrderOpenPrice()-TrailingStop*mypoint*Point,Digits) ) {
if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(ask00+TrailingGap*mypoint*sympoint,Digits)))||(OrderStopLoss()==0)) {
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(ask00+TrailingGap*mypoint*sympoint,Digits),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
//******************************************************************************
//| Break Even Strategy |
//******************************************************************************
void MoveBreakEven(int Magics,double BreakEven,double BreakPoint) {
int cnt,total=OrdersTotal();
if (OrdersTotal() > 0) {
for(cnt=0;cnt<total;cnt++) {
OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
if( OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==Magics ) {
if(OrderType()==OP_BUY) {
if(BreakEven>0) {
if(NormalizeDouble((bid00-OrderOpenPrice()),Digits) > BreakEven*mypoint*sympoint) {
if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),Digits) < 0) {
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+BreakPoint*mypoint*sympoint,Digits),OrderTakeProfit(),0,Blue);
return(0);
}
}
}
}
else
{
if(BreakEven>0) {
if(NormalizeDouble((OrderOpenPrice()-ask00),Digits) > BreakEven*mypoint*sympoint) {
if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),Digits) < 0) {
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-BreakPoint*mypoint*sympoint,Digits),OrderTakeProfit(),0,Red);
return(0);
}
}
}
}
}
}
}
}
//******************************************************************************
//| Stop Out조건발생시 전체 일괄 청산 함수 |
//******************************************************************************
void StopOutClose() { // 0
bool CloseAllOrders = false;
if(AccountFreeMargin() < StopOutBalance || AccountBalance() < StopOutBalance) CloseAllOrders = true;
else CloseAllOrders = false;
if(CloseAllOrders) { // 15
int totalord = OrdersTotal();
for(int jk=totalord-1;jk >= 0;jk--) { // 16
OrderSelect(jk, SELECT_BY_POS, MODE_TRADES);
int types = OrderType();
bool resultall = false;
RefreshRates();
switch(types) { //switch
case OP_BUY : resultall = OrderClose(OrderTicket(),OrderLots(),bid00,5,Red);
break;
case OP_SELL : resultall = OrderClose(OrderTicket(),OrderLots(),ask00,5, Blue);
} //switch
if(resultall == false) { // 17
Print("Order ", OrderTicket(), " failed to close. Error:", GetLastError() );
} // 17
} // 16
} // 15
} // 0
//******************************************************************************
//| 통화별 매직넘버 설정 |
//******************************************************************************
int getmagic() {
// 접미사형태의 통화대처를 위해 심볼명의 6자리까지 심볼명으로 지정
NowSym = StringSubstr(Symbol(), 0, 6);
if(NowSym == "EURUSD") magic1 = 67921001;
if(NowSym == "GBPUSD") magic1 = 67921002;
if(NowSym == "USDJPY") magic1 = 67921003;
if(NowSym == "AUDUSD") magic1 = 67921004;
if(NowSym == "EURGBP") magic1 = 67921005;
if(NowSym == "USDCAD") magic1 = 67921006;
if(NowSym == "USDCHF") magic1 = 67921007;
if(NowSym == "CHFJPY") magic1 = 67921008;
if(NowSym == "EURJPY") magic1 = 67921009;
if(NowSym == "NZDUSD") magic1 = 67921010;
if(NowSym == "GBPJPY") magic1 = 67921011;
if(NowSym == "EURAUD") magic1 = 67921012;
if(NowSym == "EURCAD") magic1 = 67921013;
if(NowSym == "EURCHF") magic1 = 67921014;
if(NowSym == "CADJPY") magic1 = 67921015;
if(NowSym == "AUDNZD") magic1 = 67921016;
if(NowSym == "AUDCAD") magic1 = 67921017;
if(NowSym == "AUDCHF") magic1 = 67921018;
if(NowSym == "AUDJPY") magic1 = 67921019;
if(NowSym == "GBPAUD") magic1 = 67921020;
if(NowSym == "NZDJPY") magic1 = 67921021;
if(NowSym == "GBPCAD") magic1 = 67921022;
if(NowSym == "NZDCAD") magic1 = 67921023;
if(NowSym == "CADCHF") magic1 = 67921024;
if(NowSym == "GBPNZD") magic1 = 67921025;
if(NowSym == "EURNZD") magic1 = 67921026;
if(NowSym == "NZDCHF") magic1 = 67921027;
if(NowSym == "GBPCHF") magic1 = 67921028;
return(magic1);
}
//******************************************************************************
//| Close Buy By Magic Number |
//******************************************************************************
void CloseBuyOpens(int Magic) { // 함수 시작
int total = OrdersTotal();
for(int i=total-1;i>=0;i--) { // Loop 시작
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
int type = OrderType();
bool result = false;
if (OrderMagicNumber() == Magic && type == OP_BUY) { // magic 조건시작
RefreshRates();
result = OrderClose( OrderTicket(), OrderLots(), bid00, slippage, Blue );
if(SoundEnabled3) PlaySound(sound3);
if(result == false) { // 에러 처리
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
} // 에러 처리 종료
} // magic 조건종료
} // Loop 종료
} // 함수 종료
//******************************************************************************
//| Close Sell By Magic Number |
//******************************************************************************
void CloseSellOpens(int Magic) { // 함수 시작
int total = OrdersTotal();
for(int i=total-1;i>=0;i--) { // Loop 시작
OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
int type = OrderType();
bool result = false;
if (OrderMagicNumber() == Magic && type == OP_SELL) { // magic 조건시작
RefreshRates();
result = OrderClose( OrderTicket(), OrderLots(), ask00, slippage, Red );
if(SoundEnabled4) PlaySound(sound4);
if(result == false) { // 에러 처리
Alert("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
Sleep(3000);
} // 에러 처리 종료
} // magic 조건종료
} // Loop 종료
} // 함수 종료
//******************************************************************************
//| Find Last Buy Price Function |
//******************************************************************************
double FindLastBuyPrice(int Magics) {
double ord_open_price;
int ord_ticket;
double buffers = 0;
int ticket_compair = -1;
for (int cnt = 0; cnt < OrdersTotal(); cnt++) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magics) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magics) {
ord_ticket = OrderTicket();
if (ord_ticket > ticket_compair) {
ord_open_price = OrderOpenPrice();
buffers = ord_open_price;
ticket_compair = ord_ticket;
}
}
}
return (ord_open_price);
}
//******************************************************************************
//| Find Last Sell Price Function |
//******************************************************************************
double FindLastSellPrice(int Magics) {
double ord_open_price;
int ord_ticket;
double buffers = 0;
int ticket_compair = -1;
for (int cnt = 0; cnt < OrdersTotal(); cnt++) {
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() != Symbol() || OrderMagicNumber() != Magics) continue;
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magics && OrderType() == OP_SELL) {
ord_ticket = OrderTicket();
if (ord_ticket > ticket_compair) {
ord_open_price = OrderOpenPrice();
buffers = ord_open_price;
ticket_compair = ord_ticket;
}
}
}
return (ord_open_price);
}
//******************************************************************************
//| Day/Time Filter Function |
//******************************************************************************
bool DayTimeFilter(int Dates, int start_time, int finish_time) {
int start_minute = 0;
int finish_minute = 0;
int Current_Time = TimeHour(TimeCurrent());
int Current_Minute = TimeMinute(TimeCurrent());
if (start_time==24) start_time = 0;
if (finish_time==24) finish_time = 0;
if (finish_time>24) {
finish_time = 23;
finish_minute = 59;
}
if (Current_Time==24) Current_Time = 0;
if (!TimeFilter) return(true) ;
else
if ( TimeFilter && DayOfWeek() == Dates && start_time < finish_time ) {
if ( (Current_Time >= start_time && Current_Minute >= start_minute) && (Current_Time <= finish_time && Current_Minute <= finish_minute) ) return(true) ;
else return(false);
}
if ( TimeFilter && DayOfWeek() == Dates && start_time > finish_time ) {
if ( (Current_Time >= start_time && Current_Minute >= start_minute) || (Current_Time <= finish_time && Current_Minute <= finish_minute) ) return(true) ;
else return(false);
}
}
//******************************************************************************
bool DayFilter() {
if (!DateFilter) return(true) ;
else
if ((MON && DayTimeFilter(1, mon_start_time, mon_finish_time)) || (TUE && DayTimeFilter(2, tue_start_time, tue_finish_time)) || (WED && DayTimeFilter(3, wed_start_time, wed_finish_time)) || (THU && DayTimeFilter(4, thu_start_time, thu_finish_time)) || (FRI && DayTimeFilter(5, fri_start_time, fri_finish_time))) return(true) ;
else return(false);
}
//******************************************************************************
//| Money Management Function |
//******************************************************************************
// Money Management 설정 0:FixLot,1:Percent,2:Conservative,3:Aggresive
double MoneyManagement(int DMM, double Percentage) {
double DynMM = 0.1;
double risk = 0.01;
int mmdigit, adjustlot;
if(lotstep==0.1) mmdigit = 1;
else if(lotstep==0.01) mmdigit = 2;
switch(DMM) { //switch
case 0 : return(FixLot);
break;
case 1 :
DynMM = (Percentage * AccountFreeMargin() / 100000);
DynMM = NormalizeDouble(DynMM,mmdigit);
if (DynMM > maxlot) return(maxlot);
else if (DynMM < minlot) return(minlot);
else return(DynMM);
break;
case 2 :
if(accfree<10000){adjustlot=1000;}
if(accfree<20000 && accfree>=10000){adjustlot=900;}
if(accfree<30000 && accfree>=20000){adjustlot=800;}
if(accfree<40000 && accfree>=30000){adjustlot=700;}
if(accfree<50000 && accfree>=40000){adjustlot=600;}
if(accfree<60000 && accfree>=50000){adjustlot=500;}
if(accfree<70000 && accfree>=60000){adjustlot=400;}
if(accfree<80000 && accfree>=70000){adjustlot=300;}
if(accfree<90000 && accfree>=80000){adjustlot=200;}
if(accfree>=90000){adjustlot=100;}
DynMM = NormalizeDouble(accfree * risk / adjustlot , mmdigit);
if (DynMM > maxlot) return(maxlot);
else if (DynMM < minlot) return(minlot);
else return(DynMM);
break;
case 3 :
if(accfree<10000){adjustlot=500;}
if(accfree<20000 && accfree>=10000){adjustlot=400;}
if(accfree<30000 && accfree>=20000){adjustlot=300;}
if(accfree<40000 && accfree>=30000){adjustlot=200;}
if(accfree<50000 && accfree>=40000){adjustlot=100;}
if(accfree<60000 && accfree>=50000){adjustlot=50;}
if(accfree<70000 && accfree>=60000){adjustlot=40;}
if(accfree<80000 && accfree>=70000){adjustlot=30;}
if(accfree<90000 && accfree>=80000){adjustlot=20;}
if(accfree>=90000){adjustlot=10;}
DynMM = NormalizeDouble(accfree * risk / adjustlot , mmdigit);
if (DynMM > maxlot) return(maxlot);
else if (DynMM < minlot) return(minlot);
else return(DynMM);
} //switch
}
'IT관련' 카테고리의 다른 글
Entry Logic 구성 Indicator(Backtest) (0) | 2019.09.15 |
---|---|
메타트레이더 EA - BaseCurrency_WPR Version (0) | 2019.09.14 |
메타트레이더 EA - BaseCurrency_Stochastic Version (0) | 2019.09.12 |
메타트레이더 EA - BaseCurrency_RSI 3. Weighted Version (0) | 2019.09.11 |
메타트레이더 EA - BaseCurrency_RSI 2. Reverse Version (0) | 2019.09.10 |