☞ EUR,USD,GBP,CHF,JPY,CAD,AUD,NZD로 구성된 28개통화쌍에 대하여 강세통화와 약세통화의 상대적인 추세를 RSI를 통해 판단하고 매매하는 EA로 3가지 버전으로 개발하였다. 

 

RSI Version
- 통화별 강세와 약세를 RSI롤 판단(40이하 weak, 60이상 strong)
- 약세통화와 강세통화의 조합을 추세대로 진입하는 로직 구성  
- M1 ~ H4까지의 Time Frame 전체에 대해 고려

Reverse Version
- 통화별 강세와 약세를 RSI롤 판단하여 80이상이고, 20이하인 통화에 대해 매매
- 약세통화와 강세통화의 조합을 역으로 진입하는 로직 구성 (Overbought, Oversold) 
- M1 ~ H4까지의 Time Frame 전체에 대해 고려

Weighted Version
- M1 ~ H4까지의 Time Frame 전체에 대해 고려하여 가까운시간대에 높은 가중치 부여

 

1. RSI Version 

 

//********************************************************************
//|                                        YS_BaseCurrency_RSI_V0.1     |
//|                                   Copyright @ 2012 Gguri FX LAB  |
//********************************************************************
//********************************************************************
//| Trading EA(Based On RSI)                                             |
//********************************************************************
//********************************************************************
//| Version History                                                           |
//********************************************************************
/*

 Version 0.1
- 통화별 강세와 약세를 RSI로 판단(40이하 weak, 60이상 strong)
- 약세통화와 강세통화의 조합을 추세대로 진입하는 로직 구성  
- M1 ~ H4까지의 Time Frame 전체에 대해 고려

*/

/*
Time Frame : H1
Pairs : All Pairs(USD,EUR,GBP,JPY,CAD,CHF,AUD,NZD)
*/

//********************************************************************
//| Import Library                                                   |
//********************************************************************
#import "stdlib.ex4"
   string ErrorDescription(int a0);

//********************************************************************
//| 외생변수 및 기타 내생변수                                        |
//********************************************************************

extern double FixLot=0.1 ;                       // 진입 랏사이즈 설정
extern double slippage = 3.0;                    // 슬리피지 허용 변수

extern int XSL = 120;                            // 목표 StopLoss
extern int XTP = 40;                             // 목표 TakeProfit

extern int All_SL = 300;                         // CloseAll StopLoss
extern int All_TP = 100;                         // CloseAll TakeProfit

extern string subfix = "";                       // 통화쌍 접미어가 있는 경우
extern double StopOutBalance = 500;              // 모든 거래 종료 잔고 설정

extern int MaxTrades = 1;                        // 통화당 최대 허용 거래수
extern int MaxSpread = 10;                       // 통화당 최대 허용 스프레드
/*
extern double  TrailingStop = 0.0;                // 트레일링 설정시 > 0
extern double  BreakEven = 0.0;                   // Break Even 설정시 > 0
extern double  BreakPoint = 0.0;                  // Break Even 설정시 손절치(본전 + 손절치)
*/
string Commentary = "YS_BaseCurrency_RSI_V0.1";   // Entry 주문시 비고 
string NowSym, StartDay;
datetime  PreviousBarTime;                        // NewBar함수 사용변수
double mypoint;
int TicketBuy,TicketSell;


//********************************************************************
//| Entry Logic 관련 변수 설정                                       |
//********************************************************************

string gs_unused_284 = "Entry Settings";
extern int periods = 14;
extern int weakvalue = 35;
extern int strongvalue = 65;

// 통화별 거래선택 변수
extern bool PairTrade01 = TRUE;             
extern bool PairTrade02 = TRUE;
extern bool PairTrade03 = TRUE;
extern bool PairTrade04 = TRUE;
extern bool PairTrade05 = TRUE;
extern bool PairTrade06 = TRUE;
extern bool PairTrade07 = TRUE;
extern bool PairTrade08 = TRUE;
extern bool PairTrade09 = TRUE;
extern bool PairTrade10 = TRUE;
extern bool PairTrade11 = TRUE;
extern bool PairTrade12 = TRUE;
extern bool PairTrade13 = TRUE;
extern bool PairTrade14 = TRUE;
extern bool PairTrade15 = TRUE;
extern bool PairTrade16 = TRUE;
extern bool PairTrade17 = TRUE;
extern bool PairTrade18 = TRUE;
extern bool PairTrade19 = TRUE;
extern bool PairTrade20 = TRUE;
extern bool PairTrade21 = TRUE;
extern bool PairTrade22 = TRUE;
extern bool PairTrade23 = TRUE;
extern bool PairTrade24 = TRUE;
extern bool PairTrade25 = TRUE;
extern bool PairTrade26 = TRUE;
extern bool PairTrade27 = TRUE;
extern bool PairTrade28 = TRUE;

//********************************************************************
//| 초기화                                                           |
//********************************************************************

int init()
{

  StartDay = TimeToStr(TimeCurrent(),TIME_DATE);  // EA 시작날짜를 표시하기 위해 시작일을 변수로 저장 

//********************************************************************
// 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()
{

//********************************************************************
// 하나의 봉에 대해 하나의 거래

 bool EntryEnabled = FALSE;
 
    if ( DayOfWeek() == 0 || DayOfWeek() == 6 ) EntryEnabled = FALSE; 
 
    if (NewBar()) EntryEnabled = TRUE;
    else EntryEnabled = FALSE;  

//********************************************************************
// StopOut Balance도달시 강제청산함수 가져오기

    StopOutClose(); 

//********************************************************************
// 개별 통화쌍 변수설정

   string symbol_01 = "AUDUSD" + subfix;
   string symbol_02 = "EURUSD" + subfix;
   string symbol_03 = "USDCHF" + subfix;
   string symbol_04 = "NZDUSD" + subfix;
   string symbol_05 = "GBPUSD" + subfix;
   string symbol_06 = "USDJPY" + subfix;
   string symbol_07 = "USDCAD" + subfix;
   string symbol_08 = "GBPJPY" + subfix;
   string symbol_09 = "EURJPY" + subfix;
   string symbol_10 = "AUDJPY" + subfix;
   string symbol_11 = "NZDJPY" + subfix;
   string symbol_12 = "CADJPY" + subfix;
   string symbol_13 = "CHFJPY" + subfix;
   string symbol_14 = "GBPAUD" + subfix;
   string symbol_15 = "EURAUD" + subfix;
   string symbol_16 = "AUDNZD" + subfix;
   string symbol_17 = "AUDCHF" + subfix;
   string symbol_18 = "AUDCAD" + subfix;
   string symbol_19 = "GBPCAD" + subfix;
   string symbol_20 = "EURCAD" + subfix;
   string symbol_21 = "NZDCAD" + subfix;
   string symbol_22 = "CADCHF" + subfix;
   string symbol_23 = "GBPNZD" + subfix;
   string symbol_24 = "EURNZD" + subfix;
   string symbol_25 = "NZDCHF" + subfix;
   string symbol_26 = "EURGBP" + subfix;
   string symbol_27 = "EURCHF" + subfix;
   string symbol_28 = "GBPCHF" + subfix;

//********************************************************************
// 데이타 다운로드 미비에 의한 오류계산 방지 로직
    
    if(iBars(symbol_01, PERIOD_H4)<periods) Print ("아! "+symbol_01+" Bar가 모자라");
    if(iBars(symbol_02, PERIOD_H4)<periods) Print ("아! "+symbol_02+" Bar가 모자라");
    if(iBars(symbol_03, PERIOD_H4)<periods) Print ("아! "+symbol_03+" Bar가 모자라");
    if(iBars(symbol_04, PERIOD_H4)<periods) Print ("아! "+symbol_04+" Bar가 모자라");
    if(iBars(symbol_05, PERIOD_H4)<periods) Print ("아! "+symbol_05+" Bar가 모자라");
    if(iBars(symbol_06, PERIOD_H4)<periods) Print ("아! "+symbol_06+" Bar가 모자라");
    if(iBars(symbol_07, PERIOD_H4)<periods) Print ("아! "+symbol_07+" Bar가 모자라");
    if(iBars(symbol_08, PERIOD_H4)<periods) Print ("아! "+symbol_08+" Bar가 모자라");
    if(iBars(symbol_09, PERIOD_H4)<periods) Print ("아! "+symbol_09+" Bar가 모자라");
    if(iBars(symbol_10, PERIOD_H4)<periods) Print ("아! "+symbol_10+" Bar가 모자라");
    if(iBars(symbol_11, PERIOD_H4)<periods) Print ("아! "+symbol_11+" Bar가 모자라");
    if(iBars(symbol_12, PERIOD_H4)<periods) Print ("아! "+symbol_12+" Bar가 모자라");
    if(iBars(symbol_13, PERIOD_H4)<periods) Print ("아! "+symbol_13+" Bar가 모자라");
    if(iBars(symbol_14, PERIOD_H4)<periods) Print ("아! "+symbol_14+" Bar가 모자라");
    if(iBars(symbol_15, PERIOD_H4)<periods) Print ("아! "+symbol_15+" Bar가 모자라");
    if(iBars(symbol_16, PERIOD_H4)<periods) Print ("아! "+symbol_16+" Bar가 모자라");
    if(iBars(symbol_17, PERIOD_H4)<periods) Print ("아! "+symbol_17+" Bar가 모자라");
    if(iBars(symbol_18, PERIOD_H4)<periods) Print ("아! "+symbol_18+" Bar가 모자라");
    if(iBars(symbol_19, PERIOD_H4)<periods) Print ("아! "+symbol_19+" Bar가 모자라");
    if(iBars(symbol_20, PERIOD_H4)<periods) Print ("아! "+symbol_20+" Bar가 모자라");
    if(iBars(symbol_21, PERIOD_H4)<periods) Print ("아! "+symbol_21+" Bar가 모자라");
    if(iBars(symbol_22, PERIOD_H4)<periods) Print ("아! "+symbol_22+" Bar가 모자라");
    if(iBars(symbol_23, PERIOD_H4)<periods) Print ("아! "+symbol_23+" Bar가 모자라");
    if(iBars(symbol_24, PERIOD_H4)<periods) Print ("아! "+symbol_24+" Bar가 모자라");
    if(iBars(symbol_25, PERIOD_H4)<periods) Print ("아! "+symbol_25+" Bar가 모자라");
    if(iBars(symbol_26, PERIOD_H4)<periods) Print ("아! "+symbol_26+" Bar가 모자라");
    if(iBars(symbol_27, PERIOD_H4)<periods) Print ("아! "+symbol_27+" Bar가 모자라");
    if(iBars(symbol_28, PERIOD_H4)<periods) Print ("아! "+symbol_28+" Bar가 모자라");    
   
//********************************************************************
// 통화별 매직넘버 가져오기

   int magic01 = 10109825;
   int magic02 = 20109825;
   int magic03 = 30109825;
   int magic04 = 40109825;
   int magic05 = 50109825;
   int magic06 = 60109825;
   int magic07 = 70109825;
   int magic08 = 80109825;
   int magic09 = 90109825;
   int magic10 = 10009825;
   int magic11 = 11009825;
   int magic12 = 12009825;
   int magic13 = 13009825;
   int magic14 = 14009825;
   int magic15 = 15009825;
   int magic16 = 16009825;
   int magic17 = 17009825;
   int magic18 = 18009825;
   int magic19 = 19009825;
   int magic20 = 20009825;
   int magic21 = 21009825;
   int magic22 = 22009825;
   int magic23 = 23009825;
   int magic24 = 24009825;
   int magic25 = 25009825;
   int magic26 = 26009825;
   int magic27 = 27009825;
   int magic28 = 28009825;

  
//********************************************************************
// Max Spread 초과시 진입금지 로직      
   
   if(TradeEnable(symbol_01)==false || !PairTrade01) PairTrade01 = FALSE;
   else PairTrade01 = TRUE; 
   if(TradeEnable(symbol_02)==false || !PairTrade02) PairTrade02 = FALSE;
   else PairTrade02 = TRUE; 
   if(TradeEnable(symbol_03)==false || !PairTrade03) PairTrade03 = FALSE;
   else PairTrade03 = TRUE; 
   if(TradeEnable(symbol_04)==false || !PairTrade04) PairTrade04 = FALSE;
   else PairTrade04 = TRUE; 
   if(TradeEnable(symbol_05)==false || !PairTrade05) PairTrade05 = FALSE;
   else PairTrade05 = TRUE; 
   if(TradeEnable(symbol_06)==false || !PairTrade06) PairTrade06 = FALSE;
   else PairTrade06 = TRUE; 
   if(TradeEnable(symbol_07)==false || !PairTrade07) PairTrade07 = FALSE;
   else PairTrade07 = TRUE; 
   if(TradeEnable(symbol_08)==false || !PairTrade08) PairTrade08 = FALSE;
   else PairTrade08 = TRUE; 
   if(TradeEnable(symbol_09)==false || !PairTrade09) PairTrade09 = FALSE;
   else PairTrade09 = TRUE; 
   if(TradeEnable(symbol_10)==false || !PairTrade10) PairTrade10 = FALSE;
   else PairTrade10 = TRUE;    
   if(TradeEnable(symbol_11)==false || !PairTrade11) PairTrade11 = FALSE;
   else PairTrade11 = TRUE;     
   if(TradeEnable(symbol_12)==false || !PairTrade12) PairTrade12 = FALSE;
   else PairTrade12 = TRUE; 
   if(TradeEnable(symbol_13)==false || !PairTrade13) PairTrade13 = FALSE;
   else PairTrade13 = TRUE; 
   if(TradeEnable(symbol_14)==false || !PairTrade14) PairTrade14 = FALSE;
   else PairTrade14 = TRUE; 
   if(TradeEnable(symbol_15)==false || !PairTrade15) PairTrade15 = FALSE;
   else PairTrade15 = TRUE; 
   if(TradeEnable(symbol_16)==false || !PairTrade16) PairTrade16 = FALSE;
   else PairTrade16 = TRUE; 
   if(TradeEnable(symbol_17)==false || !PairTrade17) PairTrade17 = FALSE;
   else PairTrade17 = TRUE; 
   if(TradeEnable(symbol_18)==false || !PairTrade18) PairTrade18 = FALSE;
   else PairTrade18 = TRUE; 
   if(TradeEnable(symbol_19)==false || !PairTrade19) PairTrade19 = FALSE;
   else PairTrade19 = TRUE; 
   if(TradeEnable(symbol_20)==false || !PairTrade20) PairTrade20 = FALSE;
   else PairTrade20 = TRUE; 
   if(TradeEnable(symbol_21)==false || !PairTrade21) PairTrade21 = FALSE;
   else PairTrade21 = TRUE; 
   if(TradeEnable(symbol_22)==false || !PairTrade22) PairTrade22 = FALSE;
   else PairTrade22 = TRUE;    
   if(TradeEnable(symbol_23)==false || !PairTrade23) PairTrade23 = FALSE;
   else PairTrade23 = TRUE; 
   if(TradeEnable(symbol_24)==false || !PairTrade24) PairTrade24 = FALSE;
   else PairTrade24 = TRUE; 
   if(TradeEnable(symbol_25)==false || !PairTrade25) PairTrade25 = FALSE;
   else PairTrade25 = TRUE; 
   if(TradeEnable(symbol_26)==false || !PairTrade26) PairTrade26 = FALSE;
   else PairTrade26 = TRUE; 
   if(TradeEnable(symbol_27)==false || !PairTrade27) PairTrade27 = FALSE;
   else PairTrade27 = TRUE; 
   if(TradeEnable(symbol_28)==false || !PairTrade28) PairTrade28 = FALSE;
   else PairTrade28 = TRUE; 

   
/*
   if(TrailingStop>0) MoveTrailingStop();
   if(BreakEven>0) MoveBreakEven();
*/  
   
//********************************************************************
//| Entry Logic                                                      |
//********************************************************************   

   bool USD_Weak = FALSE;
   bool EUR_Weak = FALSE;
   bool GBP_Weak = FALSE;
   bool JPY_Weak = FALSE;      
   bool CHF_Weak = FALSE;
   bool CAD_Weak = FALSE;
   bool AUD_Weak = FALSE;
   bool NZD_Weak = FALSE;            
   
   if(USD_RSI(1,1)   if(EUR_RSI(1,1)   if(GBP_RSI(1,1)   if(JPY_RSI(1,1)   if(CHF_RSI(1,1)   if(CAD_RSI(1,1)   if(AUD_RSI(1,1)   if(NZD_RSI(1,1)
   bool USD_Strong = FALSE;
   bool EUR_Strong = FALSE;
   bool GBP_Strong = FALSE;
   bool JPY_Strong = FALSE;      
   bool CHF_Strong = FALSE;
   bool CAD_Strong = FALSE;
   bool AUD_Strong = FALSE;
   bool NZD_Strong = FALSE;            
   
   if(USD_RSI(1,1)>strongvalue && USD_RSI(5,1)>strongvalue && USD_RSI(15,1)>strongvalue && USD_RSI(30,1)>strongvalue && USD_RSI(60,1)>strongvalue && USD_RSI(240,1)>strongvalue) USD_Strong = TRUE;
   if(EUR_RSI(1,1)>strongvalue && EUR_RSI(5,1)>strongvalue && EUR_RSI(15,1)>strongvalue && EUR_RSI(30,1)>strongvalue && EUR_RSI(60,1)>strongvalue && EUR_RSI(240,1)>strongvalue) EUR_Strong = TRUE;
   if(GBP_RSI(1,1)>strongvalue && GBP_RSI(5,1)>strongvalue && GBP_RSI(15,1)>strongvalue && GBP_RSI(30,1)>strongvalue && GBP_RSI(60,1)>strongvalue && GBP_RSI(240,1)>strongvalue) GBP_Strong = TRUE;
   if(JPY_RSI(1,1)>strongvalue && JPY_RSI(5,1)>strongvalue && JPY_RSI(15,1)>strongvalue && JPY_RSI(30,1)>strongvalue && JPY_RSI(60,1)>strongvalue && JPY_RSI(240,1)>strongvalue) JPY_Strong = TRUE;
   if(CHF_RSI(1,1)>strongvalue && CHF_RSI(5,1)>strongvalue && CHF_RSI(15,1)>strongvalue && CHF_RSI(30,1)>strongvalue && CHF_RSI(60,1)>strongvalue && CHF_RSI(240,1)>strongvalue) CHF_Strong = TRUE;
   if(CAD_RSI(1,1)>strongvalue && CAD_RSI(5,1)>strongvalue && CAD_RSI(15,1)>strongvalue && CAD_RSI(30,1)>strongvalue && CAD_RSI(60,1)>strongvalue && CAD_RSI(240,1)>strongvalue) CAD_Strong = TRUE;
   if(AUD_RSI(1,1)>strongvalue && AUD_RSI(5,1)>strongvalue && AUD_RSI(15,1)>strongvalue && AUD_RSI(30,1)>strongvalue && AUD_RSI(60,1)>strongvalue && AUD_RSI(240,1)>strongvalue) AUD_Strong = TRUE;
   if(NZD_RSI(1,1)>strongvalue && NZD_RSI(5,1)>strongvalue && NZD_RSI(15,1)>strongvalue && NZD_RSI(30,1)>strongvalue && NZD_RSI(60,1)>strongvalue && NZD_RSI(240,1)>strongvalue) NZD_Strong = TRUE; 
   
   if(USD_RSI(1,1)*USD_RSI(5,1)*USD_RSI(15,1)*USD_RSI(30,1)*USD_RSI(60,1)*USD_RSI(240,1)==0) USD_Weak = FALSE;
   if(EUR_RSI(1,1)*EUR_RSI(5,1)*EUR_RSI(15,1)*EUR_RSI(30,1)*EUR_RSI(60,1)*EUR_RSI(240,1)==0) EUR_Weak = FALSE;
   if(GBP_RSI(1,1)*GBP_RSI(5,1)*GBP_RSI(15,1)*GBP_RSI(30,1)*GBP_RSI(60,1)*GBP_RSI(240,1)==0) GBP_Weak = FALSE;
   if(JPY_RSI(1,1)*JPY_RSI(5,1)*JPY_RSI(15,1)*JPY_RSI(30,1)*JPY_RSI(60,1)*JPY_RSI(240,1)==0) JPY_Weak = FALSE;      
   if(CHF_RSI(1,1)*CHF_RSI(5,1)*CHF_RSI(15,1)*CHF_RSI(30,1)*CHF_RSI(60,1)*CHF_RSI(240,1)==0) CHF_Weak = FALSE;
   if(CAD_RSI(1,1)*CAD_RSI(5,1)*CAD_RSI(15,1)*CAD_RSI(30,1)*CAD_RSI(60,1)*CAD_RSI(240,1)==0) CAD_Weak = FALSE;   
   if(AUD_RSI(1,1)*AUD_RSI(5,1)*AUD_RSI(15,1)*AUD_RSI(30,1)*AUD_RSI(60,1)*AUD_RSI(240,1)==0) AUD_Weak = FALSE;
   if(NZD_RSI(1,1)*NZD_RSI(5,1)*NZD_RSI(15,1)*NZD_RSI(30,1)*NZD_RSI(60,1)*NZD_RSI(240,1)==0) NZD_Weak = FALSE;      


//********************************************************************
//| Close Condition Function                                         |
//********************************************************************
//********************************************************************  
// TP, SL 도달시 청산(Hidden TP, SL)

   if(Profit(magic01)>XTP || Profit(magic01)<-XSL) CloseAllOpens(magic01); 
   if(Profit(magic02)>XTP || Profit(magic02)<-XSL) CloseAllOpens(magic02); 
   if(Profit(magic03)>XTP || Profit(magic03)<-XSL) CloseAllOpens(magic03); 
   if(Profit(magic04)>XTP || Profit(magic04)<-XSL) CloseAllOpens(magic04); 
   if(Profit(magic05)>XTP || Profit(magic05)<-XSL) CloseAllOpens(magic05); 
   if(Profit(magic06)>XTP || Profit(magic06)<-XSL) CloseAllOpens(magic06); 
   if(Profit(magic07)>XTP || Profit(magic07)<-XSL) CloseAllOpens(magic07); 
   if(Profit(magic08)>XTP || Profit(magic08)<-XSL) CloseAllOpens(magic08); 
   if(Profit(magic09)>XTP || Profit(magic09)<-XSL) CloseAllOpens(magic09); 
   if(Profit(magic10)>XTP || Profit(magic10)<-XSL) CloseAllOpens(magic10); 
   if(Profit(magic11)>XTP || Profit(magic11)<-XSL) CloseAllOpens(magic11); 
   if(Profit(magic12)>XTP || Profit(magic12)<-XSL) CloseAllOpens(magic12);    
   if(Profit(magic13)>XTP || Profit(magic13)<-XSL) CloseAllOpens(magic13); 
   if(Profit(magic14)>XTP || Profit(magic14)<-XSL) CloseAllOpens(magic14); 
   if(Profit(magic15)>XTP || Profit(magic15)<-XSL) CloseAllOpens(magic15);    
   if(Profit(magic16)>XTP || Profit(magic16)<-XSL) CloseAllOpens(magic16); 
   if(Profit(magic17)>XTP || Profit(magic17)<-XSL) CloseAllOpens(magic17); 
   if(Profit(magic18)>XTP || Profit(magic18)<-XSL) CloseAllOpens(magic18);    
   if(Profit(magic19)>XTP || Profit(magic19)<-XSL) CloseAllOpens(magic19); 
   if(Profit(magic20)>XTP || Profit(magic20)<-XSL) CloseAllOpens(magic20); 
   if(Profit(magic21)>XTP || Profit(magic21)<-XSL) CloseAllOpens(magic21);    
   if(Profit(magic22)>XTP || Profit(magic22)<-XSL) CloseAllOpens(magic22); 
   if(Profit(magic23)>XTP || Profit(magic23)<-XSL) CloseAllOpens(magic23);    
   if(Profit(magic24)>XTP || Profit(magic24)<-XSL) CloseAllOpens(magic24); 
   if(Profit(magic25)>XTP || Profit(magic25)<-XSL) CloseAllOpens(magic25);    
   if(Profit(magic26)>XTP || Profit(magic26)<-XSL) CloseAllOpens(magic26); 
   if(Profit(magic27)>XTP || Profit(magic27)<-XSL) CloseAllOpens(magic27);    
   if(Profit(magic28)>XTP || Profit(magic28)<-XSL) CloseAllOpens(magic28);    
   
//********************************************************************
//| Close All Function                                               |
//********************************************************************
//******************************************************************** 
// 전체수익이나 손실이 설정치 이상인 경우 Close All

   double bprofit01 = BProfit(magic01)+BProfit(magic02)+BProfit(magic03)+BProfit(magic04)+BProfit(magic05)+BProfit(magic06)+BProfit(magic07)+BProfit(magic08)+BProfit(magic09)+BProfit(magic10);
   double bprofit02 = BProfit(magic11)+BProfit(magic12)+BProfit(magic13)+BProfit(magic14)+BProfit(magic15)+BProfit(magic16)+BProfit(magic17)+BProfit(magic18)+BProfit(magic19)+BProfit(magic20);     
   double bprofit03 = BProfit(magic21)+BProfit(magic22)+BProfit(magic23)+BProfit(magic24)+BProfit(magic25)+BProfit(magic26)+BProfit(magic27)+BProfit(magic28);
   double bprofits = bprofit01+bprofit02+bprofit03;

   double sprofit01 = SProfit(magic01)+SProfit(magic02)+SProfit(magic03)+SProfit(magic04)+SProfit(magic05)+SProfit(magic06)+SProfit(magic07)+SProfit(magic08)+SProfit(magic09)+SProfit(magic10);
   double sprofit02 = SProfit(magic11)+SProfit(magic12)+SProfit(magic13)+SProfit(magic14)+SProfit(magic15)+SProfit(magic16)+SProfit(magic17)+SProfit(magic18)+SProfit(magic19)+SProfit(magic20);     
   double sprofit03 = SProfit(magic21)+SProfit(magic22)+SProfit(magic23)+SProfit(magic24)+SProfit(magic25)+SProfit(magic26)+SProfit(magic27)+SProfit(magic28);
   double sprofits = sprofit01+sprofit02+sprofit03;   

   double profits = bprofits+sprofits;

   if(profits>All_TP || profits<-All_SL) {

     if(TotalOrders(magic01)>0) CloseAllOpens(magic01); 
     if(TotalOrders(magic02)>0) CloseAllOpens(magic02); 
     if(TotalOrders(magic03)>0) CloseAllOpens(magic03); 
     if(TotalOrders(magic04)>0) CloseAllOpens(magic04); 
     if(TotalOrders(magic05)>0) CloseAllOpens(magic05); 
     if(TotalOrders(magic06)>0) CloseAllOpens(magic06); 
     if(TotalOrders(magic07)>0) CloseAllOpens(magic07); 
     if(TotalOrders(magic08)>0) CloseAllOpens(magic08); 
     if(TotalOrders(magic09)>0) CloseAllOpens(magic09); 
     if(TotalOrders(magic10)>0) CloseAllOpens(magic10); 
     if(TotalOrders(magic11)>0) CloseAllOpens(magic11); 
     if(TotalOrders(magic12)>0) CloseAllOpens(magic12);    
     if(TotalOrders(magic13)>0) CloseAllOpens(magic13); 
     if(TotalOrders(magic14)>0) CloseAllOpens(magic14); 
     if(TotalOrders(magic15)>0) CloseAllOpens(magic15);    
     if(TotalOrders(magic16)>0) CloseAllOpens(magic16); 
     if(TotalOrders(magic17)>0) CloseAllOpens(magic17); 
     if(TotalOrders(magic18)>0) CloseAllOpens(magic18);    
     if(TotalOrders(magic19)>0) CloseAllOpens(magic19); 
     if(TotalOrders(magic20)>0) CloseAllOpens(magic20); 
     if(TotalOrders(magic21)>0) CloseAllOpens(magic21);    
     if(TotalOrders(magic22)>0) CloseAllOpens(magic22); 
     if(TotalOrders(magic23)>0) CloseAllOpens(magic23);    
     if(TotalOrders(magic24)>0) CloseAllOpens(magic24); 
     if(TotalOrders(magic25)>0) CloseAllOpens(magic25);    
     if(TotalOrders(magic26)>0) CloseAllOpens(magic26); 
     if(TotalOrders(magic27)>0) CloseAllOpens(magic27);    
     if(TotalOrders(magic28)>0) CloseAllOpens(magic28);        
   }


//********************************************************************
//| Buy/Sell Condition Function                                      |
//********************************************************************
//********************************************************************  
// Buy Condition

   bool BuyCon01 = FALSE;
   bool BuyCon02 = FALSE;
   bool BuyCon03 = FALSE;
   bool BuyCon04 = FALSE;
   bool BuyCon05 = FALSE;
   bool BuyCon06 = FALSE;
   bool BuyCon07 = FALSE;
   bool BuyCon08 = FALSE;
   bool BuyCon09 = FALSE;
   bool BuyCon10 = FALSE;
   bool BuyCon11 = FALSE;
   bool BuyCon12 = FALSE;
   bool BuyCon13 = FALSE;
   bool BuyCon14 = FALSE;
   bool BuyCon15 = FALSE;
   bool BuyCon16 = FALSE;
   bool BuyCon17 = FALSE;
   bool BuyCon18 = FALSE;
   bool BuyCon19 = FALSE;
   bool BuyCon20 = FALSE;
   bool BuyCon21 = FALSE;
   bool BuyCon22 = FALSE;
   bool BuyCon23 = FALSE;
   bool BuyCon24 = FALSE;
   bool BuyCon25 = FALSE;
   bool BuyCon26 = FALSE;
   bool BuyCon27 = FALSE;
   bool BuyCon28 = FALSE;

   if(AUD_Strong && USD_Weak) BuyCon01 = TRUE;
   else BuyCon01 = FALSE;
   if(EUR_Strong && USD_Weak) BuyCon02 = TRUE;
   else BuyCon02 = FALSE;
   if(USD_Strong && CHF_Weak) BuyCon03 = TRUE;
   else BuyCon03 = FALSE;
   if(NZD_Strong && USD_Weak) BuyCon04 = TRUE;
   else BuyCon04 = FALSE;
   if(GBP_Strong && USD_Weak) BuyCon05 = TRUE;
   else BuyCon05 = FALSE;
   if(USD_Strong && JPY_Weak) BuyCon06 = TRUE;
   else BuyCon06 = FALSE;
   if(USD_Strong && CAD_Weak) BuyCon07 = TRUE;
   else BuyCon07 = FALSE;
   if(GBP_Strong && JPY_Weak) BuyCon08 = TRUE;
   else BuyCon08 = FALSE;
   if(EUR_Strong && JPY_Weak) BuyCon09 = TRUE;
   else BuyCon09 = FALSE;
   if(AUD_Strong && JPY_Weak) BuyCon10 = TRUE;
   else BuyCon10 = FALSE;
   if(NZD_Strong && JPY_Weak) BuyCon11 = TRUE;
   else BuyCon11 = FALSE;
   if(CAD_Strong && JPY_Weak) BuyCon12 = TRUE;
   else BuyCon12 = FALSE;
   if(CHF_Strong && JPY_Weak) BuyCon13 = TRUE;
   else BuyCon13 = FALSE;
   if(GBP_Strong && AUD_Weak) BuyCon14 = TRUE;
   else BuyCon14 = FALSE;
   if(EUR_Strong && AUD_Weak) BuyCon15 = TRUE;
   else BuyCon15 = FALSE;
   if(AUD_Strong && NZD_Weak) BuyCon16 = TRUE;
   else BuyCon16 = FALSE;
   if(AUD_Strong && CHF_Weak) BuyCon17 = TRUE;
   else BuyCon17 = FALSE;   
   if(AUD_Strong && CAD_Weak) BuyCon18 = TRUE;
   else BuyCon18 = FALSE;   
   if(GBP_Strong && CAD_Weak) BuyCon19 = TRUE;
   else BuyCon19 = FALSE;   
   if(EUR_Strong && CAD_Weak) BuyCon20 = TRUE;
   else BuyCon20 = FALSE;   
   if(NZD_Strong && CAD_Weak) BuyCon21 = TRUE;
   else BuyCon21 = FALSE;     
   if(CAD_Strong && CHF_Weak) BuyCon22 = TRUE;
   else BuyCon22 = FALSE;     
   if(GBP_Strong && NZD_Weak) BuyCon23 = TRUE;
   else BuyCon23 = FALSE;  
   if(EUR_Strong && NZD_Weak) BuyCon24 = TRUE;
   else BuyCon24 = FALSE;  
   if(NZD_Strong && CHF_Weak) BuyCon25 = TRUE;
   else BuyCon25 = FALSE;  
   if(EUR_Strong && GBP_Weak) BuyCon26 = TRUE;
   else BuyCon26 = FALSE;  
   if(EUR_Strong && CHF_Weak) BuyCon27 = TRUE;
   else BuyCon27 = FALSE;  
   if(GBP_Strong && CHF_Weak) BuyCon28 = TRUE;
   else BuyCon28 = FALSE;     

   if(EntryEnabled && PairTrade01 && TotalOrders(magic01)   if(EntryEnabled && PairTrade02 && TotalOrders(magic02)   if(EntryEnabled && PairTrade03 && TotalOrders(magic03)   if(EntryEnabled && PairTrade04 && TotalOrders(magic04)   if(EntryEnabled && PairTrade05 && TotalOrders(magic05)   if(EntryEnabled && PairTrade06 && TotalOrders(magic06)   if(EntryEnabled && PairTrade07 && TotalOrders(magic07)   if(EntryEnabled && PairTrade08 && TotalOrders(magic08)   if(EntryEnabled && PairTrade09 && TotalOrders(magic09)   if(EntryEnabled && PairTrade10 && TotalOrders(magic10)   if(EntryEnabled && PairTrade11 && TotalOrders(magic11)   if(EntryEnabled && PairTrade12 && TotalOrders(magic12)   if(EntryEnabled && PairTrade13 && TotalOrders(magic13)   if(EntryEnabled && PairTrade14 && TotalOrders(magic14)   if(EntryEnabled && PairTrade15 && TotalOrders(magic15)   if(EntryEnabled && PairTrade16 && TotalOrders(magic16)   if(EntryEnabled && PairTrade17 && TotalOrders(magic17)   if(EntryEnabled && PairTrade18 && TotalOrders(magic18)   if(EntryEnabled && PairTrade19 && TotalOrders(magic19)   if(EntryEnabled && PairTrade20 && TotalOrders(magic20)   if(EntryEnabled && PairTrade21 && TotalOrders(magic21)   if(EntryEnabled && PairTrade22 && TotalOrders(magic22)   if(EntryEnabled && PairTrade23 && TotalOrders(magic23)   if(EntryEnabled && PairTrade24 && TotalOrders(magic24)   if(EntryEnabled && PairTrade25 && TotalOrders(magic25)   if(EntryEnabled && PairTrade26 && TotalOrders(magic26)   if(EntryEnabled && PairTrade27 && TotalOrders(magic27)   if(EntryEnabled && PairTrade28 && TotalOrders(magic28)
//********************************************************************  
// Sell Condition

   bool SellCon01 = FALSE;
   bool SellCon02 = FALSE;
   bool SellCon03 = FALSE;
   bool SellCon04 = FALSE;
   bool SellCon05 = FALSE;
   bool SellCon06 = FALSE;
   bool SellCon07 = FALSE;
   bool SellCon08 = FALSE;
   bool SellCon09 = FALSE;
   bool SellCon10 = FALSE;
   bool SellCon11 = FALSE;
   bool SellCon12 = FALSE;
   bool SellCon13 = FALSE;
   bool SellCon14 = FALSE;
   bool SellCon15 = FALSE;
   bool SellCon16 = FALSE;
   bool SellCon17 = FALSE;
   bool SellCon18 = FALSE;
   bool SellCon19 = FALSE;
   bool SellCon20 = FALSE;
   bool SellCon21 = FALSE;
   bool SellCon22 = FALSE;
   bool SellCon23 = FALSE;
   bool SellCon24 = FALSE;
   bool SellCon25 = FALSE;
   bool SellCon26 = FALSE;
   bool SellCon27 = FALSE;
   bool SellCon28 = FALSE;

   if(AUD_Weak && USD_Strong) SellCon01 = TRUE;
   else SellCon01 = FALSE;
   if(EUR_Weak && USD_Strong) SellCon02 = TRUE;
   else SellCon02 = FALSE;
   if(USD_Weak && CHF_Strong) SellCon03 = TRUE;
   else SellCon03 = FALSE;
   if(NZD_Weak && USD_Strong) SellCon04 = TRUE;
   else SellCon04 = FALSE;
   if(GBP_Weak && USD_Strong) SellCon05 = TRUE;
   else SellCon05 = FALSE;
   if(USD_Weak && JPY_Strong) SellCon06 = TRUE;
   else SellCon06 = FALSE;
   if(USD_Weak && CAD_Strong) SellCon07 = TRUE;
   else SellCon07 = FALSE;
   if(GBP_Weak && JPY_Strong) SellCon08 = TRUE;
   else SellCon08 = FALSE;
   if(EUR_Weak && JPY_Strong) SellCon09 = TRUE;
   else SellCon09 = FALSE;
   if(AUD_Weak && JPY_Strong) SellCon10 = TRUE;
   else SellCon10 = FALSE;
   if(NZD_Weak && JPY_Strong) SellCon11 = TRUE;
   else SellCon11 = FALSE;
   if(CAD_Weak && JPY_Strong) SellCon12 = TRUE;
   else SellCon12 = FALSE;
   if(CHF_Weak && JPY_Strong) SellCon13 = TRUE;
   else SellCon13 = FALSE;
   if(GBP_Weak && AUD_Strong) SellCon14 = TRUE;
   else SellCon14 = FALSE;
   if(EUR_Weak && AUD_Strong) SellCon15 = TRUE;
   else SellCon15 = FALSE;
   if(AUD_Weak && NZD_Strong) SellCon16 = TRUE;
   else SellCon16 = FALSE;
   if(AUD_Weak && CHF_Strong) SellCon17 = TRUE;
   else SellCon17 = FALSE;   
   if(AUD_Weak && CAD_Strong) SellCon18 = TRUE;
   else SellCon18 = FALSE;   
   if(GBP_Weak && CAD_Strong) SellCon19 = TRUE;
   else SellCon19 = FALSE;   
   if(EUR_Weak && CAD_Strong) SellCon20 = TRUE;
   else SellCon20 = FALSE;   
   if(NZD_Weak && CAD_Strong) SellCon21 = TRUE;
   else SellCon21 = FALSE;     
   if(CAD_Weak && CHF_Strong) SellCon22 = TRUE;
   else SellCon22 = FALSE;     
   if(GBP_Weak && NZD_Strong) SellCon23 = TRUE;
   else SellCon23 = FALSE;  
   if(EUR_Weak && NZD_Strong) SellCon24 = TRUE;
   else SellCon24 = FALSE;  
   if(NZD_Weak && CHF_Strong) SellCon25 = TRUE;
   else SellCon25 = FALSE;  
   if(EUR_Weak && GBP_Strong) SellCon26 = TRUE;
   else SellCon26 = FALSE;  
   if(EUR_Weak && CHF_Strong) SellCon27 = TRUE;
   else SellCon27 = FALSE;  
   if(GBP_Weak && CHF_Strong) SellCon28 = TRUE;
   else SellCon28 = FALSE;     

   if(EntryEnabled && PairTrade01 && TotalOrders(magic01)   if(EntryEnabled && PairTrade02 && TotalOrders(magic02)   if(EntryEnabled && PairTrade03 && TotalOrders(magic03)   if(EntryEnabled && PairTrade04 && TotalOrders(magic04)   if(EntryEnabled && PairTrade05 && TotalOrders(magic05)   if(EntryEnabled && PairTrade06 && TotalOrders(magic06)   if(EntryEnabled && PairTrade07 && TotalOrders(magic07)   if(EntryEnabled && PairTrade08 && TotalOrders(magic08)   if(EntryEnabled && PairTrade09 && TotalOrders(magic09)   if(EntryEnabled && PairTrade10 && TotalOrders(magic10)   if(EntryEnabled && PairTrade11 && TotalOrders(magic11)   if(EntryEnabled && PairTrade12 && TotalOrders(magic12)   if(EntryEnabled && PairTrade13 && TotalOrders(magic13)   if(EntryEnabled && PairTrade14 && TotalOrders(magic14)   if(EntryEnabled && PairTrade15 && TotalOrders(magic15)   if(EntryEnabled && PairTrade16 && TotalOrders(magic16)   if(EntryEnabled && PairTrade17 && TotalOrders(magic17)   if(EntryEnabled && PairTrade18 && TotalOrders(magic18)   if(EntryEnabled && PairTrade19 && TotalOrders(magic19)   if(EntryEnabled && PairTrade20 && TotalOrders(magic20)   if(EntryEnabled && PairTrade21 && TotalOrders(magic21)   if(EntryEnabled && PairTrade22 && TotalOrders(magic22)   if(EntryEnabled && PairTrade23 && TotalOrders(magic23)   if(EntryEnabled && PairTrade24 && TotalOrders(magic24)   if(EntryEnabled && PairTrade25 && TotalOrders(magic25)   if(EntryEnabled && PairTrade26 && TotalOrders(magic26)   if(EntryEnabled && PairTrade27 && TotalOrders(magic27)   if(EntryEnabled && PairTrade28 && TotalOrders(magic28)


//********************************************************************
//| 전송 데이타와 전송받은 데이타 화면표시                           |
//********************************************************************
     
     int border01 = TotalBuyOrders(magic01)+TotalBuyOrders(magic02)+TotalBuyOrders(magic03)+TotalBuyOrders(magic04)+TotalBuyOrders(magic05)+TotalBuyOrders(magic06)+TotalBuyOrders(magic07)+TotalBuyOrders(magic08)+TotalBuyOrders(magic09)+TotalBuyOrders(magic10);
     int border02 = TotalBuyOrders(magic11)+TotalBuyOrders(magic12)+TotalBuyOrders(magic13)+TotalBuyOrders(magic14)+TotalBuyOrders(magic15)+TotalBuyOrders(magic16)+TotalBuyOrders(magic17)+TotalBuyOrders(magic18)+TotalBuyOrders(magic19)+TotalBuyOrders(magic20);     
     int border03 = TotalBuyOrders(magic21)+TotalBuyOrders(magic22)+TotalBuyOrders(magic23)+TotalBuyOrders(magic24)+TotalBuyOrders(magic25)+TotalBuyOrders(magic26)+TotalBuyOrders(magic27)+TotalBuyOrders(magic28);
     int borders = border01+border02+border03;

     int sorder01 = TotalSellOrders(magic01)+TotalSellOrders(magic02)+TotalSellOrders(magic03)+TotalSellOrders(magic04)+TotalSellOrders(magic05)+TotalSellOrders(magic06)+TotalSellOrders(magic07)+TotalSellOrders(magic08)+TotalSellOrders(magic09)+TotalSellOrders(magic10);
     int sorder02 = TotalSellOrders(magic11)+TotalSellOrders(magic12)+TotalSellOrders(magic13)+TotalSellOrders(magic14)+TotalSellOrders(magic15)+TotalSellOrders(magic16)+TotalSellOrders(magic17)+TotalSellOrders(magic18)+TotalSellOrders(magic19)+TotalSellOrders(magic20);     
     int sorder03 = TotalSellOrders(magic21)+TotalSellOrders(magic22)+TotalSellOrders(magic23)+TotalSellOrders(magic24)+TotalSellOrders(magic25)+TotalSellOrders(magic26)+TotalSellOrders(magic27)+TotalSellOrders(magic28);
     int sorders = sorder01+sorder02+sorder03;     

     int orders = borders+sorders;

     double hbprofit01 = HBProfit(magic01)+HBProfit(magic02)+HBProfit(magic03)+HBProfit(magic04)+HBProfit(magic05)+HBProfit(magic06)+HBProfit(magic07)+HBProfit(magic08)+HBProfit(magic09)+HBProfit(magic10);
     double hbprofit02 = HBProfit(magic11)+HBProfit(magic12)+HBProfit(magic13)+HBProfit(magic14)+HBProfit(magic15)+HBProfit(magic16)+HBProfit(magic17)+HBProfit(magic18)+HBProfit(magic19)+HBProfit(magic20);     
     double hbprofit03 = HBProfit(magic21)+HBProfit(magic22)+HBProfit(magic23)+HBProfit(magic24)+HBProfit(magic25)+HBProfit(magic26)+HBProfit(magic27)+HBProfit(magic28);
     double hbprofit = hbprofit01+hbprofit02+hbprofit03;

     double hsprofit01 = HSProfit(magic01)+HSProfit(magic02)+HSProfit(magic03)+HSProfit(magic04)+HSProfit(magic05)+HSProfit(magic06)+HSProfit(magic07)+HSProfit(magic08)+HSProfit(magic09)+HSProfit(magic10);
     double hsprofit02 = HSProfit(magic11)+HSProfit(magic12)+HSProfit(magic13)+HSProfit(magic14)+HSProfit(magic15)+HSProfit(magic16)+HSProfit(magic17)+HSProfit(magic18)+HSProfit(magic19)+HSProfit(magic20);     
     double hsprofit03 = HSProfit(magic21)+HSProfit(magic22)+HSProfit(magic23)+HSProfit(magic24)+HSProfit(magic25)+HSProfit(magic26)+HSProfit(magic27)+HSProfit(magic28);
     double hsprofit = hsprofit01+hsprofit02+hsprofit03;   
     
     double hprofit = hbprofit+hsprofit;
     
     int hborder01 = HBuyOrders(magic01)+HBuyOrders(magic02)+HBuyOrders(magic03)+HBuyOrders(magic04)+HBuyOrders(magic05)+HBuyOrders(magic06)+HBuyOrders(magic07)+HBuyOrders(magic08)+HBuyOrders(magic09)+HBuyOrders(magic10);
     int hborder02 = HBuyOrders(magic11)+HBuyOrders(magic12)+HBuyOrders(magic13)+HBuyOrders(magic14)+HBuyOrders(magic15)+HBuyOrders(magic16)+HBuyOrders(magic17)+HBuyOrders(magic18)+HBuyOrders(magic19)+HBuyOrders(magic20);     
     int hborder03 = HBuyOrders(magic21)+HBuyOrders(magic22)+HBuyOrders(magic23)+HBuyOrders(magic24)+HBuyOrders(magic25)+HBuyOrders(magic26)+HBuyOrders(magic27)+HBuyOrders(magic28);
     int hborders = hborder01+hborder02+hborder03;

     int hsorder01 = HSellOrders(magic01)+HSellOrders(magic02)+HSellOrders(magic03)+HSellOrders(magic04)+HSellOrders(magic05)+HSellOrders(magic06)+HSellOrders(magic07)+HSellOrders(magic08)+HSellOrders(magic09)+HSellOrders(magic10);
     int hsorder02 = HSellOrders(magic11)+HSellOrders(magic12)+HSellOrders(magic13)+HSellOrders(magic14)+HSellOrders(magic15)+HSellOrders(magic16)+HSellOrders(magic17)+HSellOrders(magic18)+HSellOrders(magic19)+HSellOrders(magic20);     
     int hsorder03 = HSellOrders(magic21)+HSellOrders(magic22)+HSellOrders(magic23)+HSellOrders(magic24)+HSellOrders(magic25)+HSellOrders(magic26)+HSellOrders(magic27)+HSellOrders(magic28);
     int hsorders = hsorder01+hsorder02+hsorder03;

     int horders = hborders+hsorders;

     string ScreenStr;
     ScreenStr = StringConcatenate("Server : ",AccountServer()," Start Day_",StartDay, " , My Time : ",TimeToStr(TimeCurrent(),TIME_SECONDS)," 평가잔액 = ",AccountEquity()," Weak Value_",weakvalue," Strong Value_",strongvalue)+"\n";
     ScreenStr = ScreenStr + StringConcatenate("StopLevel : ",MarketInfo(Symbol(), MODE_STOPLEVEL)," , Freeze Level : ",MarketInfo(Symbol(), MODE_FREEZELEVEL)," , StopOut : ",AccountStopoutLevel(),"%, 목표수익 : ",XTP," 목표손실 : ",XSL)+"\n";

     ScreenStr = ScreenStr + StringConcatenate("USD Strong_",USD_Strong," Weak_",USD_Weak," USD_M1_RSI_",USD_RSI(1,1)," M5_RSI_",USD_RSI(5,1)," M15_RSI_",USD_RSI(15,1)," M30_RSI_",USD_RSI(30,1)," H1_RSI_",USD_RSI(60,1)," H4_RSI_",USD_RSI(240,1))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("EUR Strong_",EUR_Strong," Weak_",EUR_Weak," EUR_M1_RSI_",EUR_RSI(1,1)," M5_RSI_",EUR_RSI(5,1)," M15_RSI_",EUR_RSI(15,1)," M30_RSI_",EUR_RSI(30,1)," H1_RSI_",EUR_RSI(60,1)," H4_RSI_",EUR_RSI(240,1))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("GBP Strong_",GBP_Strong," Weak_",GBP_Weak," GBP_M1_RSI_",GBP_RSI(1,1)," M5_RSI_",GBP_RSI(5,1)," M15_RSI_",GBP_RSI(15,1)," M30_RSI_",GBP_RSI(30,1)," H1_RSI_",GBP_RSI(60,1)," H4_RSI_",GBP_RSI(240,1))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("JPY Strong_",JPY_Strong," Weak_",JPY_Weak," JPY_M1_RSI_",JPY_RSI(1,1)," M5_RSI_",JPY_RSI(5,1)," M15_RSI_",JPY_RSI(15,1)," M30_RSI_",JPY_RSI(30,1)," H1_RSI_",JPY_RSI(60,1)," H4_RSI_",JPY_RSI(240,1))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("CAD Strong_",CAD_Strong," Weak_",CAD_Weak," CAD_M1_RSI_",CAD_RSI(1,1)," M5_RSI_",CAD_RSI(5,1)," M15_RSI_",CAD_RSI(15,1)," M30_RSI_",CAD_RSI(30,1)," H1_RSI_",CAD_RSI(60,1)," H4_RSI_",CAD_RSI(240,1))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("CHF Strong_",CHF_Strong," Weak_",CHF_Weak," CHF_M1_RSI_",CHF_RSI(1,1)," M5_RSI_",CHF_RSI(5,1)," M15_RSI_",CHF_RSI(15,1)," M30_RSI_",CHF_RSI(30,1)," H1_RSI_",CHF_RSI(60,1)," H4_RSI_",CHF_RSI(240,1))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("AUD Strong_",AUD_Strong," Weak_",AUD_Weak," AUD_M1_RSI_",AUD_RSI(1,1)," M5_RSI_",AUD_RSI(5,1)," M15_RSI_",AUD_RSI(15,1)," M30_RSI_",AUD_RSI(30,1)," H1_RSI_",AUD_RSI(60,1)," H4_RSI_",AUD_RSI(240,1))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("NZD Strong_",NZD_Strong," Weak_",NZD_Weak," NZD_M1_RSI_",NZD_RSI(1,1)," M5_RSI_",NZD_RSI(5,1)," M15_RSI_",NZD_RSI(15,1)," M30_RSI_",NZD_RSI(30,1)," H1_RSI_",NZD_RSI(60,1)," H4_RSI_",NZD_RSI(240,1))+"\n";
     ScreenStr = ScreenStr + "=============================================================================================================================" + "\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair01_",symbol_01," TradeEnabled_",PairTrade01," 현재수익_$",Profit(magic01)," 매수건수_",TotalBuyOrders(magic01)," 매도건수_",TotalSellOrders(magic01)," 총수익_$",HistoryProfit(magic01)," 매수수익_$",HBProfit(magic01)," 매수건수_",HBuyOrders(magic01)," 매도수익_$",HSProfit(magic01)," 매도건수_",HSellOrders(magic01)," 총건수_",HOrders(magic01))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair02_",symbol_02," TradeEnabled_",PairTrade02," 현재수익_$",Profit(magic02)," 매수건수_",TotalBuyOrders(magic02)," 매도건수_",TotalSellOrders(magic02)," 총수익_$",HistoryProfit(magic02)," 매수수익_$",HBProfit(magic02)," 매수건수_",HBuyOrders(magic02)," 매도수익_$",HSProfit(magic02)," 매도건수_",HSellOrders(magic02)," 총건수_",HOrders(magic02))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair03_",symbol_03," TradeEnabled_",PairTrade03," 현재수익_$",Profit(magic03)," 매수건수_",TotalBuyOrders(magic03)," 매도건수_",TotalSellOrders(magic03)," 총수익_$",HistoryProfit(magic03)," 매수수익_$",HBProfit(magic03)," 매수건수_",HBuyOrders(magic03)," 매도수익_$",HSProfit(magic03)," 매도건수_",HSellOrders(magic03)," 총건수_",HOrders(magic03))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair04_",symbol_04," TradeEnabled_",PairTrade04," 현재수익_$",Profit(magic04)," 매수건수_",TotalBuyOrders(magic04)," 매도건수_",TotalSellOrders(magic04)," 총수익_$",HistoryProfit(magic04)," 매수수익_$",HBProfit(magic04)," 매수건수_",HBuyOrders(magic04)," 매도수익_$",HSProfit(magic04)," 매도건수_",HSellOrders(magic04)," 총건수_",HOrders(magic04))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair05_",symbol_05," TradeEnabled_",PairTrade05," 현재수익_$",Profit(magic05)," 매수건수_",TotalBuyOrders(magic05)," 매도건수_",TotalSellOrders(magic05)," 총수익_$",HistoryProfit(magic05)," 매수수익_$",HBProfit(magic05)," 매수건수_",HBuyOrders(magic05)," 매도수익_$",HSProfit(magic05)," 매도건수_",HSellOrders(magic05)," 총건수_",HOrders(magic05))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair06_",symbol_06," TradeEnabled_",PairTrade06," 현재수익_$",Profit(magic06)," 매수건수_",TotalBuyOrders(magic06)," 매도건수_",TotalSellOrders(magic06)," 총수익_$",HistoryProfit(magic06)," 매수수익_$",HBProfit(magic06)," 매수건수_",HBuyOrders(magic06)," 매도수익_$",HSProfit(magic06)," 매도건수_",HSellOrders(magic06)," 총건수_",HOrders(magic06))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair07_",symbol_07," TradeEnabled_",PairTrade07," 현재수익_$",Profit(magic07)," 매수건수_",TotalBuyOrders(magic07)," 매도건수_",TotalSellOrders(magic07)," 총수익_$",HistoryProfit(magic07)," 매수수익_$",HBProfit(magic07)," 매수건수_",HBuyOrders(magic07)," 매도수익_$",HSProfit(magic07)," 매도건수_",HSellOrders(magic07)," 총건수_",HOrders(magic07))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair08_",symbol_08," TradeEnabled_",PairTrade08," 현재수익_$",Profit(magic08)," 매수건수_",TotalBuyOrders(magic08)," 매도건수_",TotalSellOrders(magic08)," 총수익_$",HistoryProfit(magic08)," 매수수익_$",HBProfit(magic08)," 매수건수_",HBuyOrders(magic08)," 매도수익_$",HSProfit(magic08)," 매도건수_",HSellOrders(magic08)," 총건수_",HOrders(magic08))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair09_",symbol_09," TradeEnabled_",PairTrade09," 현재수익_$",Profit(magic09)," 매수건수_",TotalBuyOrders(magic09)," 매도건수_",TotalSellOrders(magic09)," 총수익_$",HistoryProfit(magic09)," 매수수익_$",HBProfit(magic09)," 매수건수_",HBuyOrders(magic09)," 매도수익_$",HSProfit(magic09)," 매도건수_",HSellOrders(magic09)," 총건수_",HOrders(magic09))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair10_",symbol_10," TradeEnabled_",PairTrade10," 현재수익_$",Profit(magic10)," 매수건수_",TotalBuyOrders(magic10)," 매도건수_",TotalSellOrders(magic10)," 총수익_$",HistoryProfit(magic10)," 매수수익_$",HBProfit(magic10)," 매수건수_",HBuyOrders(magic10)," 매도수익_$",HSProfit(magic10)," 매도건수_",HSellOrders(magic10)," 총건수_",HOrders(magic10))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair11_",symbol_11," TradeEnabled_",PairTrade11," 현재수익_$",Profit(magic11)," 매수건수_",TotalBuyOrders(magic11)," 매도건수_",TotalSellOrders(magic11)," 총수익_$",HistoryProfit(magic11)," 매수수익_$",HBProfit(magic11)," 매수건수_",HBuyOrders(magic11)," 매도수익_$",HSProfit(magic11)," 매도건수_",HSellOrders(magic11)," 총건수_",HOrders(magic11))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair12_",symbol_12," TradeEnabled_",PairTrade12," 현재수익_$",Profit(magic12)," 매수건수_",TotalBuyOrders(magic12)," 매도건수_",TotalSellOrders(magic12)," 총수익_$",HistoryProfit(magic12)," 매수수익_$",HBProfit(magic12)," 매수건수_",HBuyOrders(magic12)," 매도수익_$",HSProfit(magic12)," 매도건수_",HSellOrders(magic12)," 총건수_",HOrders(magic12))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair13_",symbol_13," TradeEnabled_",PairTrade13," 현재수익_$",Profit(magic13)," 매수건수_",TotalBuyOrders(magic13)," 매도건수_",TotalSellOrders(magic13)," 총수익_$",HistoryProfit(magic13)," 매수수익_$",HBProfit(magic13)," 매수건수_",HBuyOrders(magic13)," 매도수익_$",HSProfit(magic13)," 매도건수_",HSellOrders(magic13)," 총건수_",HOrders(magic13))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair14_",symbol_14," TradeEnabled_",PairTrade14," 현재수익_$",Profit(magic14)," 매수건수_",TotalBuyOrders(magic14)," 매도건수_",TotalSellOrders(magic14)," 총수익_$",HistoryProfit(magic14)," 매수수익_$",HBProfit(magic14)," 매수건수_",HBuyOrders(magic14)," 매도수익_$",HSProfit(magic14)," 매도건수_",HSellOrders(magic14)," 총건수_",HOrders(magic14))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair15_",symbol_15," TradeEnabled_",PairTrade15," 현재수익_$",Profit(magic15)," 매수건수_",TotalBuyOrders(magic15)," 매도건수_",TotalSellOrders(magic15)," 총수익_$",HistoryProfit(magic15)," 매수수익_$",HBProfit(magic15)," 매수건수_",HBuyOrders(magic15)," 매도수익_$",HSProfit(magic15)," 매도건수_",HSellOrders(magic15)," 총건수_",HOrders(magic15))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair16_",symbol_16," TradeEnabled_",PairTrade16," 현재수익_$",Profit(magic16)," 매수건수_",TotalBuyOrders(magic16)," 매도건수_",TotalSellOrders(magic16)," 총수익_$",HistoryProfit(magic16)," 매수수익_$",HBProfit(magic16)," 매수건수_",HBuyOrders(magic16)," 매도수익_$",HSProfit(magic16)," 매도건수_",HSellOrders(magic16)," 총건수_",HOrders(magic16))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair17_",symbol_17," TradeEnabled_",PairTrade17," 현재수익_$",Profit(magic17)," 매수건수_",TotalBuyOrders(magic17)," 매도건수_",TotalSellOrders(magic17)," 총수익_$",HistoryProfit(magic17)," 매수수익_$",HBProfit(magic17)," 매수건수_",HBuyOrders(magic17)," 매도수익_$",HSProfit(magic17)," 매도건수_",HSellOrders(magic17)," 총건수_",HOrders(magic17))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair18_",symbol_18," TradeEnabled_",PairTrade18," 현재수익_$",Profit(magic18)," 매수건수_",TotalBuyOrders(magic18)," 매도건수_",TotalSellOrders(magic18)," 총수익_$",HistoryProfit(magic18)," 매수수익_$",HBProfit(magic18)," 매수건수_",HBuyOrders(magic18)," 매도수익_$",HSProfit(magic18)," 매도건수_",HSellOrders(magic18)," 총건수_",HOrders(magic18))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair19_",symbol_19," TradeEnabled_",PairTrade19," 현재수익_$",Profit(magic19)," 매수건수_",TotalBuyOrders(magic19)," 매도건수_",TotalSellOrders(magic19)," 총수익_$",HistoryProfit(magic19)," 매수수익_$",HBProfit(magic19)," 매수건수_",HBuyOrders(magic19)," 매도수익_$",HSProfit(magic19)," 매도건수_",HSellOrders(magic19)," 총건수_",HOrders(magic19))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair20_",symbol_20," TradeEnabled_",PairTrade20," 현재수익_$",Profit(magic20)," 매수건수_",TotalBuyOrders(magic20)," 매도건수_",TotalSellOrders(magic20)," 총수익_$",HistoryProfit(magic20)," 매수수익_$",HBProfit(magic20)," 매수건수_",HBuyOrders(magic20)," 매도수익_$",HSProfit(magic20)," 매도건수_",HSellOrders(magic20)," 총건수_",HOrders(magic20))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair21_",symbol_21," TradeEnabled_",PairTrade21," 현재수익_$",Profit(magic21)," 매수건수_",TotalBuyOrders(magic21)," 매도건수_",TotalSellOrders(magic21)," 총수익_$",HistoryProfit(magic21)," 매수수익_$",HBProfit(magic21)," 매수건수_",HBuyOrders(magic21)," 매도수익_$",HSProfit(magic21)," 매도건수_",HSellOrders(magic21)," 총건수_",HOrders(magic21))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair22_",symbol_22," TradeEnabled_",PairTrade22," 현재수익_$",Profit(magic22)," 매수건수_",TotalBuyOrders(magic22)," 매도건수_",TotalSellOrders(magic22)," 총수익_$",HistoryProfit(magic22)," 매수수익_$",HBProfit(magic22)," 매수건수_",HBuyOrders(magic22)," 매도수익_$",HSProfit(magic22)," 매도건수_",HSellOrders(magic22)," 총건수_",HOrders(magic22))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair23_",symbol_23," TradeEnabled_",PairTrade23," 현재수익_$",Profit(magic23)," 매수건수_",TotalBuyOrders(magic23)," 매도건수_",TotalSellOrders(magic23)," 총수익_$",HistoryProfit(magic23)," 매수수익_$",HBProfit(magic23)," 매수건수_",HBuyOrders(magic23)," 매도수익_$",HSProfit(magic23)," 매도건수_",HSellOrders(magic23)," 총건수_",HOrders(magic23))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair24_",symbol_24," TradeEnabled_",PairTrade24," 현재수익_$",Profit(magic24)," 매수건수_",TotalBuyOrders(magic24)," 매도건수_",TotalSellOrders(magic24)," 총수익_$",HistoryProfit(magic24)," 매수수익_$",HBProfit(magic24)," 매수건수_",HBuyOrders(magic24)," 매도수익_$",HSProfit(magic24)," 매도건수_",HSellOrders(magic24)," 총건수_",HOrders(magic24))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair25_",symbol_25," TradeEnabled_",PairTrade25," 현재수익_$",Profit(magic25)," 매수건수_",TotalBuyOrders(magic25)," 매도건수_",TotalSellOrders(magic25)," 총수익_$",HistoryProfit(magic25)," 매수수익_$",HBProfit(magic25)," 매수건수_",HBuyOrders(magic25)," 매도수익_$",HSProfit(magic25)," 매도건수_",HSellOrders(magic25)," 총건수_",HOrders(magic25))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair26_",symbol_26," TradeEnabled_",PairTrade26," 현재수익_$",Profit(magic26)," 매수건수_",TotalBuyOrders(magic26)," 매도건수_",TotalSellOrders(magic26)," 총수익_$",HistoryProfit(magic26)," 매수수익_$",HBProfit(magic26)," 매수건수_",HBuyOrders(magic26)," 매도수익_$",HSProfit(magic26)," 매도건수_",HSellOrders(magic26)," 총건수_",HOrders(magic26))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair27_",symbol_27," TradeEnabled_",PairTrade27," 현재수익_$",Profit(magic27)," 매수건수_",TotalBuyOrders(magic27)," 매도건수_",TotalSellOrders(magic27)," 총수익_$",HistoryProfit(magic27)," 매수수익_$",HBProfit(magic27)," 매수건수_",HBuyOrders(magic27)," 매도수익_$",HSProfit(magic27)," 매도건수_",HSellOrders(magic27)," 총건수_",HOrders(magic27))+"\n";
     ScreenStr = ScreenStr + StringConcatenate("Pair28_",symbol_28," TradeEnabled_",PairTrade28," 현재수익_$",Profit(magic28)," 매수건수_",TotalBuyOrders(magic28)," 매도건수_",TotalSellOrders(magic28)," 총수익_$",HistoryProfit(magic28)," 매수수익_$",HBProfit(magic28)," 매수건수_",HBuyOrders(magic28)," 매도수익_$",HSProfit(magic28)," 매도건수_",HSellOrders(magic28)," 총건수_",HOrders(magic28))+"\n";
     ScreenStr = ScreenStr + "=============================================================================================================================" + "\n";
                         
     ScreenStr = ScreenStr + StringConcatenate("현재수익 : $",profits," Buy : $",bprofits," / Sell : $",sprofits,", New Orders : ",orders,"건 = Buy ",borders,"건 / Sell",sorders,"건") + "\n";
     ScreenStr = ScreenStr + StringConcatenate("Total Profits : $",hprofit,", Buy : $",hbprofit,", Sell : $",hsprofit,", Total Orders : ",horders,"건 = Total Buy ",hborders,"건 / Total Sell",hsorders,"건");
     Comment(ScreenStr);
   
     return(0);

}   // EA 종료


//********************************************************************
//| Allow One Action Per Bar                                         |
//********************************************************************
// 현재 바에서 하나만 주문할때 사용하는 함수

bool NewBar()
{  // 0
   if(PreviousBarTime<Time[0])
   {  // 1
      PreviousBarTime=Time[0];
      return(true);
   }  // 1
   return(false);
}  // 0

//********************************************************************
// Max Spread Limitation 설정함수                                    |
//********************************************************************

bool TradeEnable(string symbols) {
    if(MarketInfo(symbols,MODE_ASK)-MarketInfo(symbols,MODE_BID) > MaxSpread*mypoint*MarketInfo(symbols,MODE_POINT)) return(false);
    else return(true);
   }

//********************************************************************
//| 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(),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(),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(),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(),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(),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(),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

/*

//********************************************************************
//| Trailing Stop                                                    |
//********************************************************************

void MoveTrailingStop()
{
   int ct,totl=OrdersTotal();
   RefreshRates();
if (OrdersTotal() > 0) {
   for(ct=0;ct<totl;ct++)
   {
      OrderSelect(ct,SELECT_BY_POS,MODE_TRADES);


      if(OrderType()==OP_BUY && OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
         {
            if( TrailingStop>0 && Bid>NormalizeDouble(OrderOpenPrice()+TrailingStop*mypoint*Point,Digits) )  
            {                 
               if((NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-mypoint*TrailingStop*Point,Digits))||(OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid-mypoint*TrailingStop*Point,Digits),OrderTakeProfit(),0,Blue);
                  return(0);
               }
            }
         }
      if(OrderType()==OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
         {
            if( TrailingStop>0 && Ask<NormalizeDouble(OrderOpenPrice()-TrailingStop*mypoint*Point,Digits) )  
            {                 
               if((NormalizeDouble(OrderStopLoss(),Digits)>(NormalizeDouble(Ask+(mypoint*TrailingStop*Point),Digits)))||(OrderStopLoss()==0))
               {
                  OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask+(mypoint*TrailingStop*Point),Digits),OrderTakeProfit(),0,Red);
                  return(0);

            }
         }
      }
   }
}

}


//********************************************************************
//| Break Even Strategy                                              |
//********************************************************************

void MoveBreakEven()
{
   int cnt,total=OrdersTotal();
   RefreshRates();
if (OrdersTotal() > 0) {
   for(cnt=0;cnt<total;cnt++)
   {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);

      if( OrderType()<=OP_SELL && OrderSymbol()==Symbol() && OrderMagicNumber()==magic )
      {
         if(OrderType()==OP_BUY)
         {
            if(BreakEven>0)
            {
               if(NormalizeDouble((Bid-OrderOpenPrice()),Digits) > BreakEven*mypoint*Point)
               {
                  if(NormalizeDouble((OrderStopLoss()-OrderOpenPrice()),Digits) < 0)
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()+BreakPoint*mypoint*Point,Digits),OrderTakeProfit(),0,Blue);
                     return(0);
                  }
               }
            }
         }
         else
         {
            if(BreakEven>0)
            {
               if(NormalizeDouble((OrderOpenPrice()-Ask),Digits) > BreakEven*mypoint*Point)
               {
                  if(NormalizeDouble((OrderOpenPrice()-OrderStopLoss()),Digits) < 0)
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(OrderOpenPrice()-BreakPoint*mypoint*Point,Digits),OrderTakeProfit(),0,Red);
                     return(0);
                  }
               }
            }
         }
      }
   }
}

}

*/

//********************************************************************
//| 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 종료

}     // 함수 종료  

//********************************************************************
//| 주문 함수 (OpenOrder)                                            |
//********************************************************************

int OpenOrder( string SymbolName, int CmdType, double Lots, double Order_price, 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 Attempts = 0;
  int TryNumber = 0;
  int ErrorCodes;
  int Slips = 0;
  double Vol = 0;
  string Comments;
  color CLRs;
      
  if (CmdType == OP_BUY) Comments = "샀어_"+Commentary;
  if (CmdType == OP_SELL) Comments = "팔았어_"+Commentary;

  if (CmdType == OP_BUY) CLRs = Red;
  if (CmdType == OP_SELL) CLRs = Blue;

  while (Ticket <= 0)  {
     TryNumber++;
     ErrorCodes = GetLastError();
     Print("Loop:  Trying to send Order . . again, # ", TryNumber);
     Ticket = OrderSend(SymbolName, CmdType, Lots, Order_price, Slippages, StopLosses, TakeProfit,Comments,magic,0,CLRs); 
     }

  OrderSelect(OrdersTotal() - 1, SELECT_BY_POS, MODE_TRADES);
                     
    if (OrderSymbol() == SymbolName)  
    {
      Slips = OrderSlipPage(Order_price);
      Ticket = OrderTicket();
      Vol = OrderLots();
    }
    
  Print(Ticket, " = OrderSend( ", Comments,", ", SymbolName, ", ", OrderTypeToString[CmdType], ", ", Lots, ", ", DoubleToStr(Order_price, 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);
}

//********************************************************************
//| RSI Average Function                                             |
//********************************************************************

double USD_RSI(int TF,int shifts) {

string symbol_1 = "EURUSD" + subfix;
string symbol_2 = "GBPUSD" + subfix;
string symbol_3 = "AUDUSD" + subfix;
string symbol_4 = "NZDUSD" + subfix;
string symbol_5 = "USDJPY" + subfix;
string symbol_6 = "USDCHF" + subfix;
string symbol_7 = "USDCAD" + subfix;

   double rsi_pair1 = 100 - iRSI(symbol_1, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair2 = 100 - iRSI(symbol_2, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair3 = 100 - iRSI(symbol_3, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair4 = 100 - iRSI(symbol_4, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair5 = iRSI(symbol_5, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair6 = iRSI(symbol_6, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair7 = iRSI(symbol_7, TF, periods, PRICE_WEIGHTED, shifts);

   double rsi_sum = rsi_pair1 + rsi_pair2 + rsi_pair3 + rsi_pair4 + rsi_pair5 + rsi_pair6 + rsi_pair7;
   double results = NormalizeDouble(rsi_sum / 7.0,2);
   
   return (results);
}

double EUR_RSI(int TF,int shifts) {

string symbol_1 = "EURUSD" + subfix;
string symbol_2 = "EURGBP" + subfix;
string symbol_3 = "EURJPY" + subfix;
string symbol_4 = "EURCAD" + subfix;
string symbol_5 = "EURCHF" + subfix;
string symbol_6 = "EURAUD" + subfix;
string symbol_7 = "EURNZD" + subfix;

   double rsi_pair1 = iRSI(symbol_1, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair2 = iRSI(symbol_2, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair3 = iRSI(symbol_3, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair4 = iRSI(symbol_4, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair5 = iRSI(symbol_5, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair6 = iRSI(symbol_6, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair7 = iRSI(symbol_7, TF, periods, PRICE_WEIGHTED, shifts);

   double rsi_sum = rsi_pair1 + rsi_pair2 + rsi_pair3 + rsi_pair4 + rsi_pair5 + rsi_pair6 + rsi_pair7;
   double results = NormalizeDouble(rsi_sum / 7.0,2);
   
   return (results);
}

double GBP_RSI(int TF,int shifts) {

string symbol_1 = "GBPUSD" + subfix;
string symbol_2 = "EURGBP" + subfix;
string symbol_3 = "GBPJPY" + subfix;
string symbol_4 = "GBPCAD" + subfix;
string symbol_5 = "GBPCHF" + subfix;
string symbol_6 = "GBPAUD" + subfix;
string symbol_7 = "GBPNZD" + subfix;

   double rsi_pair1 = iRSI(symbol_1, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair2 = 100 - iRSI(symbol_2, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair3 = iRSI(symbol_3, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair4 = iRSI(symbol_4, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair5 = iRSI(symbol_5, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair6 = iRSI(symbol_6, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair7 = iRSI(symbol_7, TF, periods, PRICE_WEIGHTED, shifts);

   double rsi_sum = rsi_pair1 + rsi_pair2 + rsi_pair3 + rsi_pair4 + rsi_pair5 + rsi_pair6 + rsi_pair7;
   double results = NormalizeDouble(rsi_sum / 7.0,2);
   
   return (results);
}

double CHF_RSI(int TF,int shifts) {

string symbol_1 = "USDCHF" + subfix;
string symbol_2 = "EURCHF" + subfix;
string symbol_3 = "GBPCHF" + subfix;
string symbol_4 = "CADCHF" + subfix;
string symbol_5 = "CHFJPY" + subfix;
string symbol_6 = "AUDCHF" + subfix;
string symbol_7 = "NZDCHF" + subfix;

   double rsi_pair1 = 100 - iRSI(symbol_1, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair2 = 100 - iRSI(symbol_2, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair3 = 100 - iRSI(symbol_3, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair4 = 100 - iRSI(symbol_4, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair5 = iRSI(symbol_5, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair6 = 100 - iRSI(symbol_6, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair7 = 100 - iRSI(symbol_7, TF, periods, PRICE_WEIGHTED, shifts);

   double rsi_sum = rsi_pair1 + rsi_pair2 + rsi_pair3 + rsi_pair4 + rsi_pair5 + rsi_pair6 + rsi_pair7;
   double results = NormalizeDouble(rsi_sum / 7.0,2);
   
   return (results);
}

double JPY_RSI(int TF,int shifts) {

string symbol_1 = "USDJPY" + subfix;
string symbol_2 = "EURJPY" + subfix;
string symbol_3 = "GBPJPY" + subfix;
string symbol_4 = "CADJPY" + subfix;
string symbol_5 = "CHFJPY" + subfix;
string symbol_6 = "AUDJPY" + subfix;
string symbol_7 = "NZDJPY" + subfix;

   double rsi_pair1 = 100 - iRSI(symbol_1, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair2 = 100 - iRSI(symbol_2, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair3 = 100 - iRSI(symbol_3, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair4 = 100 - iRSI(symbol_4, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair5 = 100 - iRSI(symbol_5, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair6 = 100 - iRSI(symbol_6, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair7 = 100 - iRSI(symbol_7, TF, periods, PRICE_WEIGHTED, shifts);

   double rsi_sum = rsi_pair1 + rsi_pair2 + rsi_pair3 + rsi_pair4 + rsi_pair5 + rsi_pair6 + rsi_pair7;
   double results = NormalizeDouble(rsi_sum / 7.0,2);
   
   return (results);
}


double CAD_RSI(int TF,int shifts) {

string symbol_1 = "USDCAD" + subfix;
string symbol_2 = "EURCAD" + subfix;
string symbol_3 = "GBPCAD" + subfix;
string symbol_4 = "AUDCAD" + subfix;
string symbol_5 = "CADCHF" + subfix;
string symbol_6 = "CADJPY" + subfix;
string symbol_7 = "NZDCAD" + subfix;

   double rsi_pair1 = 100 - iRSI(symbol_1, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair2 = 100 - iRSI(symbol_2, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair3 = 100 - iRSI(symbol_3, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair4 = 100 - iRSI(symbol_4, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair5 = iRSI(symbol_5, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair6 = iRSI(symbol_6, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair7 = 100 - iRSI(symbol_7, TF, periods, PRICE_WEIGHTED, shifts);

   double rsi_sum = rsi_pair1 + rsi_pair2 + rsi_pair3 + rsi_pair4 + rsi_pair5 + rsi_pair6 + rsi_pair7;
   double results = NormalizeDouble(rsi_sum / 7.0,2);
   
   return (results);
}

double AUD_RSI(int TF,int shifts) {

string symbol_1 = "AUDUSD" + subfix;
string symbol_2 = "EURAUD" + subfix;
string symbol_3 = "GBPAUD" + subfix;
string symbol_4 = "AUDCAD" + subfix;
string symbol_5 = "AUDCHF" + subfix;
string symbol_6 = "AUDJPY" + subfix;
string symbol_7 = "AUDNZD" + subfix;

   double rsi_pair1 = iRSI(symbol_1, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair2 = 100 - iRSI(symbol_2, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair3 = 100 - iRSI(symbol_3, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair4 = iRSI(symbol_4, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair5 = iRSI(symbol_5, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair6 = iRSI(symbol_6, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair7 = iRSI(symbol_7, TF, periods, PRICE_WEIGHTED, shifts);

   double rsi_sum = rsi_pair1 + rsi_pair2 + rsi_pair3 + rsi_pair4 + rsi_pair5 + rsi_pair6 + rsi_pair7;
   double results = NormalizeDouble(rsi_sum / 7.0,2);
   
   return (results);
}

double NZD_RSI(int TF,int shifts) {

string symbol_1 = "NZDUSD" + subfix;
string symbol_2 = "EURNZD" + subfix;
string symbol_3 = "GBPNZD" + subfix;
string symbol_4 = "NZDCAD" + subfix;
string symbol_5 = "NZDCHF" + subfix;
string symbol_6 = "NZDJPY" + subfix;
string symbol_7 = "AUDNZD" + subfix;

   double rsi_pair1 = iRSI(symbol_1, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair2 = 100 - iRSI(symbol_2, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair3 = 100 - iRSI(symbol_3, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair4 = iRSI(symbol_4, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair5 = iRSI(symbol_5, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair6 = iRSI(symbol_6, TF, periods, PRICE_WEIGHTED, shifts);
   double rsi_pair7 = 100 - iRSI(symbol_7, TF, periods, PRICE_WEIGHTED, shifts);

   double rsi_sum = rsi_pair1 + rsi_pair2 + rsi_pair3 + rsi_pair4 + rsi_pair5 + rsi_pair6 + rsi_pair7;
   double results = NormalizeDouble(rsi_sum / 7.0,2);
   
   return (results);
}

//********************************************************************
//| 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(),MarketInfo(OrderSymbol(),MODE_BID),5,Red);
             break;

             case OP_SELL : resultall = OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5, Blue);
             }    //switch

     if(resultall == false) {  // 17
     Print("Order ", OrderTicket(), " failed to close. Error:", GetLastError() );
                         }  // 17

       }  // 16
   }   // 15
}  // 0

+ Recent posts