//+---------------------------------------------------------------------+

//+---------------------------------------------------------------------+
#property copyright "Copyright used to be 2008, Orest @ ForexFactory; now plus Charvo"
#property link      ""

// this EA based on T101 v1.18 Orest version
// many bugs from v1.18 were killed, and i believe more will too.

// the EA will trade based on:
/*
   1. Short/Long Strong
   2. BI indi cross
   3. GJ or leading pair break away from fractals (check geoff's);
   
   4. this is NOT done yet, MACD signal on BI indi...
*/

// rev 1.15 [1 Dec 2009] : Added handling 5 digits broker like AlpariUK (Skyline - glicciardello@gmail.com)
// rev 1.16 [7 Dec 2009] : Made Numbers/Arrows on the right of the columns as ADX indicator data
// rev 1.17 [6 Feb 2010] : Made Customizable (Open Time) columns
// rev 1.18 [9 Feb 2010] : Made Customizable (Close Time) columns, fixed weekly columns, added Open BUY/SELL now

// ---------------- Charvo Added EXT Variables ---------------------
extern string note4 = "Permit/Pause Trading";
extern bool  OK2Trade = true;
// ---------------- Charvo Added EXT Variables ---------------------
extern string Buy_currency_pairs = "----- List of Buy currency pairs -----";
extern string Buy_pair_1 = "USDCHF";         //"USDCHF";// "USDJPY";
extern bool  Show_buy_direction_1 = false; //   true;
extern string Buy_pair_2 = "EURGBP";  //"EURGBP";//  "EURUSD";
extern bool  Show_buy_direction_2 = false;//  true;

extern string Buy_pair_3 = "GBPUSD";   //"GBPUSD"; //  "EURCHF";
extern bool  Show_buy_direction_3 = false; //  true;

extern string Buy_pair_4 = "NZDUSD";  //  "NZDUSD" ;//"GBPJPY";
extern bool  Show_buy_direction_4 = false; //true;

extern string Buy_pair_5 = "EURJPY" ; //"USDCAD";
extern bool  Show_buy_direction_5 = false;

extern string Buy_pair_6 = "AUDJPY";// "CADJPY";
extern bool  Show_buy_direction_6 = false;

extern string Buy_pair_7 = "GBPJPY" ; //"AUDUSD";
extern bool  Show_buy_direction_7 = false;

extern string Sell_currency_pairs = "----- List of Sell currency pairs -----";
extern string Sell_pair_1 = "AUDUSD"; // "AUDUSD"; //"EURJPY";
extern bool  Show_sell_direction_1 = false; //true;

extern string Sell_pair_2 = "NZDJPY"; // "GBPUSD";
extern bool  Show_sell_direction_2 = false;

extern string Sell_pair_3 = "CHFJPY"; //"EURGBP";
extern bool  Show_sell_direction_3 = false;

extern string Sell_pair_4 = "USDJPY";//"GBPCHF";
extern bool  Show_sell_direction_4 = false;

extern string Sell_pair_5 = "EURUSD";//"EURUSD";//"CHFJPY";
extern bool  Show_sell_direction_5 = false; //true;
 
extern string Sell_pair_6 = "EURCHF";//"EURCHF";//"USDCHF";
extern bool  Show_sell_direction_6 = false; //true;

extern string Sell_pair_7 = "GBPCHF"; //"GBPCHF";//"AUDJPY";
extern bool  Show_sell_direction_7 = false; //true;

extern string Columns_0 = "======= Columns Customization ========== ";

extern string Columns_1 = "1 - 30d,      2 - 21d,  3 - 14d,  4-This week";
extern string Columns_2 = "5 - This day, 6 - 12h,  7 - 8h,   8 - 4h";
extern string Columns_3 = "9 - 2h,       10 - 1h,  11 - 30min";
extern string Columns_4 = "12 - 15min,   13 - 5min,14 - 1min,15 - Custom";

extern int column1 = 3;
extern datetime Time_Open1  = D'2010.01.01 00:00';
extern datetime Time_Close1 = D'0000.00.00 00:00';
extern int column2 = 4;
extern datetime Time_Open2 = D'2010.01.01 00:00';
extern datetime Time_Close2 = D'0000.00.00 00:00';
extern int column3 = 5;
extern datetime Time_Open3 = D'2010.01.01 00:00';
extern datetime Time_Close3 = D'0000.00.00 00:00';
extern int column4 = 7;
extern datetime Time_Open4 = D'2010.01.01 00:00';
extern datetime Time_Close4 = D'0000.00.00 00:00';
extern int column5 = 9;
extern datetime Time_Open5 = D'2010.01.01 00:00';
extern datetime Time_Close5 = D'0000.00.00 00:00';
extern int column6 = 12;
extern datetime Time_Open6 = D'2010.01.01 00:00';
extern datetime Time_Close6 = D'0000.00.00 00:00';
extern int column7 = 0;
extern datetime Time_Open7 = D'2010.01.01 00:00';
extern datetime Time_Close7 = D'0000.00.00 00:00';

extern string Trade_mgmt = "======= Trade management ========== ";
extern int MAGIC = 123456;
extern bool Protect_Account = true;

// ---------------- Charvo Added EXT Variables ---------------------
extern string note2 = "pip-dime-->10;pip-cent,use 100.";
extern int Lot_factor = 10;
extern string note3 = "numbers below are for standard lot.";
// ---------------- Charvo Added EXT Variables ---------------------

extern double BASKET_STOPLOSS = -600.0;
extern double BASKET_TAKE_PROFIT = 3000.0;
extern double Lot = 0.01;
extern int Slippage = 30;
extern string Trade_mgmt1 = "======= Business Rules ========== ";
extern bool   Rules_ON    = true;
extern int    Timeframe   = 4;      // from 1 to 14 see columns customization; if 0 - trade wouldn't open
extern string Pair_to_Follow = "Buy N SELL";  // "BUY" - any BUY pair, "SELL" - any sell pair
extern int    Upper_Slot_to_occupy = 1;   // Slot# the pair shoud occupy, if 0 - a trade woldn't open
extern int    Lower_Slot_to_occupy = 14;   // Slot# the pair shoud occupy, if 0 - a trade woldn't open
extern double Profit_in_Pips_more_then = 0;   // how much a pair should gain in that slot.
extern double Profit_in_Pips_less_then = 0;   // how much a pair should loose in that slot.
extern bool   Open_Short               = true; // Open SHORT trade
extern bool   Open_Long                = true; // Open LONG trade
extern bool   Open_On_Strong_Signal    = true; // Open Only if SiGNAL is STRONG

// ---------------- Charvo Added EXT Variables ---------------------

extern string UserComment2="if false,open 12 pos";
extern bool   AntiPos = false;
extern string UserComment3="+Use standard pair name+";
extern string LoserPair1 = "USDCHF";
extern string LoserPair2 = "GBPCHF";

extern bool   normalpairs = true;
extern string pair_suffix = "";
extern int    BuyAllfMA = 5;
extern int    BuyAllsMA = 10;
extern int    buyallTF = 60;
extern int    lookback4X = 2;

extern string note1 = "Leading Pair is?";
extern string LeadingPair = "GBPJPY"; //"EURJPY";
extern bool   UseSR = true;
extern int    SRTF = 15;
// ---------------- Charvo Added EXT Variables ---------------------


bool Stop_Rules ;


double GBPUSDm, EURGBPm, GBPJPYm, USDCHFm, NZDUSDm, AUDJPYm, EURJPYm;
double EURUSDm, USDJPYm, AUDUSDm, NZDJPYm, GBPCHFm, CHFJPYm, EURCHFm;

double blue, red, blue_usd, red_usd, blue_jpy, red_jpy, blue_oth, red_oth ;

double GBPUSDm_now,EURGBPm_now,GBPJPYm_now,USDCHFm_now,NZDUSDm_now,AUDJPYm_now,EURJPYm_now;
double EURUSDm_now,USDJPYm_now,AUDUSDm_now,NZDJPYm_now,GBPCHFm_now,CHFJPYm_now,EURCHFm_now;

double GBPUSDm_pips, EURGBPm_pips, GBPJPYm_pips, USDCHFm_pips, NZDUSDm_pips,
       AUDJPYm_pips, EURJPYm_pips;

double EURUSDm_pips, USDJPYm_pips,AUDUSDm_pips,NZDJPYm_pips,GBPCHFm_pips,
       CHFJPYm_pips,EURCHFm_pips;

double GBPUSDm_pips_5min,EURGBPm_pips_5min,GBPJPYm_pips_5min,USDCHFm_pips_5min,NZDUSDm_pips_5min=0,
       AUDJPYm_pips_5min,EURJPYm_pips_5min;

double EURUSDm_pips_5min,USDJPYm_pips_5min,AUDUSDm_pips_5min,NZDJPYm_pips_5min,GBPCHFm_pips_5min,
       CHFJPYm_pips_5min,EURCHFm_pips_5min;

int pairs_num = 0;

bool loop_running = false;

string short_name;
int wnd;
int companion;


int Columns[7];
string Titles[7];
datetime TimeOpenings[7];
datetime TimeClosings[7];

int ECN;
int main_font_size = 9;

int buys_x = 0;
int buys_y = 0;

int buys_x_all = 0;
int buys_y_all = 0;

int buys_x_off = 0;
int buys_y_off = 0;

int close_all_x = 0;
int close_all_y = 0;

int sells_x = 0;
int sells_y = 0;

int sells_x_all = 0;
int sells_y_all = 0;

int sells_x_off = 0;
int sells_y_off = 0;

int y_coord = 0;
int AllLongSignal;
int AllShortSignal;

int BusinessRules_Long;
int BusinessRules_Short;

bool run_print = true;
double locked_profit = 0;
double step_profit =0;
string PairsNames1[14];   


// ---------------- Charvo Added Variables ---------------------


// ---------------- Charvo Added Variables ---------------------


int init()
{
      
   short_name="T101_v.1.18_Orest@ForexFactory";
   IndicatorShortName(short_name);

   TimeOpenings[0] = Time_Open1;
   TimeOpenings[1] = Time_Open2;
   TimeOpenings[2] = Time_Open3;
   TimeOpenings[3] = Time_Open4;
   TimeOpenings[4] = Time_Open5;
   TimeOpenings[5] = Time_Open6;
   TimeOpenings[6] = Time_Open7;

   TimeClosings[0] = Time_Close1;
   TimeClosings[1] = Time_Close2;
   TimeClosings[2] = Time_Close3;
   TimeClosings[3] = Time_Close4;
   TimeClosings[4] = Time_Close5;
   TimeClosings[5] = Time_Close6;
   TimeClosings[6] = Time_Close7;

   Columns[0] = column1;
   Columns[1] = column2;
   Columns[2] = column3;
   Columns[3] = column4;
   Columns[4] = column5;
   Columns[5] = column6;
   Columns[6] = column7;

   for (int i=0; i<7; i++)
   {
      if (Columns[i]==1)
          Titles[i]="30d ago   ADX"; 
      else if (Columns[i]==2)
         Titles[i]= "21d ago   ADX";
      else if (Columns[i]==3)
         Titles[i]= "14d ago   ADX";
      else if (Columns[i]==4)
         Titles[i]= "This Week ADX";
      else if (Columns[i]==5)
         Titles[i]= "This Day  ADX";
      else if (Columns[i]==6)
         Titles[i]= "12h ago   ADX";
      else if (Columns[i]==7)
         Titles[i]= "8h ago    ADX";
      else if (Columns[i]==8)
         Titles[i]= "4 hours ago ADX";
      else if (Columns[i]==9)
         Titles[i]= "2 hour ago ADX";
      else if (Columns[i]==10)
         Titles[i]= "1 hour ago ADX";
      else if (Columns[i]==11)
         Titles[i]= "30 min ago ADX";
      else if (Columns[i]==12)
         Titles[i]= "15 min ago ADX";
      else if (Columns[i]==13)
         Titles[i]= "5 min ago  ADX";
      else if (Columns[i]==14)
         Titles[i]= "1 min ago  ADX";
      else if (Columns[i]==15)
         Titles[i]= TimeToStr(TimeOpenings[i],TIME_DATE)+" "+TimeToStr(TimeOpenings[i],TIME_MINUTES);
   }
   
   Stop_Rules = false;

   return(0);
}

int deinit()
{
 for (int i=1; i<=7; i++)
   delete_objects(i);
   
   return(0);
}

// @@@@@@@@@@@@@@@@@@@@@ START OF START() @@@@@@@@@@@@@@@@@@@@@
int start()
{
  // Broker 4/5 digits
  ECN = 1;
  if ( Digits == 3 || Digits == 5 ) { ECN = 10; }       
  //if (loop_running) return(0);
  //while (true)  {

   double PLArray1[14];   
   double PLArray2[14];   
   double PLArray3[14];   
   double PLArray4[14];   
   double PLArray5[14];   
   double PLArray6[14];   
   double PLArray7[14];   

   string PairsNames2[14];   
   string PairsNames3[14];   
   string PairsNames4[14];   
   string PairsNames5[14];   
   string PairsNames6[14];   
   string PairsNames7[14];   

   loop_running = true;

   RefreshRates();

   AllLongSignal = 1;
   AllShortSignal= 1;

   if (Rules_ON) {
      BusinessRules_Long  = 0;
      BusinessRules_Short = 0;
   }

   //if (run_print)
   //Print ("Begin...");

   for (int i=0; i<7; i++)
   {
      pairs_num = 0;

      //delete_objects(Columns[i]);
      if (Columns[i]>0) {
         run_statistics_longs(Columns[i], TimeOpenings[i],TimeClosings[i]);  
         run_statistics_shorts(Columns[i], TimeOpenings[i],TimeClosings[i]); 
      }
      
      if (i==0 && Columns[i]>0)
         draw_objects(i,PairsNames1,PLArray1,TimeOpenings[i],Columns[i],TimeClosings[i]);
      else if (i==1 && Columns[i]>0)
         draw_objects(i,PairsNames2,PLArray2,TimeOpenings[i],Columns[i],TimeClosings[i]); 
      else if (i==2 && Columns[i]>0)
         draw_objects(i,PairsNames3,PLArray3,TimeOpenings[i],Columns[i],TimeClosings[i]); 
      else if (i==3 && Columns[i]>0)
         draw_objects(i,PairsNames4,PLArray4,TimeOpenings[i],Columns[i],TimeClosings[i]); 
      else if (i==4 && Columns[i]>0)
         draw_objects(i,PairsNames5,PLArray5,TimeOpenings[i],Columns[i],TimeClosings[i]); 
      else if (i==5 && Columns[i]>0)
         draw_objects(i,PairsNames6,PLArray6,TimeOpenings[i],Columns[i],TimeClosings[i]); 
      else if (i==6 && Columns[i]>0)
         draw_objects(i,PairsNames7,PLArray7,TimeOpenings[i],Columns[i],TimeClosings[i]); 
   }

   show_buy_sell(y_coord);
   Sleep(500);

//}
 
return(0);
}
// @@@@@@@@@@@@@@@@@@@@@ END OF START() @@@@@@@@@@@@@@@@@@@@@

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
void run_statistics_longs(int week_back, datetime Time_Open, datetime Time_Close)
{

int tf=0;
int bars_back = 0;
int closing_tf = PERIOD_H1;

datetime period_starts_5min;
int bars_period_starts_5min;
double open_5min;
double spread;


GBPUSDm =0; EURGBPm =0; GBPJPYm=0; USDCHFm=0; NZDUSDm=0; AUDJPYm=0; EURJPYm=0;

GBPUSDm_now =0; EURGBPm_now = 0; GBPJPYm_now =0; USDCHFm_now =0; NZDUSDm_now = 0; AUDJPYm_now=0;EURJPYm_now=0;

GBPUSDm_pips = 0; EURGBPm_pips=0; GBPJPYm_pips = 0; USDCHFm_pips =0; NZDUSDm_pips=0;
AUDJPYm_pips = 0; EURJPYm_pips=0;

GBPUSDm_pips_5min = 0; EURGBPm_pips_5min=0; GBPJPYm_pips_5min = 0; USDCHFm_pips_5min =0; NZDUSDm_pips_5min=0;
AUDJPYm_pips_5min = 0; EURJPYm_pips_5min=0;

 if (week_back==1)  // 30 days ago
 {
     tf = PERIOD_D1;
     bars_back = 29;
 }    
 else if (week_back==2) // 21 days ago
 {
     tf = PERIOD_D1;
     bars_back = 20;
 }    
 else if (week_back==3) // 14 days ago
 {
     tf = PERIOD_D1;
     bars_back = 13;
    
 }    
 else if (week_back==4) // this week
 {
     tf = PERIOD_W1;
     bars_back = 0;
 }    
 else if (week_back==5) // this day
 {
     tf = PERIOD_D1;
     bars_back = 0;
 }
else if (week_back==6) // 12 hours ago
 {
     tf = PERIOD_M1;
     bars_back = 719;
 }
else if (week_back==7) // 8 hours ago
 {
     tf = PERIOD_M1;
     bars_back = 479;
 }
else if (week_back==8) // 4 hours ago
 {
     tf = PERIOD_M1;
     bars_back = 239;
 }
else if (week_back==9) // 2 hour ago
 {
     tf = PERIOD_M1;
     bars_back = 119;
 }
else if (week_back==10) // hour ago
 {
     tf = PERIOD_M1;
     bars_back = 59;
 }
else if (week_back==11) // 30 min ago
 {
     tf = PERIOD_M1;
     bars_back = 29;
 }
else if (week_back==12) // 15min ago
 {
     tf = PERIOD_M1;
     bars_back = 14;
 }
else if (week_back==13) // 5min ago
 {
     tf = PERIOD_M1;
     bars_back = 4;
 }
else if (week_back==14) // 1 min ago
 {
     tf = PERIOD_M1;
     bars_back = 0;
 }
else if (week_back==15) // Custom
 {
     tf = PERIOD_H1;
     bars_back = 0;
 }
 
 datetime Opentime;
 datetime CloseTime;
  
if (StringLen(Buy_pair_1)>0  && iOpen(Buy_pair_1, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Buy_pair_1, MODE_SPREAD)/ECN*dPoint(Buy_pair_1),0);
  
   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Buy_pair_1, tf, Time_Open);
         GBPUSDm      = iOpen(Buy_pair_1, tf, bars_period_starts_5min);
   }      
   else {
         period_starts_5min  = iTime(Buy_pair_1, tf, bars_back)+60;
         
         bars_period_starts_5min = iBarShift(Buy_pair_1, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Buy_pair_1, tf, bars_back);
         GBPUSDm      =    iOpen(Buy_pair_1,PERIOD_M1,iBarShift(Buy_pair_1, PERIOD_M1, Opentime));
   }      

   open_5min    = iOpen(Buy_pair_1, PERIOD_M1, bars_period_starts_5min);

   if (Time_Close==978307200)
      GBPUSDm_now  = MarketInfo(Buy_pair_1, MODE_ASK);
   else {
      bars_period_starts_5min = iBarShift(Buy_pair_1, closing_tf, Time_Close);
      //Print (bars_period_starts_5min);
      
      GBPUSDm_now      = iClose(Buy_pair_1, closing_tf, bars_period_starts_5min);
   }   

   GBPUSDm_pips = NormalizeDouble((GBPUSDm_now-GBPUSDm-spread)/dPoint(Buy_pair_1),0);

   GBPUSDm_pips_5min = (open_5min - GBPUSDm - spread)/dPoint(Buy_pair_1);
  
   pairs_num++;
}

if (StringLen(Buy_pair_2)>0 && iOpen(Buy_pair_2, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Buy_pair_2, MODE_SPREAD)/ECN*dPoint(Buy_pair_2),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Buy_pair_2, tf, Time_Open);
         EURGBPm      = iOpen(Buy_pair_2, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Buy_pair_2, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Buy_pair_2, PERIOD_M1, period_starts_5min);

         Opentime = iTime(Buy_pair_2, tf, bars_back);
         EURGBPm      =    iOpen(Buy_pair_2,PERIOD_M1,iBarShift(Buy_pair_2, PERIOD_M1, Opentime));

   }

   open_5min       = iOpen(Buy_pair_2, PERIOD_M1, bars_period_starts_5min);
   if (Time_Close==978307200)
      EURGBPm_now  = MarketInfo(Buy_pair_2, MODE_ASK);
   else {
      bars_period_starts_5min = iBarShift(Buy_pair_2, closing_tf, Time_Close);
      EURGBPm_now      = iClose(Buy_pair_2, closing_tf, bars_period_starts_5min);
   }
 
   EURGBPm_pips = NormalizeDouble((EURGBPm_now-EURGBPm-spread)/dPoint(Buy_pair_2),0);
   EURGBPm_pips_5min = (open_5min - EURGBPm - spread)/dPoint(Buy_pair_2);

   pairs_num++;
}

if (StringLen(Buy_pair_3)>0 && iOpen(Buy_pair_3, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Buy_pair_3, MODE_SPREAD)/ECN*dPoint(Buy_pair_3),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Buy_pair_3, tf, Time_Open);
         GBPJPYm      = iOpen(Buy_pair_3, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Buy_pair_3, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Buy_pair_3, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Buy_pair_3, tf, bars_back);
         GBPJPYm      =    iOpen(Buy_pair_3,PERIOD_M1,iBarShift(Buy_pair_3, PERIOD_M1, Opentime));

   }

   open_5min       = iOpen(Buy_pair_3, PERIOD_M1, bars_period_starts_5min);
   if (Time_Close==978307200)
      GBPJPYm_now  = MarketInfo(Buy_pair_3, MODE_ASK);
   else {
      bars_period_starts_5min = iBarShift(Buy_pair_3, closing_tf, Time_Close);
      GBPJPYm_now      = iClose(Buy_pair_3, closing_tf, bars_period_starts_5min);
   }
 
   GBPJPYm_pips = NormalizeDouble((GBPJPYm_now-GBPJPYm-spread)/dPoint(Buy_pair_3),0);
   GBPJPYm_pips_5min = (open_5min - GBPJPYm - spread)/dPoint(Buy_pair_3);
   pairs_num++;
}

if (StringLen(Buy_pair_4)>0 && iOpen(Buy_pair_4, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Buy_pair_4, MODE_SPREAD)/ECN*dPoint(Buy_pair_4),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Buy_pair_4, tf, Time_Open);
         USDCHFm      = iOpen(Buy_pair_4, tf, bars_period_starts_5min);
   }         
   else  {
         period_starts_5min  = iTime(Buy_pair_4, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Buy_pair_4, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Buy_pair_4, tf, bars_back);
         USDCHFm      =    iOpen(Buy_pair_4,PERIOD_M1,iBarShift(Buy_pair_4, PERIOD_M1, Opentime));

   }
   open_5min       = iOpen(Buy_pair_4, PERIOD_M1, bars_period_starts_5min);

   if (Time_Close==978307200)
      USDCHFm_now  = MarketInfo(Buy_pair_4, MODE_ASK);
   else {
      bars_period_starts_5min = iBarShift(Buy_pair_4, closing_tf, Time_Close);
      USDCHFm_now      = iClose(Buy_pair_4, closing_tf, bars_period_starts_5min);
   }
   USDCHFm_pips = NormalizeDouble((USDCHFm_now-USDCHFm-spread)/dPoint(Buy_pair_4),0);
   USDCHFm_pips_5min = (open_5min - USDCHFm - spread)/dPoint(Buy_pair_4);
   pairs_num++;
}

if (StringLen(Buy_pair_5)>0 && iOpen(Buy_pair_5, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Buy_pair_5, MODE_SPREAD)/ECN*dPoint(Buy_pair_5),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Buy_pair_5, tf, Time_Open);
         NZDUSDm      = iOpen(Buy_pair_5, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Buy_pair_5, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Buy_pair_5, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Buy_pair_5, tf, bars_back);
         NZDUSDm      =    iOpen(Buy_pair_5,PERIOD_M1,iBarShift(Buy_pair_5, PERIOD_M1, Opentime));
  }

   open_5min       = iOpen(Buy_pair_5, PERIOD_M1, bars_period_starts_5min);

   if (Time_Close==978307200)
      NZDUSDm_now  = MarketInfo(Buy_pair_5, MODE_ASK);
   else {
      bars_period_starts_5min = iBarShift(Buy_pair_5, closing_tf, Time_Close);
      NZDUSDm_now      = iClose(Buy_pair_5, closing_tf, bars_period_starts_5min);
   }
   NZDUSDm_pips = NormalizeDouble((NZDUSDm_now-NZDUSDm-spread)/dPoint(Buy_pair_5),0);

   NZDUSDm_pips_5min = (open_5min - NZDUSDm - spread)/dPoint(Buy_pair_5);
   pairs_num++;
}

if (StringLen(Buy_pair_6)>0 && iOpen(Buy_pair_6, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Buy_pair_6, MODE_SPREAD)/ECN*dPoint(Buy_pair_6),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Buy_pair_6, tf, Time_Open);
         AUDJPYm      = iOpen(Buy_pair_6, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Buy_pair_6, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Buy_pair_6, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Buy_pair_6, tf, bars_back);
         AUDJPYm      =    iOpen(Buy_pair_6,PERIOD_M1,iBarShift(Buy_pair_6, PERIOD_M1, Opentime));
   }

   open_5min       = iOpen(Buy_pair_6, PERIOD_M1, bars_period_starts_5min);

  if (Time_Close==978307200)
      AUDJPYm_now  = MarketInfo(Buy_pair_6, MODE_ASK);
   else {
      bars_period_starts_5min = iBarShift(Buy_pair_6, closing_tf, Time_Close);
      AUDJPYm_now      = iClose(Buy_pair_6, closing_tf, bars_period_starts_5min);
   }
   AUDJPYm_pips = NormalizeDouble((AUDJPYm_now-AUDJPYm-spread)/dPoint(Buy_pair_6),0);

   AUDJPYm_pips_5min = (open_5min - AUDJPYm - spread)/dPoint(Buy_pair_6);
   pairs_num++;
}

if (StringLen(Buy_pair_7)>0 && iOpen(Buy_pair_7, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Buy_pair_7, MODE_SPREAD)/ECN*dPoint(Buy_pair_7),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Buy_pair_7, tf, Time_Open);
         EURJPYm      = iOpen(Buy_pair_7, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Buy_pair_7, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Buy_pair_7, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Buy_pair_7, tf, bars_back);
         EURJPYm      =    iOpen(Buy_pair_7,PERIOD_M1,iBarShift(Buy_pair_7, PERIOD_M1, Opentime));
   }
   open_5min       = iOpen(Buy_pair_7, PERIOD_M1, bars_period_starts_5min);

   if (Time_Close==978307200)
      EURJPYm_now  = MarketInfo(Buy_pair_7, MODE_ASK);
   else {
      bars_period_starts_5min = iBarShift(Buy_pair_7, closing_tf, Time_Close);
      EURJPYm_now      = iClose(Buy_pair_7, closing_tf, bars_period_starts_5min);
   }
   EURJPYm_pips = NormalizeDouble((EURJPYm_now-EURJPYm-spread)/dPoint(Buy_pair_7),0);

   EURJPYm_pips_5min = (open_5min - EURJPYm - spread)/dPoint(Buy_pair_7);
   pairs_num++;   
}

   return;

}

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------

void run_statistics_shorts(int week_back, datetime Time_Open, datetime Time_Close)
{

int tf=0;
int bars_back = 0;

int closing_tf = PERIOD_H1;

datetime period_starts_5min;
int bars_period_starts_5min;
double open_5min;
double spread;

EURUSDm=0; USDJPYm=0; AUDUSDm=0; NZDJPYm=0; GBPCHFm=0; CHFJPYm=0; EURCHFm=0;
EURUSDm_now=0;USDJPYm_now=0;AUDUSDm_now=0;NZDJPYm_now=0;GBPCHFm_now=0;CHFJPYm_now=0;EURCHFm_now=0;

EURUSDm_pips=0; USDJPYm_pips=0;AUDUSDm_pips=0;NZDJPYm_pips=0; GBPCHFm_pips=0;
CHFJPYm_pips=0;EURCHFm_pips=0;

EURUSDm_pips_5min=0; USDJPYm_pips_5min=0;AUDUSDm_pips_5min=0;NZDJPYm_pips_5min=0; GBPCHFm_pips_5min=0;
CHFJPYm_pips_5min=0;EURCHFm_pips_5min=0;

 if (week_back==1)  // 30 days ago
 {
     tf = PERIOD_D1;
     bars_back = 29;
 }    
 else if (week_back==2) // 21 days ago
 {
     tf = PERIOD_D1;
     bars_back = 20;
 }    
 else if (week_back==3) // 14 days ago
 {
     tf = PERIOD_D1;
     bars_back = 13;
    
 }    
 else if (week_back==4) // this week
 {
     tf = PERIOD_W1;
     bars_back = 0;
 }    
 else if (week_back==5) // this day
 {
     tf = PERIOD_D1;
     bars_back = 0;
 }
else if (week_back==6) // 12 hours ago
 {
     tf = PERIOD_M1;
     bars_back = 719;
 }
else if (week_back==7) // 8 hours ago
 {
     tf = PERIOD_M1;
     bars_back = 479;
 }
else if (week_back==8) // 4 hours ago
 {
     tf = PERIOD_M1;
     bars_back = 239;
 }
else if (week_back==9) // 2 hour ago
 {
     tf = PERIOD_M1;
     bars_back = 119;
 }
else if (week_back==10) // hour ago
 {
     tf = PERIOD_M1;
     bars_back = 59;
 }
else if (week_back==11) // 30 min ago
 {
     tf = PERIOD_M1;
     bars_back = 29;
 }
else if (week_back==12) // 15min ago
 {
     tf = PERIOD_M1;
     bars_back = 14;
 }
else if (week_back==13) // 5min ago
 {
     tf = PERIOD_M1;
     bars_back = 4;
 }
else if (week_back==14) // 1 min ago
 {
     tf = PERIOD_M1;
     bars_back = 0;
 }
else if (week_back==15) // Custom
 {
     tf = PERIOD_H1;
     bars_back = 0;
 }

datetime Opentime;
  
if (StringLen(Sell_pair_1)>0 && iOpen(Sell_pair_1, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Sell_pair_1, MODE_SPREAD)/ECN*dPoint(Sell_pair_1),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Sell_pair_1, tf, Time_Open);
         EURUSDm      = iOpen(Sell_pair_1, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Sell_pair_1, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Sell_pair_1, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Sell_pair_1, tf, bars_back);
         EURUSDm      =    iOpen(Sell_pair_1,PERIOD_M1,iBarShift(Sell_pair_1, PERIOD_M1, Opentime));
   }

   open_5min       = iOpen(Sell_pair_1, PERIOD_M1, bars_period_starts_5min);
   
   if (Time_Close==978307200)
      EURUSDm_now  = MarketInfo(Sell_pair_1, MODE_BID);
   else {
      bars_period_starts_5min = iBarShift(Sell_pair_1, closing_tf, Time_Close);
      EURUSDm_now      = iClose(Sell_pair_1, closing_tf, bars_period_starts_5min);
   }   

   EURUSDm_pips = NormalizeDouble((EURUSDm-EURUSDm_now+spread)/dPoint(Sell_pair_1),0);
   EURUSDm_pips_5min = (EURUSDm - open_5min + spread)/dPoint(Sell_pair_1);
   pairs_num++;
}

if (StringLen(Sell_pair_2)>0 && iOpen(Sell_pair_2, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Sell_pair_2, MODE_SPREAD)/ECN*dPoint(Sell_pair_2),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Sell_pair_2, tf, Time_Open);
         USDJPYm      = iOpen(Sell_pair_2, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Sell_pair_2, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Sell_pair_2, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Sell_pair_2, tf, bars_back);
         USDJPYm      =    iOpen(Sell_pair_2,PERIOD_M1,iBarShift(Sell_pair_2, PERIOD_M1, Opentime));
  }

   open_5min       = iOpen(Sell_pair_2, PERIOD_M1, bars_period_starts_5min);

   if (Time_Close==978307200)
      USDJPYm_now  = MarketInfo(Sell_pair_2, MODE_BID);
   else {
      bars_period_starts_5min = iBarShift(Sell_pair_2, closing_tf, Time_Close);
      USDJPYm_now      = iClose(Sell_pair_2, closing_tf, bars_period_starts_5min);
   }   

   USDJPYm_pips = NormalizeDouble((USDJPYm-USDJPYm_now+spread)/dPoint(Sell_pair_2),0);
   USDJPYm_pips_5min = (USDJPYm - open_5min + spread)/dPoint(Sell_pair_2);

   pairs_num++;
}

if (StringLen(Sell_pair_3)>0 && iOpen(Sell_pair_3, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Sell_pair_3, MODE_SPREAD)/ECN*dPoint(Sell_pair_3),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Sell_pair_3, tf, Time_Open);
         AUDUSDm      = iOpen(Sell_pair_3, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Sell_pair_3, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Sell_pair_3, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Sell_pair_3, tf, bars_back);
         AUDUSDm      =    iOpen(Sell_pair_3,PERIOD_M1,iBarShift(Sell_pair_3, PERIOD_M1, Opentime));
   }

   open_5min       = iOpen(Sell_pair_3, PERIOD_M1, bars_period_starts_5min);

   if (Time_Close==978307200)
      AUDUSDm_now  = MarketInfo(Sell_pair_3, MODE_BID);
   else {
      bars_period_starts_5min = iBarShift(Sell_pair_3, closing_tf, Time_Close);
      AUDUSDm_now      = iClose(Sell_pair_3, closing_tf, bars_period_starts_5min);
   }   
   AUDUSDm_pips = NormalizeDouble((AUDUSDm-AUDUSDm_now+spread)/dPoint(Sell_pair_3),0);

   AUDUSDm_pips_5min = (AUDUSDm - open_5min + spread)/dPoint(Sell_pair_3);
   pairs_num++;
}

if (StringLen(Sell_pair_4)>0 && iOpen(Sell_pair_4, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Sell_pair_4, MODE_SPREAD)/ECN*dPoint(Sell_pair_4),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Sell_pair_4, tf, Time_Open);
         NZDJPYm      = iOpen(Sell_pair_4, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Sell_pair_4, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Sell_pair_4, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Sell_pair_4, tf, bars_back);
         NZDJPYm      =    iOpen(Sell_pair_4,PERIOD_M1,iBarShift(Sell_pair_4, PERIOD_M1, Opentime));
  }

   open_5min       = iOpen(Sell_pair_4, PERIOD_M1, bars_period_starts_5min);

   if (Time_Close==978307200)
      NZDJPYm_now  = MarketInfo(Sell_pair_4, MODE_BID);
   else {
      bars_period_starts_5min = iBarShift(Sell_pair_4, closing_tf, Time_Close);
      NZDJPYm_now      = iClose(Sell_pair_4, closing_tf, bars_period_starts_5min);
   }   
   NZDJPYm_pips = NormalizeDouble((NZDJPYm-NZDJPYm_now+spread)/dPoint(Sell_pair_4),0);

   NZDJPYm_pips_5min = (NZDJPYm - open_5min + spread)/dPoint(Sell_pair_4);
   pairs_num++;
}

if (StringLen(Sell_pair_5)>0 && iOpen(Sell_pair_5, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Sell_pair_5, MODE_SPREAD)/ECN*dPoint(Sell_pair_5),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Sell_pair_5, tf, Time_Open);
         GBPCHFm      = iOpen(Sell_pair_5, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Sell_pair_5, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Sell_pair_5, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Sell_pair_5, tf, bars_back);
         GBPCHFm      =    iOpen(Sell_pair_5,PERIOD_M1,iBarShift(Sell_pair_5, PERIOD_M1, Opentime));
  }

   open_5min       = iOpen(Sell_pair_5, PERIOD_M1, bars_period_starts_5min);

   if (Time_Close==978307200)
      GBPCHFm_now  = MarketInfo(Sell_pair_5, MODE_BID);
   else {
      bars_period_starts_5min = iBarShift(Sell_pair_5, closing_tf, Time_Close);
      GBPCHFm_now      = iClose(Sell_pair_5, closing_tf, bars_period_starts_5min);
   }   
   GBPCHFm_pips = NormalizeDouble((GBPCHFm-GBPCHFm_now+spread)/dPoint(Sell_pair_5),0);

   GBPCHFm_pips_5min = (GBPCHFm - open_5min + spread)/dPoint(Sell_pair_5);
   pairs_num++;
}

if (StringLen(Sell_pair_6)>0 && iOpen(Sell_pair_6, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Sell_pair_6, MODE_SPREAD)/ECN*dPoint(Sell_pair_6),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Sell_pair_6, tf, Time_Open);
         CHFJPYm      = iOpen(Sell_pair_6, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Sell_pair_6, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Sell_pair_6, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Sell_pair_6, tf, bars_back);
         CHFJPYm      =    iOpen(Sell_pair_6,PERIOD_M1,iBarShift(Sell_pair_6, PERIOD_M1, Opentime));
  }

   open_5min       = iOpen(Sell_pair_6, PERIOD_M1, bars_period_starts_5min);

   if (Time_Close==978307200)
      CHFJPYm_now  = MarketInfo(Sell_pair_6, MODE_BID);
   else {
      bars_period_starts_5min = iBarShift(Sell_pair_6, closing_tf, Time_Close);
      CHFJPYm_now      = iClose(Sell_pair_6, closing_tf, bars_period_starts_5min);
   }
   
   CHFJPYm_pips = NormalizeDouble((CHFJPYm-CHFJPYm_now+spread)/dPoint(Sell_pair_6),0);
   CHFJPYm_pips_5min = (CHFJPYm - open_5min + spread)/dPoint(Sell_pair_6);
   pairs_num++;
}

if (StringLen(Sell_pair_7)>0 && iOpen(Sell_pair_7, tf, bars_back)!=0)
{
   spread = NormalizeDouble(MarketInfo(Sell_pair_7, MODE_SPREAD)/ECN*dPoint(Sell_pair_7),0);

   if (week_back==15) {
         bars_period_starts_5min = iBarShift(Sell_pair_7, tf, Time_Open);
         EURCHFm      = iOpen(Sell_pair_7, tf, bars_period_starts_5min);
   }
   else  {
         period_starts_5min  = iTime(Sell_pair_7, tf, bars_back)+60;
         bars_period_starts_5min = iBarShift(Sell_pair_7, PERIOD_M1, period_starts_5min);
         Opentime = iTime(Sell_pair_7, tf, bars_back);
         EURCHFm      =    iOpen(Sell_pair_7,PERIOD_M1,iBarShift(Sell_pair_7, PERIOD_M1, Opentime));
 }

   open_5min       = iOpen(Sell_pair_7, PERIOD_M1, bars_period_starts_5min);

   if (Time_Close==978307200)
      EURCHFm_now  = MarketInfo(Sell_pair_7, MODE_BID);
   else {
      bars_period_starts_5min = iBarShift(Sell_pair_7, closing_tf, Time_Close);
      EURCHFm_now      = iClose(Sell_pair_7, closing_tf, bars_period_starts_5min);
   }
   EURCHFm_pips = NormalizeDouble((EURCHFm-EURCHFm_now+spread)/dPoint(Sell_pair_7),0);

   EURCHFm_pips_5min = (EURCHFm - open_5min + spread)/dPoint(Sell_pair_7);
   pairs_num++;
}

   return;

}

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------

void draw_objects(int week_back, string& PairsNames[],double& Pairspips[], datetime Time_Opening, int column_period, datetime Time_Closing)
{

int x_coord;
string loc_date = Titles[week_back];

week_back = week_back+1;

 if (week_back==1)
     x_coord = 5;
 else if (week_back==2)
     x_coord = 145;
 else if (week_back==3)
     x_coord = 285;
 else if (week_back==4)
     x_coord = 425;
 else if (week_back==5)
     x_coord = 565;
 else if (week_back==6)
     x_coord = 705;
 else if (week_back==7)
     x_coord = 845;

companion =WindowFind(short_name);
if (companion == -1)companion=0;

blue=0; red=0;
blue_usd=0; red_usd=0; blue_jpy=0; red_jpy=0; blue_oth=0; red_oth=0;                                                                                  

int result;
string add_str;
double diff;
int pair_index = 0;

   string PairsDisplay[14];   

   string PairsSearch[14];
   
   color  PairsColor[14]; 
                  
   double PLArray[14];

   double PLArray_5min[14];

   bool ShowDirections[14];

   PLArray_5min[0]=GBPUSDm_pips_5min;
   PLArray_5min[1]=EURGBPm_pips_5min;
   PLArray_5min[2]=GBPJPYm_pips_5min;
   PLArray_5min[3]=USDCHFm_pips_5min;
   PLArray_5min[4]=NZDUSDm_pips_5min;
   PLArray_5min[5]=AUDJPYm_pips_5min;
   PLArray_5min[6]=EURJPYm_pips_5min;
   
   PLArray_5min[7]=  EURUSDm_pips_5min;
   PLArray_5min[8]=  USDJPYm_pips_5min;
   PLArray_5min[9]=  AUDUSDm_pips_5min;
   PLArray_5min[10]= NZDJPYm_pips_5min;
   PLArray_5min[11]= GBPCHFm_pips_5min;
   PLArray_5min[12]= CHFJPYm_pips_5min;
   PLArray_5min[13]= EURCHFm_pips_5min;

   PLArray[0]=GBPUSDm_pips;
   PLArray[1]=EURGBPm_pips;
   PLArray[2]=GBPJPYm_pips;
   PLArray[3]=USDCHFm_pips;
   PLArray[4]=NZDUSDm_pips;
   PLArray[5]=AUDJPYm_pips;
   PLArray[6]=EURJPYm_pips;
   
   PLArray[7]=  EURUSDm_pips;
   PLArray[8]=  USDJPYm_pips;
   PLArray[9]=  AUDUSDm_pips;
   PLArray[10]= NZDJPYm_pips;
   PLArray[11]= GBPCHFm_pips;
   PLArray[12]= CHFJPYm_pips;
   PLArray[13]= EURCHFm_pips;

   PairsNames[0]=Buy_pair_1;
   PairsNames[1]=Buy_pair_2;
   PairsNames[2]=Buy_pair_3;
   PairsNames[3]=Buy_pair_4;
   PairsNames[4]=Buy_pair_5;
   PairsNames[5]=Buy_pair_6;
   PairsNames[6]=Buy_pair_7;

   PairsNames[7]=Sell_pair_1;
   PairsNames[8]=Sell_pair_2;
   PairsNames[9]=Sell_pair_3;
   PairsNames[10]=Sell_pair_4;
   PairsNames[11]=Sell_pair_5;
   PairsNames[12]=Sell_pair_6;
   PairsNames[13]=Sell_pair_7;

   for(int m=0;m<=13;m++)
   { 
     PairsSearch[m]   = PairsNames[m];
   }

   ShowDirections[0] = Show_buy_direction_1;    
   ShowDirections[1] = Show_buy_direction_2;    
   ShowDirections[2] = Show_buy_direction_3;    
   ShowDirections[3] = Show_buy_direction_4;    
   ShowDirections[4] = Show_buy_direction_5;    
   ShowDirections[5] = Show_buy_direction_6;    
   ShowDirections[6] = Show_buy_direction_7;    

   ShowDirections[7] = Show_sell_direction_1;    
   ShowDirections[8] = Show_sell_direction_2;    
   ShowDirections[9] = Show_sell_direction_3;    
   ShowDirections[10] = Show_sell_direction_4;    
   ShowDirections[11] = Show_sell_direction_5;    
   ShowDirections[12] = Show_sell_direction_6;    
   ShowDirections[13] = Show_sell_direction_7;    

   PairsColor[0] = LimeGreen;
   PairsColor[1] = LimeGreen;
   PairsColor[2] = LimeGreen;
   PairsColor[3] = LimeGreen;
   PairsColor[4] = LimeGreen;
   PairsColor[5] = LimeGreen;
   PairsColor[6] = LimeGreen;

   PairsColor[7] = Tomato;
   PairsColor[8] = Tomato;
   PairsColor[9] = Tomato;
   PairsColor[10]= Tomato;
   PairsColor[11]= Tomato;
   PairsColor[12]= Tomato;
   PairsColor[13]= Tomato;

   int plarr_size = ArraySize(PLArray);
   
   double temp_var;
   string temp_str;
   color temp_color;
   bool temp_direction;
   double temp_var_5min;
   
   for(int i=0;i < plarr_size;i++) //Hold the first element
	{
		for(int j=i+1;j<plarr_size;j++) //Hold the next element from the first element
		{
			if(PLArray[i] < PLArray[j])	//comparing first and next element
			{
				temp_var = PLArray[j];	
				PLArray[j] = PLArray[i];
				PLArray[i] = temp_var;
				
				temp_str = PairsNames[j];	
				PairsNames[j] = PairsNames[i];
				PairsNames[i] = temp_str;

				temp_color  = PairsColor[j];	
				PairsColor[j] = PairsColor[i];
				PairsColor[i] = temp_color;

				temp_direction  = ShowDirections[j];	
				ShowDirections[j] = ShowDirections[i];
				ShowDirections[i] = temp_direction;

				temp_var_5min = PLArray_5min[j];	
				PLArray_5min[j] = PLArray_5min[i];
				PLArray_5min[i] = temp_var_5min;
				
				//Print(temp_str,"-------->",temp_var);
			}
		}
	}
   
   //for(i=0;i < plarr_size;i++) 
   //    Print(i,"----->",PLArray[i]);
   
   
   // Sorting 5 min array
   for(i=0;i < plarr_size;i++) //Hold the first element
	{
		for(j=i+1;j<plarr_size;j++) //Hold the next element from the first element
		{
			if(PLArray_5min[i] < PLArray_5min[j]) //comparing first and next element
			{
				temp_var_5min = PLArray_5min[j];	
				PLArray_5min[j] = PLArray_5min[i];
				PLArray_5min[i] = temp_var_5min;

				temp_str = PairsSearch[j];	
				PairsSearch[j] = PairsSearch[i];
				PairsSearch[i] = temp_str;
			}
		}
	}

  
   for(i=0;i<=13;i++)
    { 
      Pairspips[i] = PLArray[i];
    
      if(PairsColor[i] == LimeGreen) 
       {
         PairsDisplay[i] = ""+  StringTrimRight(StringTrimLeft(PairsNames[i]))  ; // Buy
         blue = blue + PLArray[i];

        if (StringFind(PairsNames[i], "USD")>=0)
            blue_usd = blue_usd + PLArray[i];
        else if (StringFind(PairsNames[i], "JPY")>=0)
            blue_jpy = blue_jpy + PLArray[i];
        else    
            blue_oth = blue_oth + PLArray[i];        
       }
       
      if(PairsColor[i] == Tomato) 
       {
         PairsDisplay[i] = ""+StringTrimRight(StringTrimLeft(PairsNames[i])); // Sell
         red = red + PLArray[i];
      
         if (StringFind(PairsNames[i], "USD")>=0)
            red_usd = red_usd + PLArray[i];
         else if (StringFind(PairsNames[i], "JPY")>=0)
            red_jpy = red_jpy + PLArray[i];
         else    
            red_oth = red_oth + PLArray[i];          
         
       }
       
    }


if (ObjectFind(week_back+"sig_tit") == -1 ){
   ObjectCreate(week_back+"sig_tit", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"sig_tit", OBJPROP_COLOR, Tomato);
   ObjectSet(week_back+"sig_tit", OBJPROP_XDISTANCE, x_coord);
   ObjectSet(week_back+"sig_tit", OBJPROP_YDISTANCE, 15);
   
   ObjectSetText(week_back+"sig_tit",loc_date,10,"Courier New",White);
}

y_coord = 40;

if (StringLen(PairsDisplay[0])>0) //StringLen(StringTrimLeft(StringSubstr(PairsDisplay[0],4)))>0
{
   if (ObjectFind("W"+week_back+PairsDisplay[0]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[0], OBJ_LABEL, companion, 0, 0);
   }
      ObjectSet("W"+week_back+PairsDisplay[0], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[0], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[0], OBJPROP_YDISTANCE, y_coord);

   ObjectSetText("W"+week_back+PairsDisplay[0],StringSubstr(PairsDisplay[0],0,6)+"  "+DoubleToStr(PLArray[0],0), main_font_size,
                     "Lucida Console Bold",PairsColor[0]);

      if (ShowDirections[0])
         draw_rating(0,week_back,PairsSearch,PairsDisplay[0], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);

      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[1])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[1]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[1], OBJ_LABEL, companion, 0, 0);
   }
      ObjectSet("W"+week_back+PairsDisplay[1], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[1], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[1], OBJPROP_YDISTANCE, y_coord);

   ObjectSetText("W"+week_back+PairsDisplay[1],StringSubstr(PairsDisplay[1],0,6)+"  "+DoubleToStr(PLArray[1],0)+add_str, main_font_size,
         "Lucida Console Bold",PairsColor[1]);

       if (ShowDirections[1])
         draw_rating(1,week_back,PairsSearch,PairsDisplay[1], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
         
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[2])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[2]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[2], OBJ_LABEL, companion, 0, 0);
   }

      ObjectSet("W"+week_back+PairsDisplay[2], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[2], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[2], OBJPROP_YDISTANCE, y_coord);

   ObjectSetText("W"+week_back+PairsDisplay[2],StringSubstr(PairsDisplay[2],0,6) + "  "+DoubleToStr(PLArray[2],0)+add_str, main_font_size,
      "Lucida Console Bold",PairsColor[2]);

       if (ShowDirections[2])
         draw_rating(2,week_back,PairsSearch,PairsDisplay[2], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
         
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[3])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[3]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[3], OBJ_LABEL, companion, 0, 0);
   }
      ObjectSet("W"+week_back+PairsDisplay[3], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[3], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[3], OBJPROP_YDISTANCE, y_coord);

   ObjectSetText("W"+week_back+PairsDisplay[3],StringSubstr(PairsDisplay[3],0,6)+"  "+DoubleToStr(PLArray[3],0)+add_str, main_font_size,
       "Lucida Console Bold",PairsColor[3]);

      if (ShowDirections[3])
         draw_rating(3,week_back,PairsSearch,PairsDisplay[3], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
         
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[4])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[4]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[4], OBJ_LABEL, companion, 0, 0);
   }
      ObjectSet("W"+week_back+PairsDisplay[4], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[4], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[4], OBJPROP_YDISTANCE, y_coord);

   ObjectSetText("W"+week_back+PairsDisplay[4],StringSubstr(PairsDisplay[4],0,6)+"  "+DoubleToStr(PLArray[4],0)+add_str, main_font_size,
      "Lucida Console Bold",PairsColor[4]);

      if (ShowDirections[4])
         draw_rating(4,week_back,PairsSearch,PairsDisplay[4], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
         
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[5])>0)
{

   if (ObjectFind("W"+week_back+PairsDisplay[5]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[5], OBJ_LABEL, companion, 0, 0);
   }

      ObjectSet("W"+week_back+PairsDisplay[5], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[5], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[5], OBJPROP_YDISTANCE, y_coord);

   ObjectSetText("W"+week_back+PairsDisplay[5],StringSubstr(PairsDisplay[5],0,6)+"  "+DoubleToStr(PLArray[5],0)+add_str, main_font_size,
      "Lucida Console Bold",PairsColor[5]);

      if (ShowDirections[5])
        draw_rating(5,week_back,PairsSearch,PairsDisplay[5], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
      
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[6])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[6]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[6], OBJ_LABEL, companion, 0, 0);
   }

      ObjectSet("W"+week_back+PairsDisplay[6], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[6], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[6], OBJPROP_YDISTANCE, y_coord);

      ObjectSetText("W"+week_back+PairsDisplay[6],StringSubstr(PairsDisplay[6],0,6)+"  "+DoubleToStr(PLArray[6],0)+add_str, main_font_size,
      "Lucida Console Bold",PairsColor[6]);

      if (ShowDirections[6])
         draw_rating(6,week_back,PairsSearch,PairsDisplay[6], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
      
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[7])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[7]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[7], OBJ_LABEL, companion, 0, 0);
   }

      ObjectSet("W"+week_back+PairsDisplay[7], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[7], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[7], OBJPROP_YDISTANCE, y_coord);

   ObjectSetText("W"+week_back+PairsDisplay[7],StringSubstr(PairsDisplay[7],0,6)+"  "+DoubleToStr(PLArray[7],0)+add_str, main_font_size,
      "Lucida Console Bold",PairsColor[7]);

      if (ShowDirections[7])
         draw_rating(7,week_back,PairsSearch,PairsDisplay[7], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
         
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[8])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[8]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[8], OBJ_LABEL, companion, 0, 0);
   }

      ObjectSet("W"+week_back+PairsDisplay[8], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[8], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[8], OBJPROP_YDISTANCE, y_coord);

   ObjectSetText("W"+week_back+PairsDisplay[8],StringSubstr(PairsDisplay[8],0,6)+"  "+DoubleToStr(PLArray[8],0)+add_str, main_font_size,
      "Lucida Console Bold",PairsColor[8]);


     if (ShowDirections[8])
       draw_rating(8,week_back,PairsSearch,PairsDisplay[8], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
      
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[9])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[9]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[9], OBJ_LABEL, companion, 0, 0);
   }

      ObjectSet("W"+week_back+PairsDisplay[9], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[9], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[9], OBJPROP_YDISTANCE, y_coord);

      ObjectSetText("W"+week_back+PairsDisplay[9],StringSubstr(PairsDisplay[9],0,6) +"  "+DoubleToStr(PLArray[9],0)+add_str, main_font_size,
      "Lucida Console Bold",PairsColor[9]);

      if (ShowDirections[9])
         draw_rating(9,week_back,PairsSearch,PairsDisplay[9], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
         
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[10])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[10]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[10], OBJ_LABEL, companion, 0, 0);
   }

      ObjectSet("W"+week_back+PairsDisplay[10], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[10], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[10], OBJPROP_YDISTANCE, y_coord);

      ObjectSetText("W"+week_back+PairsDisplay[10],StringSubstr(PairsDisplay[10],0,6)+"  "+DoubleToStr(PLArray[10],0)+add_str, main_font_size,
      "Lucida Console Bold",PairsColor[10]);

      if (ShowDirections[10])
         draw_rating(10,week_back,PairsSearch,PairsDisplay[10], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
      
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[11])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[11]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[11], OBJ_LABEL, companion, 0, 0);
   }

      ObjectSet("W"+week_back+PairsDisplay[11], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[11], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[11], OBJPROP_YDISTANCE, y_coord);

      ObjectSetText("W"+week_back+PairsDisplay[11],StringSubstr(PairsDisplay[11],0,6)+"  "+DoubleToStr(PLArray[11],0)+add_str, main_font_size,
      "Lucida Console Bold",PairsColor[11]);

      if (ShowDirections[11])
         draw_rating(11,week_back,PairsSearch,PairsDisplay[11], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
      
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[12])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[12]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[12], OBJ_LABEL, companion, 0, 0);
   }

      ObjectSet("W"+week_back+PairsDisplay[12], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[12], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[12], OBJPROP_YDISTANCE, y_coord);

      ObjectSetText("W"+week_back+PairsDisplay[12],StringSubstr(PairsDisplay[12],0,6)+"  "+DoubleToStr(PLArray[12],0)+add_str, main_font_size,
         "Lucida Console Bold",PairsColor[12]);

      if (ShowDirections[12])
         draw_rating(12,week_back,PairsSearch,PairsDisplay[12], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
      
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (StringLen(PairsDisplay[13])>0)
{
   if (ObjectFind("W"+week_back+PairsDisplay[13]) == -1 ){
      ObjectCreate("W"+week_back+PairsDisplay[13], OBJ_LABEL, companion, 0, 0);
   }

      ObjectSet("W"+week_back+PairsDisplay[13], OBJPROP_COLOR, Tomato);
      ObjectSet("W"+week_back+PairsDisplay[13], OBJPROP_XDISTANCE, x_coord);
      ObjectSet("W"+week_back+PairsDisplay[13], OBJPROP_YDISTANCE, y_coord);

      ObjectSetText("W"+week_back+PairsDisplay[13],StringSubstr(PairsDisplay[13],0,6)+"  "+DoubleToStr(PLArray[13],0)+add_str, main_font_size,
         "Lucida Console Bold",PairsColor[13]);

      if (ShowDirections[13])
         draw_rating(13,week_back,PairsSearch,PairsDisplay[13], x_coord, y_coord, companion, Time_Opening,column_period, Time_Closing);
      
      y_coord = y_coord + 15;
      pair_index++;
      
      draw_delimiter (week_back, x_coord, y_coord, pair_index);
}

if (ObjectFind(week_back+"lin") == -1 ){
    ObjectCreate(week_back+"lin",OBJ_LABEL,companion,0, 0);
    ObjectSet(week_back+"lin",OBJPROP_COLOR,White);
    ObjectSet(week_back+"lin", OBJPROP_XDISTANCE, x_coord);
    ObjectSet(week_back+"lin", OBJPROP_YDISTANCE, y_coord);
    ObjectSetText(week_back+"lin","-----------------", 10,
         "Courier New",White);
    y_coord = y_coord+15;
}

//---------------------------------------------------------------
if (ObjectFind(week_back+"bu_lett") == -1 ){
   ObjectCreate(week_back+"bu_lett", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"bu_lett", OBJPROP_COLOR, White);
   ObjectSet(week_back+"bu_lett", OBJPROP_XDISTANCE, x_coord-7);
   ObjectSet(week_back+"bu_lett", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"bu_lett","U", 9, "Courier New",White);

if (ObjectFind(week_back+"bu_tot") == -1 ){
   ObjectCreate(week_back+"bu_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"bu_tot", OBJPROP_COLOR, SpringGreen);
   ObjectSet(week_back+"bu_tot", OBJPROP_XDISTANCE, x_coord);
   ObjectSet(week_back+"bu_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"bu_tot",DoubleToStr(blue_usd,0), 9,
         "Courier New",SpringGreen);

if (ObjectFind(week_back+"su_tot") == -1 ){
   ObjectCreate(week_back+"su_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"su_tot", OBJPROP_COLOR, OrangeRed);
   ObjectSet(week_back+"su_tot", OBJPROP_XDISTANCE, x_coord + 45);
   ObjectSet(week_back+"su_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"su_tot",DoubleToStr(red_usd,0), 9,
         "Courier New",OrangeRed);

if (ObjectFind(week_back+"u_tot") == -1 ){
   ObjectCreate(week_back+"u_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"u_tot", OBJPROP_COLOR, Yellow);
   ObjectSet(week_back+"u_tot", OBJPROP_XDISTANCE, x_coord + 80);
   ObjectSet(week_back+"u_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"u_tot","T:"+DoubleToStr(red_usd+blue_usd,0), 9,
         "Courier New",Yellow);
   y_coord = y_coord +12;         

if (ObjectFind(week_back+"bj_lett") == -1 ){
   ObjectCreate(week_back+"bj_lett", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"bj_lett", OBJPROP_COLOR, White);
   ObjectSet(week_back+"bj_lett", OBJPROP_XDISTANCE, x_coord-7);
   ObjectSet(week_back+"bj_lett", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"bj_lett","J", 9, "Courier New",White);

if (ObjectFind(week_back+"bj_tot") == -1 ){
   ObjectCreate(week_back+"bj_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"bj_tot", OBJPROP_COLOR, SpringGreen);
   ObjectSet(week_back+"bj_tot", OBJPROP_XDISTANCE, x_coord);
   ObjectSet(week_back+"bj_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"bj_tot",DoubleToStr(blue_jpy,0), 9,
         "Courier New",SpringGreen);

if (ObjectFind(week_back+"sj_tot") == -1 ){
   ObjectCreate(week_back+"sj_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"sj_tot", OBJPROP_COLOR, OrangeRed);
   ObjectSet(week_back+"sj_tot", OBJPROP_XDISTANCE, x_coord + 45);
   ObjectSet(week_back+"sj_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"sj_tot",DoubleToStr(red_jpy,0), 9,
         "Courier New",OrangeRed);

if (ObjectFind(week_back+"j_tot") == -1 ){
   ObjectCreate(week_back+"j_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"j_tot", OBJPROP_COLOR, Yellow);
   ObjectSet(week_back+"j_tot", OBJPROP_XDISTANCE, x_coord + 80);
   ObjectSet(week_back+"j_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"j_tot","T:"+DoubleToStr(red_jpy+blue_jpy,0), 9,
         "Courier New",Yellow);
   y_coord = y_coord +12;         

if (ObjectFind(week_back+"bo_lett") == -1 ){
   ObjectCreate(week_back+"bo_lett", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"bo_lett", OBJPROP_COLOR, White);
   ObjectSet(week_back+"bo_lett", OBJPROP_XDISTANCE, x_coord-7);
   ObjectSet(week_back+"bo_lett", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"bo_lett","O", 9, "Courier New",White);

if (ObjectFind(week_back+"bo_tot") == -1 ){
   ObjectCreate(week_back+"bo_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"bo_tot", OBJPROP_COLOR, SpringGreen);
   ObjectSet(week_back+"bo_tot", OBJPROP_XDISTANCE, x_coord);
   ObjectSet(week_back+"bo_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"bo_tot",DoubleToStr(blue_oth,0), 9,
         "Courier New",SpringGreen);

if (ObjectFind(week_back+"so_tot") == -1 ){
   ObjectCreate(week_back+"so_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"so_tot", OBJPROP_COLOR, OrangeRed);
   ObjectSet(week_back+"so_tot", OBJPROP_XDISTANCE, x_coord + 45);
   ObjectSet(week_back+"so_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"so_tot",DoubleToStr(red_oth,0), 9,
         "Courier New",OrangeRed);

if (ObjectFind(week_back+"o_tot") == -1 ){
   ObjectCreate(week_back+"o_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"o_tot", OBJPROP_COLOR, Yellow);
   ObjectSet(week_back+"o_tot", OBJPROP_XDISTANCE, x_coord + 80);
   ObjectSet(week_back+"o_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"o_tot","T:"+DoubleToStr(red_oth+blue_oth,0), 9,
         "Courier New",Yellow);
   y_coord = y_coord +12;         

if (ObjectFind(week_back+"b_tot") == -1 ){
   ObjectCreate(week_back+"b_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"b_tot", OBJPROP_COLOR, Chartreuse);
   ObjectSet(week_back+"b_tot", OBJPROP_XDISTANCE, x_coord);
   ObjectSet(week_back+"b_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"b_tot",DoubleToStr(blue,0), 9,
         "Courier New",Chartreuse);

if (ObjectFind(week_back+"s_tot") == -1 ){
   ObjectCreate(week_back+"s_tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"s_tot", OBJPROP_COLOR, Orange);
   ObjectSet(week_back+"s_tot", OBJPROP_XDISTANCE, x_coord + 45);
   ObjectSet(week_back+"s_tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"s_tot",DoubleToStr(red,0), 9,
         "Courier New",Orange);

if (ObjectFind(week_back+"tot") == -1 ){
   ObjectCreate(week_back+"tot", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"tot", OBJPROP_COLOR, Peru);
   ObjectSet(week_back+"tot", OBJPROP_XDISTANCE, x_coord + 80);
   ObjectSet(week_back+"tot", OBJPROP_YDISTANCE, y_coord);
}

   ObjectSetText(week_back+"tot","T:"+DoubleToStr(red+blue,0), 9,
         "Courier New",Peru);
   y_coord = y_coord +20;         

//---------------------------------------------------------------
if (ObjectFind(week_back+"sig") == -1 ){
   ObjectCreate(week_back+"sig", OBJ_LABEL, companion, 0, 0);
   ObjectSet(week_back+"sig", OBJPROP_COLOR, Tomato);
   ObjectSet(week_back+"sig", OBJPROP_XDISTANCE, x_coord);
   ObjectSet(week_back+"sig", OBJPROP_YDISTANCE, y_coord);
}

  string trend = "NONE";
  color col = White;
  int long_strong = 0;
  int short_strong = 0;
   
   if (red > 0 && blue < 0)
      {trend = "SHORT (Strong)"; col = Tomato; short_strong = 1;}
   else if (red > blue && (red > 0 && blue > 0))
      {trend = "SHORT (Weak)"; col = Orange;}
   else if (blue > 0 && red < 0)
      {trend = "LONG (Strong)"; col = Blue; long_strong=1;}
   else if (blue > red && (blue > 0 && red > 0))
      {trend = "LONG (Weak)"; col = DeepSkyBlue;}

   AllLongSignal = AllLongSignal * long_strong;
   AllShortSignal= AllShortSignal * short_strong;

// ***vvvvvvvvvvv*** charvo edition ***vvvvvvvvvvvvv***

   int l_signal = 0;
   int s_signal = 0;
   // BusinessRules_Long
   // BusinessRules_Short 

   if (Rules_ON && ! Stop_Rules && Columns[week_back-1] == Timeframe) {
      //Print ("Passed 1st step");
      
      //  
      if (Upper_Slot_to_occupy>0 && Lower_Slot_to_occupy>0) {
         //Print ("Passed 2ndt step");

         if (Pair_to_Follow=="BUY N SELL") {
            // determine to buy...
            if (PairsColor[Upper_Slot_to_occupy-1]==LimeGreen && PairsColor[Lower_Slot_to_occupy-1]==Tomato) {
                 if (PLArray[Upper_Slot_to_occupy-1] >= Profit_in_Pips_more_then)
                     l_signal = 1;
                 else if (PLArray[Lower_Slot_to_occupy-1] <= Profit_in_Pips_less_then)
                     l_signal = 1;
            }     
            // determine to sell...
            if (PairsColor[Upper_Slot_to_occupy-1]==Tomato && PairsColor[Lower_Slot_to_occupy-1]==LimeGreen) {
                 if (PLArray[Upper_Slot_to_occupy-1] >= Profit_in_Pips_more_then)
                     s_signal = 1;
                 else if (PLArray[Lower_Slot_to_occupy-1] <= Profit_in_Pips_less_then)
                     s_signal = 1;

            }         
         }            

         else if (StringLen(Pair_to_Follow)>0) {
               //Print ("Passed 3d step");
               //Print (PairsNames[Upper_Slot_to_occupy-1],"   ",Pair_to_Follow," Titles ",Titles[week_back], " Pips:", PLArray[Upper_Slot_to_occupy-1]);
               if (PairsNames[Upper_Slot_to_occupy-1]==Pair_to_Follow) {
                  //Print ("Passed 4th step");
                     if (PLArray[Upper_Slot_to_occupy-1] >= Profit_in_Pips_more_then)
                         if (PairsColor[Upper_Slot_to_occupy-1]==LimeGreen) l_signal = 1;
                         if (PairsColor[Upper_Slot_to_occupy-1]==Tomato) s_signal = 1;
               }
               if (PairsNames[Lower_Slot_to_occupy-1]==Pair_to_Follow) {
                     //if (Profit_in_Pips_less_then != 0 && PLArray[Lower_Slot_to_occupy-1] <= Profit_in_Pips_less_then)
                     if (PLArray[Lower_Slot_to_occupy-1] <= Profit_in_Pips_less_then)
                         if (PairsColor[Lower_Slot_to_occupy-1]==LimeGreen) s_signal = 1;
                         if (PairsColor[Lower_Slot_to_occupy-1]==Tomato) l_signal = 1;
               }
               
         }
      }
      //Print("Long Strong ",long_strong, "  Short Strong  ",short_strong);      
 
      if (s_signal == 1 && Open_Short)
         BusinessRules_Short = 1;
      else if (l_signal == 1 && Open_Long)
         BusinessRules_Long = 1;     
 
      if (BusinessRules_Long == 1 && Open_On_Strong_Signal && long_strong == 0)
          BusinessRules_Long = 0;

      if (BusinessRules_Short == 1 && Open_On_Strong_Signal && short_strong == 0)
          BusinessRules_Short = 0;
   }

// ***^^^^^^^^^^^*** charvo edition ***^^^^^^^^^^^^^***                       

   //if (BusinessRules_Long == 1)
   //   Print("BusinessRules_Long");
 
   //if (BusinessRules_Short == 1)
   //   Print("BusinessRules_Short");


   //if (run_print) {
   //   Print("Allshort:===>",  short_strong,"==============",AllShortSignal);
   //   Print("Alllong:===>",  long_strong,"==============",AllLongSignal);
   //}
   ObjectSetText(week_back+"sig",trend, 12,"Lucida Console Bold",col);

   WindowRedraw();
}

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
double dPoint(string sym)
{
  double _Point = MarketInfo(sym,MODE_POINT)*ECN;
  
  return(_Point); 
}

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
int ArraySearch(string& m[], string e) {
  for (int i=0; i<ArraySize(m); i++) {
    if (m[i]==e) return(i);
  }
  return(-1);
}

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
void draw_rating(int i_index, int week_back, string& PairsSearch[], string pair_display, int x_coord, int y_coord,
                 int companion,datetime Time_Open, int column_period, datetime Time_Closing)
{
         int tf = 0;
         int bars_back = 0;

         color adx_color_prev, adx_color_now; 
         string adx_arrow_prev, adx_arrow_now;

         if (column_period==1)  // 30 days ago
        {
            tf = PERIOD_D1;
            bars_back = 29;
        }    
        else if (column_period==2) // 21 days ago
        {
            tf = PERIOD_D1;
            bars_back = 20;
        }    
        else if (column_period==3) // 14 days ago
        {
            tf = PERIOD_D1;
            bars_back = 13;
    
        }    
        else if (column_period==4) // this week
        {
            tf = PERIOD_W1;
            bars_back = 0;
        }    
        else if (column_period==5) // this day
        {
            tf = PERIOD_D1;
            bars_back = 0;
        }
       else if (column_period==6) // 12 hours ago
        {
            tf = PERIOD_M1;
            bars_back = 719;
        }
       else if (column_period==7) // 8 hours ago
        {
            tf = PERIOD_M1;
            bars_back = 479;
        }
       else if (column_period==8) // 4 hours ago
        {
            tf = PERIOD_M1;
            bars_back = 239;
        }
       else if (column_period==9) // 2 hour ago
        {
            tf = PERIOD_M1;
            bars_back = 119;
        }
       else if (column_period==10) // hour ago
        {
            tf = PERIOD_M1;
            bars_back = 59;
        }
       else if (column_period==11) // 30 min ago
        {
            tf = PERIOD_M1;
            bars_back = 29;
        }
       else if (column_period==12) // 15min ago
        {
            tf = PERIOD_M1;
            bars_back = 14;
        }
       else if (column_period==13) // 5min ago
        {
            tf = PERIOD_M1;
            bars_back = 4;
        }
       else if (column_period==14) // 1 min ago
        {
            tf = PERIOD_M1;
            bars_back = 0;
        }
       else if (column_period==15) // custom
        {
            tf = PERIOD_H1;
            bars_back = iBarShift(pair_display, tf, Time_Open);
        }
        
        if (column_period!=15) {
            datetime Opentime = iTime(pair_display, tf, bars_back);
            bars_back =   iBarShift(pair_display, PERIOD_M1, Opentime);
            tf = PERIOD_M1;
        }
        
        // because if bars_back == 0 we always have prev. value = current value
       // bars_back++;
       
       
       
       double adx_prev  = iADX(pair_display,tf,14,PRICE_CLOSE,0,bars_back);
       double di_p_prev = iADX(pair_display,tf,14,PRICE_CLOSE,1,bars_back);
       double di_m_prev = iADX(pair_display,tf,14,PRICE_CLOSE,2,bars_back);    

       //if (column_period==15 || column_period==4)
       //   Print (bars_back, "    ",adx_prev, "     ", tf, pair_display,"   ");  
   
       int shift; 

       if (Time_Closing==978307200)
           shift = 0;
       else {
           shift = iBarShift(pair_display, tf, Time_Closing);
       }   

       double adx_now  = iADX(pair_display,tf,14,PRICE_CLOSE,0,shift);
       double di_p_now = iADX(pair_display,tf,14,PRICE_CLOSE,1,shift);
       double di_m_now = iADX(pair_display,tf,14,PRICE_CLOSE,2,shift);    

       string adx_prev_value;
       string adx_now_value;
      
      if ((adx_prev < 15) && (adx_prev != 0)) { adx_color_prev = LightSkyBlue; }
      if ((adx_prev >=15) && (di_p_prev > di_m_prev)) { adx_color_prev = Lime; }
      if ((adx_prev >=15) && (di_p_prev < di_m_prev)) { adx_color_prev = Red; }
   
      if ((adx_now < 15) && (adx_now != 0)) { adx_color_now = LightSkyBlue; }
      if ((adx_now >=15) && (di_p_now > di_m_now)) { adx_color_now = Lime; }
      if ((adx_now >=15) && (di_p_now < di_m_now)) { adx_color_now = Red; }


      if (adx_prev < 23 && adx_prev != 0) { adx_arrow_prev = "h"; }
      if ((adx_prev >= 23 && adx_prev < 28) && (di_p_prev > di_m_prev)) { adx_arrow_prev = "ì"; }
      if ((adx_prev >= 23 && adx_prev < 28) && (di_p_prev < di_m_prev)) { adx_arrow_prev = "î"; }
      if ((adx_prev >=28) && (di_p_prev > di_m_prev)) { adx_arrow_prev = "é"; }
      if ((adx_prev >=28) && (di_p_prev < di_m_prev)) { adx_arrow_prev = "ê"; }

      if (adx_now < 23 && adx_now != 0) { adx_arrow_now = "h"; }
      if ((adx_now >= 23 && adx_now < 28) && (di_p_now > di_m_now)) { adx_arrow_now = "ì"; }
      if ((adx_now >= 23 && adx_now < 28) && (di_p_now < di_m_now)) { adx_arrow_now = "î"; }
      if ((adx_now >=28) && (di_p_now > di_m_now)) { adx_arrow_now = "é"; }
      if ((adx_now >=28) && (di_p_now < di_m_now)) { adx_arrow_now = "ê"; }


      adx_prev_value = adx_prev;
      adx_now_value  = adx_now;
        
      int result = ArraySearch(PairsSearch,pair_display);
      if (result!=-1)
      {

        // if (ObjectFind("W"+week_back+pair_display) != -1 )
        // {
            ObjectDelete("W_prev"+week_back+pair_display);
        // }
         
        // if (ObjectFind("WA"+week_back+pair_display) != -1 )
        // {
            ObjectDelete("WA"+week_back+pair_display);         
        // }

            ObjectDelete("W_now"+week_back+pair_display);
            ObjectDelete("WA_now"+week_back+pair_display);         

            int x_coord_numb, x_coord_arrow;
            
            x_coord_numb = x_coord + 70;
            x_coord_arrow= x_coord + 90;      
            
            if (ObjectFind("W_prev"+week_back+pair_display) == -1 /*&& result!=i_index*/)
            {
               ObjectCreate("W_prev"+week_back+pair_display, OBJ_LABEL, companion, 0, 0);
               ObjectSet("W_prev"+week_back+pair_display, OBJPROP_COLOR, White);
               ObjectSet("W_prev"+week_back+pair_display, OBJPROP_XDISTANCE, x_coord_numb); //95  // 75
               ObjectSet("W_prev"+week_back+pair_display, OBJPROP_YDISTANCE, y_coord);
            }  

            if (ObjectFind("WA"+week_back+pair_display) == -1 /*&& result!=i_index*/)
            {
               ObjectCreate("WA"+week_back+pair_display, OBJ_LABEL, companion, 0, 0); 
               
               ObjectSet("WA"+week_back+pair_display, OBJPROP_XDISTANCE, x_coord_arrow); //110
               ObjectSet("WA"+week_back+pair_display, OBJPROP_YDISTANCE, y_coord);
            }  
     

            x_coord_numb = x_coord_arrow + 12;
            x_coord_arrow= x_coord_arrow + 32;      
            
            if (ObjectFind("W_now"+week_back+pair_display) == -1 /*&& result!=i_index*/)
            {
               ObjectCreate("W_now"+week_back+pair_display, OBJ_LABEL, companion, 0, 0);
               ObjectSet("W_now"+week_back+pair_display, OBJPROP_COLOR, White);
               ObjectSet("W_now"+week_back+pair_display, OBJPROP_XDISTANCE, x_coord_numb); //95  // 75
               ObjectSet("W_now"+week_back+pair_display, OBJPROP_YDISTANCE, y_coord);
            }  

            if (ObjectFind("WA_now"+week_back+pair_display) == -1 /*&& result!=i_index*/)
            {
               ObjectCreate("WA_now"+week_back+pair_display, OBJ_LABEL, companion, 0, 0); 
               
               ObjectSet("WA_now"+week_back+pair_display, OBJPROP_XDISTANCE, x_coord_arrow); //110
               ObjectSet("WA_now"+week_back+pair_display, OBJPROP_YDISTANCE, y_coord);
            }  

                        
            ObjectSetText("W_prev"+week_back+pair_display, StringSubstr(adx_prev_value,0,4)+" ",7, "Lucida Sands Regular",adx_color_prev);
            ObjectSetText("WA"+week_back+pair_display,adx_arrow_prev,9, "Wingdings",adx_color_prev);

        // if (week_back==1) 
        //     Print (objset,StringSubstr(adx_prev_value,0,4));

            ObjectSetText("W_now"+week_back+pair_display, StringSubstr(adx_now_value,0,4)+" ",7, "Lucida Sands Regular",adx_color_now);
            ObjectSetText("WA_now"+week_back+pair_display,adx_arrow_now,9, "Wingdings",adx_color_now);

      }
      
      return;
}

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
void draw_delimiter (int week_back, int x_coord, int y_coord, int index) {
  
   if (index >= (pairs_num/2) && ObjectFind(week_back+"lin_med") == -1 ){
       ObjectCreate(week_back+"lin_med",OBJ_LABEL,companion,0, 0);
       ObjectSet(week_back+"lin_med",OBJPROP_COLOR,White);
       ObjectSet(week_back+"lin_med", OBJPROP_XDISTANCE, x_coord);
       ObjectSet(week_back+"lin_med", OBJPROP_YDISTANCE, y_coord-10);
       ObjectSetText(week_back+"lin_med","-----------------", 10,
         "Courier New",Yellow);
   }
 return;  
}

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
void delete_objects(int week_back)
{
  for(int m=0;m<=13;m++)
  { 
   if (ObjectFind("WA"+week_back+PairsNames1[m]) > -1 ){
      ObjectDelete("WA"+week_back+PairsNames1[m]);
   }

   if (ObjectFind("W"+week_back+PairsNames1[m]) > -1 ){
      ObjectDelete("W"+week_back+PairsNames1[m]);
   }

   if (ObjectFind("W_prev"+week_back+PairsNames1[m]) > -1 ){
      ObjectDelete("W_prev"+week_back+PairsNames1[m]);
   }

   if (ObjectFind("WA_now"+week_back+PairsNames1[m]) > -1 ){
      ObjectDelete("WA_now"+week_back+PairsNames1[m]);
   }

   if (ObjectFind("W_now"+week_back+PairsNames1[m]) > -1 ){
      ObjectDelete("W_now"+week_back+PairsNames1[m]);
   }


  }
  
   if (ObjectFind(week_back+"b_tot") > -1 ){
      ObjectDelete(week_back+"b_tot");
   }

   if (ObjectFind(week_back+"tot") > -1 ){
      ObjectDelete(week_back+"tot");
   }

   if (ObjectFind(week_back+"s_tot") > -1 ){
      ObjectDelete(week_back+"s_tot");
   }

   if (ObjectFind(week_back+"bu_tot") > -1 ){
      ObjectDelete(week_back+"bu_tot");
   }

   if (ObjectFind(week_back+"bu_lett") > -1 ){
      ObjectDelete(week_back+"bu_lett");
   }

   if (ObjectFind(week_back+"bj_lett") > -1 ){
      ObjectDelete(week_back+"bj_lett");
   }

   if (ObjectFind(week_back+"bo_lett") > -1 ){
      ObjectDelete(week_back+"bo_lett");
   }

   if (ObjectFind(week_back+"u_tot") > -1 ){
      ObjectDelete(week_back+"u_tot");
   }

   if (ObjectFind(week_back+"su_tot") > -1 ){
      ObjectDelete(week_back+"su_tot");
   }

   if (ObjectFind(week_back+"bj_tot") > -1 ){
      ObjectDelete(week_back+"bj_tot");
   }

   if (ObjectFind(week_back+"j_tot") > -1 ){
      ObjectDelete(week_back+"j_tot");
   }

   if (ObjectFind(week_back+"sj_tot") > -1 ){
      ObjectDelete(week_back+"sj_tot");
   }

   if (ObjectFind(week_back+"bo_tot") > -1 ){
      ObjectDelete(week_back+"bo_tot");
   }

   if (ObjectFind(week_back+"o_tot") > -1 ){
      ObjectDelete(week_back+"o_tot");
   }

   if (ObjectFind(week_back+"so_tot") > -1 ){
      ObjectDelete(week_back+"so_tot");
   }

   if (ObjectFind(week_back+"lin") > -1 ){
      ObjectDelete(week_back+"lin");
   }

   if (ObjectFind(week_back+"lin_med") > -1 ){
      ObjectDelete(week_back+"lin_med");
   }

   if (ObjectFind(week_back+"sig_tit") > -1 ){
      ObjectDelete(week_back+"sig_tit");
   }

   if (ObjectFind(week_back+"sig") > -1 ){
      ObjectDelete(week_back+"sig");
   }
   
   if (ObjectFind("buy_move_part") > -1 ){
      ObjectDelete("buy_move_part");
   }

   if (ObjectFind("buy_descr") > -1 ){
      ObjectDelete("buy_descr");
   }

   if (ObjectFind("buy_reset") > -1 ){
      ObjectDelete("buy_reset");
   }

  //----------------- SELLS------------------------------------//
      
     if (ObjectFind("sell_move_part") > -1 ){
         ObjectDelete("sell_move_part");
   }

   if (ObjectFind("sell_descr") > -1 ){
      ObjectDelete("sell_descr");
   }

   if (ObjectFind("sell_reset") > -1 ){
      ObjectDelete("sell_reset");
   }

// --------  For All
  if (ObjectFind("buy_move_part_all") > -1 ){
      ObjectDelete("buy_move_part_all");
   }

   if (ObjectFind("buy_descr_all") > -1 ){
      ObjectDelete("buy_descr_all");
   }

  //----------------- SELLS------------------------------------//
      
  if (ObjectFind("sell_move_part_all") > -1 ){
      ObjectDelete("sell_move_part_all");
   }

   if (ObjectFind("sell_descr_all") > -1 ){
      ObjectDelete("sell_descr_all");
   }
 
// ------------------
   if (ObjectFind("profit_info") > -1 ){
      ObjectDelete("profit_info");
   }

   if (ObjectFind("close_all") > -1 ){
      ObjectDelete("close_all");
   }


}

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
void show_buy_sell(int y_c) {

   int x_c = 0;
   y_c = y_c + 50;
  
   if (ObjectFind("buy_move_part") == -1 ){
      ObjectCreate("buy_move_part", OBJ_LABEL, companion, 0, 0);
      ObjectSet("buy_move_part", OBJPROP_COLOR, RoyalBlue);
      ObjectSet("buy_move_part", OBJPROP_XDISTANCE, x_c);
      ObjectSet("buy_move_part", OBJPROP_YDISTANCE, y_c);
      
      buys_x = x_c;
      buys_y = y_c;
   }

   ObjectSetText("buy_move_part","Move me", 10,"Lucida Console Bold",RoyalBlue);

   if (ObjectFind("buy_descr") == -1 ){
      ObjectCreate("buy_descr", OBJ_LABEL, companion, 0, 0);
      ObjectSet("buy_descr", OBJPROP_COLOR, RoyalBlue);
      ObjectSet("buy_descr", OBJPROP_XDISTANCE, x_c+60);
      ObjectSet("buy_descr", OBJPROP_YDISTANCE, y_c);
   }

   ObjectSetText("buy_descr","[to Open Buy orders when all signals=LONG]", 10,"Lucida Console Bold",RoyalBlue);

   if (ObjectFind("buy_reset") == -1 ){
      ObjectCreate("buy_reset", OBJ_LABEL, companion, 0, 0);
      ObjectSet("buy_reset", OBJPROP_COLOR, RoyalBlue);
      ObjectSet("buy_reset", OBJPROP_XDISTANCE, x_c+350);
      ObjectSet("buy_reset", OBJPROP_YDISTANCE, y_c);

      buys_x_off = x_c+350;
      buys_y_off = y_c;
      
   }

   ObjectSetText("buy_reset","Turn opening buys OFF", 10,"Lucida Console Bold",RoyalBlue);

   if (ObjectFind("close_all") == -1 ){
      ObjectCreate("close_all", OBJ_LABEL, companion, 0, 0);
      ObjectSet("close_all", OBJPROP_COLOR, White);
      ObjectSet("close_all", OBJPROP_XDISTANCE, x_c+550);
      ObjectSet("close_all", OBJPROP_YDISTANCE, y_c);

      close_all_x = x_c+550;
      close_all_y = y_c;
      
   }

   ObjectSetText("close_all","Close all positions", 10,"Lucida Console Bold",White);

   if (ObjectFind("close_all") != -1 ){
      int new_close_all_x=ObjectGet("close_all", OBJPROP_XDISTANCE);
      int new_close_all_y=ObjectGet("close_all", OBJPROP_YDISTANCE);
      
      if (new_close_all_x != close_all_x || new_close_all_y != close_all_y) {
         ObjectSet("close_all", OBJPROP_XDISTANCE, close_all_x);
         ObjectSet("close_all", OBJPROP_YDISTANCE, close_all_y);
         CloseAll();
      }
   }   


   if (ObjectFind("buy_reset") != -1 ){
      int new_x_off=ObjectGet("buy_reset", OBJPROP_XDISTANCE);
      int new_y_off=ObjectGet("buy_reset", OBJPROP_YDISTANCE);
      
      if (new_x_off != buys_x_off || new_y_off != buys_y_off) {
         ObjectSet("buy_reset", OBJPROP_XDISTANCE, buys_x_off);
         ObjectSet("buy_reset", OBJPROP_YDISTANCE, buys_y_off);
         ObjectSet("buy_move_part", OBJPROP_XDISTANCE, buys_x);
         ObjectSet("buy_move_part", OBJPROP_YDISTANCE, buys_y);
      }
   }   


   if (ObjectFind("buy_move_part") != -1 ){
      int new_x=ObjectGet("buy_move_part", OBJPROP_XDISTANCE);
      int new_y=ObjectGet("buy_move_part", OBJPROP_YDISTANCE);
      
      if (new_x != buys_x || new_y != buys_y)
         //Alert("The BUY object was moved!");
         
         //AllLongSignal=1;
         //Print (new_x,"=========",buys_x,"=========",new_y,"=========",buys_y);
         
         if (countBuys()==0 && AllLongSignal==1) {
            ObjectSet("buy_move_part", OBJPROP_XDISTANCE, buys_x);
            ObjectSet("buy_move_part", OBJPROP_YDISTANCE, buys_y);
            Open_Buys();
         }
   }

//-------------- Charvo Added Logic ---------------------
  
   if (IsNewBar(1)) 
   {
      if (countBuys()==0 && LongEntryCondCheck() && BusinessRules_Long==1 && OK2Trade==true)   

//-------------- Charvo Added Logic ---------------------
      {
         Print("$$$$$$$$$$$$$$$$$$$$$$$$$$ Buys = ", countBuys(), " and Long Conditions are ", LongEntryCondCheck(), ".");
         Open_Buys();
         Stop_Rules = true;
      }
   }
 
  //----------------- SELLS------------------------------------//
     y_c = y_c + 20;
      
     if (ObjectFind("sell_move_part") == -1 ){
      ObjectCreate("sell_move_part", OBJ_LABEL, companion, 0, 0);
      ObjectSet("sell_move_part", OBJPROP_COLOR, Tomato);
      ObjectSet("sell_move_part", OBJPROP_XDISTANCE, x_c);
      ObjectSet("sell_move_part", OBJPROP_YDISTANCE, y_c);
      
      sells_x = x_c;
      sells_y = y_c;
   }

   ObjectSetText("sell_move_part","Move me", 10,"Lucida Console Bold",Tomato);

   if (ObjectFind("sell_descr") == -1 ){
      ObjectCreate("sell_descr", OBJ_LABEL, companion, 0, 0);
      ObjectSet("sell_descr", OBJPROP_COLOR, Tomato);
      ObjectSet("sell_descr", OBJPROP_XDISTANCE, x_c+60);
      ObjectSet("sell_descr", OBJPROP_YDISTANCE, y_c);
   }

   ObjectSetText("sell_descr","[to Open Sell orders when all signals=SHORT]", 10,"Lucida Console Bold",Tomato);

   if (ObjectFind("sell_reset") == -1 ){
      ObjectCreate("sell_reset", OBJ_LABEL, companion, 0, 0);
      ObjectSet("sell_reset", OBJPROP_COLOR, Tomato);
      ObjectSet("sell_reset", OBJPROP_XDISTANCE, x_c+350);
      ObjectSet("sell_reset", OBJPROP_YDISTANCE, y_c);

      sells_x_off = x_c+350;
      sells_y_off = y_c;
   }

   ObjectSetText("sell_reset","Turn opening sells OFF", 10,"Lucida Console Bold",Tomato);

   if (ObjectFind("sell_reset") != -1 ){
      int new_s_x_off=ObjectGet("sell_reset", OBJPROP_XDISTANCE);
      int new_s_y_off=ObjectGet("sell_reset", OBJPROP_YDISTANCE);
      
      if (new_s_x_off != sells_x_off || new_s_y_off != sells_y_off) {
         ObjectSet("sell_reset", OBJPROP_XDISTANCE, sells_x_off);
         ObjectSet("sell_reset", OBJPROP_YDISTANCE, sells_y_off);
         ObjectSet("sell_move_part", OBJPROP_XDISTANCE, sells_x);
         ObjectSet("sell_move_part", OBJPROP_YDISTANCE, sells_y);
      }
   }   


   if (ObjectFind("sell_move_part") != -1 ){
      int new_s_x=ObjectGet("sell_move_part", OBJPROP_XDISTANCE);
      int new_s_y=ObjectGet("sell_move_part", OBJPROP_YDISTANCE);
      
      if (new_s_x != sells_x || new_s_y != sells_y)
         //Alert("The SELL object was moved!");
        if (countSells()==0 && AllShortSignal==1) {
            ObjectSet("sell_move_part", OBJPROP_XDISTANCE, sells_x);
            ObjectSet("sell_move_part", OBJPROP_YDISTANCE, sells_y);
            Open_Sells();
         }
   } 

     y_c = y_c + 20;

//------------------------------------------------------------------//
   if (ObjectFind("buy_move_part_all") == -1 ){
      ObjectCreate("buy_move_part_all", OBJ_LABEL, companion, 0, 0);
      ObjectSet("buy_move_part_all", OBJPROP_COLOR, RoyalBlue);
      ObjectSet("buy_move_part_all", OBJPROP_XDISTANCE, x_c);
      ObjectSet("buy_move_part_all", OBJPROP_YDISTANCE, y_c);
      
      buys_x_all = x_c;
      buys_y_all = y_c;
   }

   ObjectSetText("buy_move_part_all","Move me", 10,"Lucida Console Bold",RoyalBlue);

   if (ObjectFind("buy_descr_all") == -1 ){
      ObjectCreate("buy_descr_all", OBJ_LABEL, companion, 0, 0);
      ObjectSet("buy_descr_all", OBJPROP_COLOR, RoyalBlue);
      ObjectSet("buy_descr_all", OBJPROP_XDISTANCE, x_c+60);
      ObjectSet("buy_descr_all", OBJPROP_YDISTANCE, y_c);
   }

   ObjectSetText("buy_descr_all","[to Open Buy orders NOW]", 10,"Lucida Console Bold",RoyalBlue);

   if (ObjectFind("buy_move_part_all") != -1 ){
      new_x=ObjectGet("buy_move_part_all", OBJPROP_XDISTANCE);
      new_y=ObjectGet("buy_move_part_all", OBJPROP_YDISTANCE);
      
      if (new_x != buys_x_all || new_y != buys_y_all)
         
         if (countBuys()==0) {
            ObjectSet("buy_move_part_all", OBJPROP_XDISTANCE, buys_x_all);
            ObjectSet("buy_move_part_all", OBJPROP_YDISTANCE, buys_y_all);
            Open_Buys();
         }
   }

  //----------------- SELLS------------------------------------//
     y_c = y_c + 20;
      
     if (ObjectFind("sell_move_part_all") == -1 ){
      ObjectCreate("sell_move_part_all", OBJ_LABEL, companion, 0, 0);
      ObjectSet("sell_move_part_all", OBJPROP_COLOR, Tomato);
      ObjectSet("sell_move_part_all", OBJPROP_XDISTANCE, x_c);
      ObjectSet("sell_move_part_all", OBJPROP_YDISTANCE, y_c);
      
      sells_x_all = x_c;
      sells_y_all = y_c;
   }

   ObjectSetText("sell_move_part_all","Move me", 10,"Lucida Console Bold",Tomato);

   if (ObjectFind("sell_descr_all") == -1 ){
      ObjectCreate("sell_descr_all", OBJ_LABEL, companion, 0, 0);
      ObjectSet("sell_descr_all", OBJPROP_COLOR, Tomato);
      ObjectSet("sell_descr_all", OBJPROP_XDISTANCE, x_c+60);
      ObjectSet("sell_descr_all", OBJPROP_YDISTANCE, y_c);
   }

   ObjectSetText("sell_descr_all","[to Open Sell orders NOW]", 10,"Lucida Console Bold",Tomato);

    if (ObjectFind("sell_move_part_all") != -1 ){
      new_s_x=ObjectGet("sell_move_part_all", OBJPROP_XDISTANCE);
      new_s_y=ObjectGet("sell_move_part_all", OBJPROP_YDISTANCE);
      
      if (new_s_x != sells_x_all || new_s_y != sells_y_all)
        if (countSells()==0) {
            ObjectSet("sell_move_part_all", OBJPROP_XDISTANCE, sells_x_all);
            ObjectSet("sell_move_part_all", OBJPROP_YDISTANCE, sells_y_all);
            Open_Sells();
         }
   } 
//-----------------------------------------------------------------//


//-------------- Charvo Added Logic ---------------------

   //if (countSells()==0 && BusinessRules_Short==1)    

   if (IsNewBar(1))
   {
      if (countSells()==0 && ShortEntryCondCheck() && BusinessRules_Short==1 && OK2Trade==true)    

//-------------- Charvo Added Logic ---------------------  
      {
         Print("$$$$$$$$$$$$$$$$$$$$$$$$$$ Sells = ", countSells(), " and Short Conditions are ", ShortEntryCondCheck(), ".");
         Open_Sells();
         Stop_Rules = true;
      }
   }
        
   if (Protect_Account)
      ProtectAccount(y_c);
}

//------------------------------------------------------------------

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
double CalculateBasketPL()
{
   double BasketProfit=0;
   int NoOfBasketTrades=0;
   
   for (int cc=0; cc < OrdersTotal(); cc++)
   {
      OrderSelect(cc, SELECT_BY_POS);

      bool lMagic = true;
         
       if (MAGIC > 0 && OrderMagicNumber() != MAGIC)
           lMagic = false;
    
      if (lMagic)
      {
         BasketProfit=BasketProfit+OrderProfit();
      }
   }
   //string ScreenMessage = StringConcatenate(ScreenMessage, "Basket profit = ", BasketProfit, NL);
   //if (LockedProfit > -1) ScreenMessage = StringConcatenate(ScreenMessage, "Locked profits = ", LockedProfit, NL);
   //Comment(ScreenMessage);
   
 return (BasketProfit);   
}

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
void ProtectAccount(int y_coord) {
   double curr_profit = 0;
   double show_locked_profit = 0;

   if ((countBuys() + countSells()) == 0) {
      locked_profit = -999999;
      step_profit = -999999;
      show_locked_profit = 0;
   }
   
   curr_profit = CalculateBasketPL();

  if (curr_profit <=  BASKET_STOPLOSS/Lot_factor || curr_profit >= BASKET_TAKE_PROFIT/Lot_factor) 
  {
     CloseAll();
     Alert("Floating P/L is ", curr_profit, ", Closure criteria met! Basket should be closed by now.");   
  }
   if (curr_profit <= locked_profit && locked_profit>0) CloseAll();
   if (curr_profit >= 5000.0/Lot_factor && locked_profit == 4010.0/Lot_factor) step_profit = 4510/Lot_factor;
   if (curr_profit >= 4500.0/Lot_factor && locked_profit == 3510.0/Lot_factor) step_profit = 4010/Lot_factor;
   if (curr_profit >= 4000.0/Lot_factor && locked_profit == 3010.0/Lot_factor) step_profit = 3510/Lot_factor;
   if (curr_profit >= 3500.0/Lot_factor && locked_profit == 2510.0/Lot_factor) step_profit = 3010/Lot_factor;
   if (curr_profit >= 3000.0/Lot_factor && locked_profit == 2010.0/Lot_factor) step_profit = 2510/Lot_factor;
   if (curr_profit >= 2500.0/Lot_factor && locked_profit == 1510.0/Lot_factor) step_profit = 2010/Lot_factor;
   if (curr_profit >= 2000.0/Lot_factor && locked_profit == 1010.0/Lot_factor) step_profit = 1510/Lot_factor;
   if (curr_profit >= 1500.0/Lot_factor && locked_profit == 710.0/Lot_factor) step_profit = 1010/Lot_factor;
   if (curr_profit >= 1000.0/Lot_factor && locked_profit == 510.0/Lot_factor) step_profit = 710/Lot_factor;
   if (curr_profit >= 700.0/Lot_factor && locked_profit == 410.0/Lot_factor) step_profit = 510/Lot_factor;
   if (curr_profit >= 500.0/Lot_factor && locked_profit == 310.0/Lot_factor) step_profit = 410/Lot_factor;
   if (curr_profit >= 400.0/Lot_factor && locked_profit == 210.0/Lot_factor) step_profit = 310/Lot_factor;
   if (curr_profit >= 300.0/Lot_factor && locked_profit == 110.0/Lot_factor) step_profit = 210/Lot_factor;
   if (curr_profit >= 200.0/Lot_factor && locked_profit == 50.0/Lot_factor) step_profit = 110/Lot_factor;
   if (curr_profit >= 100.0/Lot_factor && (locked_profit == -999999.0 || locked_profit ==0.0)) step_profit = 50/Lot_factor;
   if (step_profit > locked_profit) locked_profit = step_profit;   
   //Print(curr_profit, "========", locked_profit, "=========",step_profit);   
   
   if (locked_profit > 0)
       show_locked_profit = locked_profit;
   
   if (ObjectFind("profit_info") == -1 ){
      ObjectCreate("profit_info", OBJ_LABEL, companion, 0, 0);
      ObjectSet("profit_info", OBJPROP_COLOR, Tomato);
      ObjectSet("profit_info", OBJPROP_XDISTANCE, 0);
      ObjectSet("profit_info", OBJPROP_YDISTANCE, y_coord+20);
   }

   ObjectSetText("profit_info","Basket profit = "+DoubleToStr(curr_profit,2)+"     "+"Locked profit = "+DoubleToStr(show_locked_profit,2), 10,"Lucida Console Bold",White);   
   return;
}

// ----------------------------------------------------------
//                       Charvo Added CloseAll SUB
//                       Orest's closeall often DOES NOT work
// ----------------------------------------------------------
void CloseAll()
{
      
   for (int cc=0; cc<OrdersTotal(); cc++)
   {
      OrderSelect(cc,SELECT_BY_POS);
      if (OrderMagicNumber()==MAGIC)      
      {
         if (OrderType()==OP_BUY)
         {
            bool result=OrderClose(OrderTicket(),OrderLots(), MarketInfo(OrderSymbol(), MODE_BID),5,CLR_NONE);
            if (result) cc--;   
         }//if (OrderType()==OP_BUY)   
         
         if (OrderType()==OP_SELL)
         {
            result=OrderClose(OrderTicket(),OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK),5,CLR_NONE);
            if (result) cc--;
         }//if (OrderType()==OP_SELL)   
         
      }//if (OrderMagicNumber()==MagicNumber)
   }//for (int cc=0; cc<OrdersTotal(); cc++)
   
}// end void CloseBasketTrades()


// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
void Open_Buys()
  {
   
    for(int i=0;i<=13;i++)
    { 
         string Pair_name = ""+  StringTrimRight(StringTrimLeft(PairsNames1[i]))  ; // Buy
         if (StringLen(Pair_name) > 0 && (Pair_name != LoserPair1+pair_suffix && Pair_name != LoserPair2+pair_suffix))  {
            OrderSend(Pair_name, OP_BUY, Lot, MarketInfo(Pair_name,MODE_ASK), Slippage, 0, 0, "Basket Buy(#" + MAGIC + ")", MAGIC, 0, DodgerBlue);
            Sleep(1000);
         }
    }

    if (AntiPos == true)  {
         OrderSend(LoserPair1+pair_suffix, OP_SELL, Lot, MarketInfo(LoserPair1+pair_suffix,MODE_BID), Slippage, 0, 0, "Basket Buy-Anti(#" + MAGIC + ")", MAGIC, 0, DodgerBlue);
         OrderSend(LoserPair2+pair_suffix, OP_SELL, Lot, MarketInfo(LoserPair2+pair_suffix,MODE_BID), Slippage, 0, 0, "Basket Buy-Anti(#" + MAGIC + ")", MAGIC, 0, DodgerBlue);
         Sleep(1000);
    }



   return;
  }

// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
void Open_Sells()
  {

    for(int i=0;i<=13;i++)
    { 
         string Pair_name = ""+StringTrimRight(StringTrimLeft(PairsNames1[i])); // Sell
         if (StringLen(Pair_name) > 0 && (Pair_name != LoserPair1+pair_suffix && Pair_name != LoserPair2+pair_suffix))  {
            OrderSend(Pair_name, OP_SELL, Lot, MarketInfo(Pair_name,MODE_BID), Slippage, 0, 0, "Basket Sell(#" + MAGIC + ")", MAGIC, 0, Tomato);
            Sleep(1000);
         }   
    }
    
    if (AntiPos == true)  {
         OrderSend(LoserPair1+pair_suffix, OP_BUY, Lot, MarketInfo(LoserPair1+pair_suffix,MODE_ASK), Slippage, 0, 0, "Basket Sell-Anti(#" + MAGIC + ")", MAGIC, 0, DodgerBlue);
         OrderSend(LoserPair2+pair_suffix, OP_BUY, Lot, MarketInfo(LoserPair2+pair_suffix,MODE_ASK), Slippage, 0, 0, "Basket Sell-Anti(#" + MAGIC + ")", MAGIC, 0, DodgerBlue);
         Sleep(1000);
    }
    

   return;
  }
 
// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
 int countBuys() {
   int num_buys = 0;
   
   for (int cc=0; cc < OrdersTotal(); cc++)
   {
      OrderSelect(cc, SELECT_BY_POS);

      bool lMagic = true;
         
       if (MAGIC > 0 && OrderMagicNumber() != MAGIC)
           lMagic = false;
    
      if (lMagic && OrderType()==OP_BUY)
      {
         num_buys++;
      }
   }
 
   return (num_buys); 
 }
 
// ----------------------------------------------------------
//                       SUBROUTINES
// ----------------------------------------------------------
 int countSells() {
   int num_sells = 0;
   
   for (int cc=0; cc < OrdersTotal(); cc++)
   {
      OrderSelect(cc, SELECT_BY_POS);

      bool lMagic = true;
         
       if (MAGIC > 0 && OrderMagicNumber() != MAGIC)
           lMagic = false;
    
      if (lMagic && OrderType()==OP_SELL)
      {
         num_sells++;
      }
   }
 
   return (num_sells); 
  }
// ----------------Charvo Added Function---------------------
//                       SUBROUTINES
// ----------------Charvo Added Function---------------------
 bool LongEntryCondCheck() {
 
   bool longconditions = false;
   bool breakOK = false;
       
   if ( UseSR == true && MarketInfo(LeadingPair+pair_suffix, MODE_BID) > iCustom(LeadingPair+pair_suffix, SRTF, "Support and Resistance", 0, 0) )
   {
      breakOK = true;
   }  
   else if (UseSR == false)
   {
      breakOK = true;
   }  

   //Print("$$$$$$$$$ Entry Conditions: 1. buyallOK ", buyallOK, "; PAok ", PAok, "; breakOK ", breakOK, "; and cross is ", DoubleToStr(CheckRecntCrx(lookback4X, 1),1), ".");
   Print("$$$ breakOK is ", breakOK, "; and cross is ", CheckRecntCrx(lookback4X, 1), ".");   
     
   if (breakOK==true && CheckRecntCrx(lookback4X, 1)==1) longconditions = true;  
   
   return (longconditions); 
  }
// ----------------Charvo Added Function---------------------
//                       SUBROUTINES
// ----------------Charvo Added Function---------------------
 bool ShortEntryCondCheck() {
 
   bool shortconditions = false;
   bool breakOK = false;
      
   if ( UseSR == true && MarketInfo(LeadingPair+pair_suffix, MODE_ASK) < iCustom(LeadingPair+pair_suffix, SRTF, "Support and Resistance", 1, 0) )
   {
      breakOK = true;
   }  
   else if (UseSR == false)
   {
      breakOK = true;
   }  

   Print("$$$ breakOK is ", breakOK, "; and cross is ", CheckRecntCrx(lookback4X, -1), ".");
        
   if (breakOK==true && CheckRecntCrx(lookback4X, -1)==-1) shortconditions = true;  
   
   return (shortconditions); 
  }
// ----------------Charvo Added Function---------------------
//                       SUBROUTINES
// ----------------Charvo Added Function---------------------
 bool CheckRecntCrx(int lookback, int updn) 
 {
   // updn: 1 to check cross up; -1 to check cross down;
   int i;
   double BuyAll_fast, BuyAll_slow, BuyAll_fast_pre, BuyAll_slow_pre;
   int cross;

   for(i=0; i<=lookback;i++)
   {
      BuyAll_fast = iCustom(LeadingPair+pair_suffix,buyallTF,"BI_T101_OTR_V1_5",10,5,288,0.0,0.0,"Check_Candle : 0 for current , 1 for last closed candle",0,false," 0 for S_R , 1 for Fast/Slow cross",1,"Alert.wav","Alert2.wav",false,0,i);
      BuyAll_slow = iCustom(LeadingPair+pair_suffix,buyallTF,"BI_T101_OTR_V1_5",10,5,288,0.0,0.0,"Check_Candle : 0 for current , 1 for last closed candle",0,false," 0 for S_R , 1 for Fast/Slow cross",1,"Alert.wav","Alert2.wav",false,1,i);
      BuyAll_fast_pre = iCustom(LeadingPair+pair_suffix,buyallTF,"BI_T101_OTR_V1_5",10,5,288,0.0,0.0,"Check_Candle : 0 for current , 1 for last closed candle",0,false," 0 for S_R , 1 for Fast/Slow cross",1,"Alert.wav","Alert2.wav",false,0,i+1);
      BuyAll_slow_pre = iCustom(LeadingPair+pair_suffix,buyallTF,"BI_T101_OTR_V1_5",10,5,288,0.0,0.0,"Check_Candle : 0 for current , 1 for last closed candle",0,false," 0 for S_R , 1 for Fast/Slow cross",1,"Alert.wav","Alert2.wav",false,1,i+1);

      if ( updn==1 && (BuyAll_fast>BuyAll_slow+0.001 && BuyAll_fast_pre<BuyAll_slow_pre) )  cross = 1;
      if ( cross != 0 ) break;
      if ( updn==-1 && (BuyAll_fast<BuyAll_slow-0.001 && BuyAll_fast_pre>BuyAll_slow_pre) )  cross = -1;
      if ( cross != 0 ) break;
   }     
 
   if (cross != 0) Print("XXXXXX Cross is found for ", cross, " around ", i, "th bar!XXXXXX");
   
   return(cross);
      
 } 
// ----------------Charvo Added Function---------------------
//                       SUBROUTINES
// ----------------Charvo Added Function---------------------
bool IsNewBar(int timeFrame)
   {
   bool res=false;
   
   static datetime _sTime[9]; 
   int i;
 
   switch (timeFrame) 
      {
      case 1  : i=0; break;
      case 5  : i=1; break;
      case 15 : i=2; break;
      case 30 : i=3; break;
      case 60 : i=4; break;
      case 240: i=5;break;
      case 1440:i=6;break;
      case 10080:i=7;break;
      case 43200:i=8;break;
      default:  timeFrame = 1;
      }

   if (_sTime[i]==0 || _sTime[i]!=iTime("GBPJPY",timeFrame,0))
      {
      _sTime[i] = iTime("GBPJPY"+pair_suffix,timeFrame,0);
      res=true;
      }
   return(res);   
}