//+------------------------------------------------------------------+
//|                                           !!BaseInfoPanel_v1.mq4 |
//|                                                         derMitay |
//|                                       www.forum.tradelikeapro.ru |
//+------------------------------------------------------------------+
#property copyright "derMitay"
#property link      "www.forum.tradelikeapro.ru"
#property version   "1.00"
#property strict
/*#include <stdlib.mqh>
#include <WinUser32.mqh>
#include <ChartObjects\ChartObjectsTxtControls.mqh>
*/
#define BullColor Lime
#define BearColor Red

enum dbu {Constant=0,OneMinute=1,FiveMinutes=5};

sinput   string   t_trade    = "EXPERT MANAGEMENT"; // =================================
sinput bool                      UseDefaultPairs            = true;              // Use the default 28 pairs
sinput string                    OwnPairs                   = "";                // Comma seperated own pair list
sinput dbu                       DashUpdate                 = 0;                 // Dashboard update interval
sinput int                       Magic_Number               = 0;
sinput bool                      autotrade                  = false;

sinput   string   t_trigger = "TRIGGER MANAGEMENT"; // =================================
sinput   bool                    trigger_use_Pips           = true;              // Use Pips
sinput   double                  trade_MIN_pips             = 8;                // Minimum pips to open position
/*sinput   bool                    trigger_UseHeatMap1        = true;             // Use Heat Map
sinput   ENUM_TIMEFRAMES         trigger_TF_HM1             = 1440;              // TimeFrame for Heat Map 
sinput   double                  trade_MIN_HeatMap1         = 0.5;               // Minimum % HeatMap to open position
sinput   bool                    trigger_use_bidratio       = true;              // Use BidRatio filtering
sinput   double                  trigger_buy_bidratio       = 60;                // % Level to open Buy
sinput   double                  trigger_sell_bidratio      = 30;                // % Level to open Sell
sinput   bool                    trigger_use_relstrength    = true;              // Use Relative Strength filtering (Base)
sinput   double                  trigger_buy_relstrength    = 5.0;               // Strenth to open Buy
sinput   double                  trigger_sell_relstrength   =-5.0;               // Strength to open Sell
sinput   bool                    trigger_use_buysellratio   = true;              // Use Buy/Sell Ratio filtering
sinput   double                  trigger_buy_buysellratio   = 4.0;               // Level to open Buy
sinput   double                  trigger_sell_buysellratio  = -4.0;              // level to open Sell
sinput   bool                    trigger_use_gap            = true;              // Use Gap filtering
sinput   double                  trigger_gap_buy            = 0.6;               // Gap level to open Buy
sinput   double                  trigger_gap_sell           =- 0.6;              // Gap level to open Sell
sinput   bool                    trigger_use_RSI            = true;              // Use RSI filtering
sinput   double                  trigger_buy_RSI            = 75;                // RSI level to open Buy
sinput   double                  trigger_sell_RSI           =25;                 // RSI level to open Sell
sinput   int                     trigger_RSI_period         =2;                  // RSI Period
sinput   ENUM_TIMEFRAMES         trigger_RSI_Timeframe      = 30;                // RSI Timeframe
sinput   ENUM_APPLIED_PRICE      trigger_RSI_Applied        =0;                  // RSI Applied Price
sinput   int                     trigger_RSI_shift          =0;                  // RSI 0=current bar 1=previous bar

sinput   bool                    trigger_use_SSRC            = true;              // Use SSRC filtering
sinput   double                  trigger_low_SSRC            = -0.85;                // за этим пределом перекраш в зеленый
sinput   double                  trigger_high_SSRC           =0.85;                 // за этим пределом перекраш в красный
sinput   double                  trigger_buy_SSRC            =-0.9;                // SSRC level to open Buy
sinput   double                  trigger_sell_SSRC           =0.9;                 // SSRC level to open Sell
sinput   int                     trigger_SSRC_snakerange     =3;                  // SSRC Snake Range 
sinput   int                     trigger_SSRC_filtperiod     =21;                // SSRC Period
sinput   double                  trigger_SSRC_martfiltr      =2.0;                  // SSRC martfiltr
sinput   ENUM_APPLIED_PRICE      trigger_SSRC_Applied         =6;                  // SSRC Applied Pricesinput  
sinput   int                     trigger_SSRC_shift          =0;                  // SSRC 0=current bar 1=previous bar


sinput   bool                    trigger_Candle_DirectionScalp   = false;         // Scalp M1&M5 Candle Direction
sinput   bool                    trigger_Candle_DirectionSwing   = false;         // Swing M15-Mn Candle Direction
sinput   bool                    trigger_Moving_Average1     = false;              // Use MA 1
sinput   int                     trade_Period_MA1            = 5;                 // MA Period (Small)
sinput   bool                    trigger_Moving_Average2     = false;              // Use MA 2
sinput   int                     trade_Period_MA2            = 12;                 // MA Period (Big)*/

sinput   string   t_basket = "BASKET MANAGEMENT"; // =================================
sinput double                    lot                        = 0.01;
sinput int                       MaxTrades                  = 3;                  // Max trades per pair
sinput int                       MaxTotalTrades             = 0;                  // Max total trades overall
sinput int                       MaxSpread                  = 4.0;                // Max Spread Allowe
sinput int                       Basket_Target              = 0;                  // Basket Take Profit in $
sinput int                       Basket_StopLoss            = 0;                  // Basket Stop Lloss in $
sinput int                       Piptp                      = 0;                  // Takeprofit in pips 
sinput int                       Pipsl                      = 0;                  // Stoploss in pips 
sinput double                    BasketP1                   = 0.0;                // At profit 1
sinput double                    BasketL1                   = 0.0;                // Lock 1
sinput double                    BasketP2                   = 0.0;                // At profit 2
sinput double                    BasketL2                   = 0.0;                // Lock 2
sinput double                    BasketP3                   = 0.0;                // At profit 3
sinput double                    BasketL3                   = 0.0;                // Lock 3
sinput double                    BasketP4                   = 0.0;                // At profit 4
sinput double                    BasketL4                   = 0.0;                // Lock 4
sinput double                    BasketP5                   = 0.0;                // At profit 5
sinput double                    BasketL5                   = 0.0;                // Lock 5
sinput double                    BasketP6                   = 0.0;                // At profit 6
sinput double                    BasketL6                   = 0.0;                // Lock 6
sinput bool                      TrailLastLock              = true;               // Trail the last set lock
sinput double                    TrailDistance              = 0.0;                // Trail distance 0 means last lock
sinput int                       StopProfit                 = 0;                  // Stop after this many profitable baskets
sinput double                    Adr1tp                     = 0;                 // Takeprofit percent adr(10) 0=None
sinput double                    Adr1sl                     = 0;                 // Stoploss adr percent adr(10) 0 = None
sinput int                       StopLoss                   = 0;                  // Stop after this many losing baskets baskets
sinput bool                      OnlyAddProfit              = true;               // Only adds trades in profit 
sinput bool                      CloseAllSession            = false;              // Close all trades after session(s)

sinput   string   t_time = "TIME MANAGEMENT"; // =================================
sinput bool                      UseSession1                = true;
sinput string                    sess1start                 = "00:00";
sinput string                    sess1end                   = "23:59";
sinput string                    sess1comment               = "AUTO SESS1";
sinput bool                      UseSession2                = false;
sinput string                    sess2start                 = "00:00";
sinput string                    sess2end                   = "23:59";
sinput string                    sess2comment               = "AUTO SESS2";
sinput bool                      UseSession3                = false;
sinput string                    sess3start                 = "00:00";
sinput string                    sess3end                   = "23:59";
sinput string                    sess3comment               = "AUTO SESS3";

sinput   string   t_chart = "CHART MANAGEMENT"; // =================================
sinput bool                      EnableCur                  = true;              //Enable Currencies Buttons
sinput ENUM_TIMEFRAMES           TimeFrame                  = 30;                //TimeFrame to open chart
sinput string                    usertemplate               = "Default";
sinput int                       x_axis                     =0;
sinput int                       y_axis                    =65;
sinput bool    autoTimeFrame     = true;
sinput ENUM_TIMEFRAMES           timeFrame         = 30;
int userTimeFrame;

int BeforeMin = 15;
int FontSize = 12;
string FontName = "Lucida Console";
int ShiftX = 250;
int ShiftY = 70;
int Corner = 0;

string button_close_basket_All = "btn_Close ALL"; 
string button_close_basket_Prof = "btn_Close Prof";
string button_close_basket_Loss = "btn_Close Loss";

string button_reset_ea = "RESET EA";
 
string button_EUR_basket = "EUR_BASKET"; 
string button_EUR_basket_buy = "EUR_BASKET_BUY";
string button_EUR_basket_sell = "EUR_BASKET_SELL";
string button_EUR_basket_close = "EUR_BASKET_CLOSE";

string button_GBP_basket = "GBP_BASKET"; 
string button_GBP_basket_buy = "GBP_BASKET_BUY";
string button_GBP_basket_sell = "GBP_BASKET_SELL";
string button_GBP_basket_close = "GBP_BASKET_CLOSE";

string button_CHF_basket = "CHF_BASKET"; 
string button_CHF_basket_buy = "CHF_BASKET_BUY";
string button_CHF_basket_sell = "CHF_BASKET_SELL";
string button_CHF_basket_close = "CHF_BASKET_CLOSE";

string button_USD_basket = "USD_BASKET"; 
string button_USD_basket_buy = "USD_BASKET_BUY";
string button_USD_basket_sell = "USD_BASKET_SELL";
string button_USD_basket_close = "USD_BASKET_CLOSE";

string button_CAD_basket = "CAD_BASKET"; 
string button_CAD_basket_buy = "CAD_BASKET_BUY";
string button_CAD_basket_sell = "CAD_BASKET_SELL";
string button_CAD_basket_close = "CAD_BASKET_CLOSE";

string button_NZD_basket = "NZD_BASKET"; 
string button_NZD_basket_buy = "NZD_BASKET_BUY";
string button_NZD_basket_sell = "NZD_BASKET_SELL";
string button_NZD_basket_close = "NZD_BASKET_CLOSE";

string button_AUD_basket = "AUD_BASKET"; 
string button_AUD_basket_buy = "AUD_BASKET_BUY";
string button_AUD_basket_sell = "AUD_BASKET_SELL";
string button_AUD_basket_close = "AUD_BASKET_CLOSE";

string button_JPY_basket = "JPY_BASKET"; 
string button_JPY_basket_buy = "JPY_BASKET_BUY";
string button_JPY_basket_sell = "JPY_BASKET_SELL";
string button_JPY_basket_close = "JPY_BASKET_CLOSE";
 
string DefaultPairs[] = {"AUDCAD","AUDCHF","AUDJPY","AUDNZD","AUDUSD","CADCHF","CADJPY","CHFJPY","EURAUD","EURCAD","EURCHF","EURGBP","EURJPY","EURNZD","EURUSD","GBPAUD","GBPCAD","GBPCHF","GBPJPY","GBPNZD","GBPUSD","NZDCAD","NZDCHF","NZDJPY","NZDUSD","USDCAD","USDCHF","USDJPY"};
string TradePairs[];
string curr[8] = {"USD","EUR","GBP","JPY","AUD","NZD","CAD","CHF"};
string EUR[7] = {"EURAUD","EURCAD","EURCHF","EURGBP","EURJPY","EURNZD","EURUSD"};
string GBP[6] = {"GBPAUD","GBPCAD","GBPCHF","GBPJPY","GBPNZD","GBPUSD"};
string GBP_R[1] = {"EURGBP"};
string CHF[1] = {"CHFJPY"};
string CHF_R[6] = {"AUDCHF","CADCHF","EURCHF","GBPCHF","NZDCHF","USDCHF"};
string USD[3] = {"USDCAD","USDCHF","USDJPY"};
string USD_R[4] = {"AUDUSD","EURUSD","GBPUSD","NZDUSD"};
string CAD[2] = {"CADCHF","CADJPY"};
string CAD_R[5] = {"AUDCAD","EURCAD","GBPCAD","NZDCAD","USDCAD"};
string NZD[4] = {"NZDCAD","NZDCHF","NZDJPY","NZDUSD"};
string NZD_R[3] = {"AUDNZD","EURNZD","GBPNZD"};
string AUD[5] = {"AUDCAD","AUDCHF","AUDJPY","AUDNZD","AUDUSD"};
string AUD_R[2] = {"EURAUD","GBPAUD"};
string JPY_R[7] = {"AUDJPY","CADJPY","CHFJPY","EURJPY","GBPJPY","NZDJPY","USDJPY"};

string   _font="Consolas";
string TMz;
datetime LastAlertTime;
long           thisChart;
int            timeOffset;
datetime       ServerLocalOffset;
datetime       localtime;
int Broker_Time_Offset = 3;
int Alert_Mod = 1; // Select Alert Mode 



struct pairinf {
   double PairPip;
   int pipsfactor;
   double Pips;
   double PipsSig;
   double Pipsprev;
   double Spread;
   double point;
   int lastSignal;
   string   base;
   string    quote;   
}; pairinf pairinfo[];

struct LBSRat{
 double LBSr;
}; LBSRat LBSRatio[];


#define NONE 0
#define DOWN -1
#define UP 1

#define  UPFv 4
#define  DOWNFn -4
#define  UPfv 3
#define  DOWNfn -3
#define  UPfo 2
#define  DOWNfo -2



#define NOTHING 0
#define BUY 1
#define SELL 2

struct signal { 
   string symbol;
   double range;
   double range1;
   double ratio;
   double ratio1;
   double bidratio;
   double fact;
   double strength;
   double strength1;
   double strength2;
   double calc;
   double strength3;
   double strength4;
   double strength5;
   double strength6;
   double strength7;
   double strength8;
   double strength_Gap;
   double hi;
   double lo;
   double prevratio;   
   double prevbid;   
   int    shift;
   double open;
   double close;
   double bid;
   double point;   
   double Signalperc;   
   double SigRatio;
   double SigRelStr;
   double SigBSRatio;    
   double SigCRS;
   double SigGap;
   double SigGapPrev;
   double SigRatioPrev;
   double RSI;
   double SigRSI;
   double Signalrsi;
   double highRatio;
   double lowRatio;
   double xLBSr;
   
  // double SSRC;
  // double SignalSSRC;
  // double DirrSSRC;
  // double SSRCSig;
   
   double Signalfl;
   double Signalfl0;
   double Signalfl1;
   double Signalfl2;
   double Signalfl0up;
   double Signalfl0dn;
   double Signalfl1up;
   double Signalfl1dn;
   double Signalfl2up;
   double Signalfl2dn;
   
   double Signalm1;
   double Signalm5;
   double Signalm15;
   double Signalm30;
   double Signalh1;
   double Signalh4;
   double Signald1;
   double Signalw1;
   double Signalmn;
   double SignaldirupScalp;
   double SignaldirdnScalp;
   double SignaldirupSwing;
   double SignaldirdnSwing;

   double SignalhaM1;
   double SignalhaM5;
   double SignalmaM1up;
   double SignalmaM1dn;
   double SignalmaM5up;
   double SignalmaM5dn;

   
}; signal signals[];

struct currency 
  {
   string            curr;
   double            strength;
   double            prevstrength;
   double            crs;
   int               sync;
   datetime          lastbar;
  }
; currency currencies[8];

double totalbuystrength,totalsellstrength;
color Color,Color1,Color2,Color3,Color4,Color5,Color6,Color7,Color8;
color ProfitColor,ProfitColor1,ProfitColor2,ProfitColor3,PipsColor,LotColor,LotColor1,OrdColor,OrdColor1;
color BackGrnCol =C'20,20,20';
color LineColor=clrBlack;
color TextColor=clrBlack;

struct adrval {
   double adr;
   double adr1;
   double adr5;
   double adr10;
   double adr20;
}; adrval adrvalues[];

double totalprofit,totallots;

datetime s1start,s2start,s3start;
datetime s1end,s2end,s3end;

string comment;
int strper = PERIOD_W1;
int profitbaskets = 0;
int lossbaskets = 0;
int ticket;
int    orders  = 0;
double blots[28],slots[28],bprofit[28],sprofit[28],tprofit[28],bpos[28],spos[28];
double tloss,tprof;
bool CloseAll;
string postfix=StringSubstr(Symbol(),6,6);
int   symb_cnt=0;
int period1[]= {240,1440,10080};
double factor;
int labelcolor; 
double GetBalanceSymbol,SymbolMaxDD,SymbolMaxHi;
double PercentFloatingSymbol=0;
double PercentMaxDDSymbol=0;
datetime newday=0;
datetime newm1=0; 
bool   Accending=true;
/* HP */
int localday = 99;
bool s1active = false;
bool s2active = false;
bool s3active = false;
MqlDateTime sess;
string strspl[];
double currentlock = 0.0;
bool trailstarted = false;
double lockdistance = 0.0;
int totaltrades = 0;
int maxtotaltrades=0;
double stoploss;
double takeprofit;
double currstrength[8];
double prevstrength[8];
string Sig[28],Sell;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {   
                  
    if (UseDefaultPairs == true)
      ArrayCopy(TradePairs,DefaultPairs);
    else
      StringSplit(OwnPairs,',',TradePairs);
   
  for (int i=0;i<8;i++)
      currencies[i].curr = curr[i]; 
   
   if (ArraySize(TradePairs) <= 0) {
      Print("No pairs to trade");
      return(INIT_FAILED);
   }
   
   ArrayResize(adrvalues,ArraySize(TradePairs));
   ArrayResize(signals,ArraySize(TradePairs));
   ArrayResize(pairinfo,ArraySize(TradePairs));
          
    for(int i=0;i<ArraySize(TradePairs);i++){
    TradePairs[i]=TradePairs[i]+postfix;    

     pairinfo[i].base = StringSubstr(TradePairs[i],0,3);
     pairinfo[i].quote = StringSubstr(TradePairs[i],3,0);
   
      if (MarketInfo(TradePairs[i] ,MODE_DIGITS) == 4 || MarketInfo(TradePairs[i] ,MODE_DIGITS) == 2) {
         pairinfo[i].PairPip = MarketInfo(TradePairs[i] ,MODE_POINT);
         pairinfo[i].pipsfactor = 1;
      } else { 
         pairinfo[i].PairPip = MarketInfo(TradePairs[i] ,MODE_POINT)*10;
         pairinfo[i].pipsfactor = 10;
      }
       
         //SetPanel("BarSupMeter",0,x_axis,y_axis-30,1300,30,clrDarkSlateGray,C'61,61,61',1);                
        // SetPanel("Bar",0,x_axis,y_axis,1300,450,C'30,30,30',C'61,61,61',1);
         //SetPanel("Panel",0,x_axis+1100,y_axis+13,130,150,C'30,30,30',clrWhite,1);// Была панелька вокруг метра.
         //SetPanel("BottPanel",0,x_axis+405,y_axis+450,602,77,C'30,30,30',clrWhite,1);
      /*   SetPanel("Spread"+IntegerToString(i),0,x_axis+60,(i*16)+y_axis-2,30,17,C'10,10,10',clrWhite,1);
         SetPanel("Pips"+IntegerToString(i),0,x_axis+90,(i*16)+y_axis-2,35,17,clrSilver,clrWhite,1);
         SetPanel("Adr"+IntegerToString(i),0,x_axis+125,(i*16)+y_axis-2,28,17,clrSilver,clrWhite,1);
         SetPanel("BidRatio"+IntegerToString(i),0,x_axis+153,(i*16)+y_axis-2,59,17,clrBlack,C'61,61,61',1);
         SetPanel("RelStr"+IntegerToString(i),0,x_axis+212,(i*16)+y_axis-2,17,17,clrBlack,C'61,61,61',1);
         SetPanel("BSRatio"+IntegerToString(i),0,x_axis+229,(i*16)+y_axis-2,24,17,clrBlack,C'61,61,61',1);
         SetPanel("LSB"+IntegerToString(i),0,x_axis+253,(i*16)+y_axis-2,24,17,clrBlack,C'61,61,61',1);
         SetPanel("GAP123"+IntegerToString(i),0,x_axis+277,(i*16)+y_axis-2,38,17,clrBlack,C'61,61,61',1);         
         SetPanel("MA1"+IntegerToString(i),0,x_axis+315,(i*16)+y_axis-2,18,17,clrBlack,C'61,61,61',1);
         SetPanel("MA2"+IntegerToString(i),0,x_axis+332,(i*16)+y_axis-2,18,17,clrBlack,C'61,61,61',1);
         SetPanel("RSI"+IntegerToString(i),0,x_axis+350,(i*16)+y_axis-2,40,17,clrBlack,C'61,61,61',1);         
         SetPanel("HM1"+IntegerToString(i),0,x_axis+390,(i*16)+y_axis-2,40,17,BackGrnCol,C'61,61,61',1);         
         SetPanel("m1"+IntegerToString(i),0,x_axis+430,(i*16)+y_axis-2,15,17,Color2,clrWhite,1);
         SetPanel("m5"+IntegerToString(i),0,x_axis+445,(i*16)+y_axis-2,15,17,Color3,clrWhite,1);
         SetPanel("m15"+IntegerToString(i),0,x_axis+460,(i*16)+y_axis-2,15,17,Color4,clrWhite,1);
         SetPanel("m30"+IntegerToString(i),0,x_axis+475,(i*16)+y_axis-2,15,17,Color5,clrWhite,1);
         SetPanel("h1"+IntegerToString(i),0,x_axis+490,(i*16)+y_axis-2,15,17,Color6,clrWhite,1);
         SetPanel("h4"+IntegerToString(i),0,x_axis+505,(i*16)+y_axis-2,15,17,Color7,clrWhite,1);
         SetPanel("d1"+IntegerToString(i),0,x_axis+520,(i*16)+y_axis-2,15,17,Color8,clrWhite,1);
         SetPanel("Slm1"+IntegerToString(i),0,x_axis+535,(i*16)+y_axis-2,35,17,BackGrnCol,C'61,61,61',1);    
         SetPanel("Slm5"+IntegerToString(i),0,x_axis+570,(i*16)+y_axis-2,35,17,BackGrnCol,C'61,61,61',1);    
         SetPanel("Slm15"+IntegerToString(i),0,x_axis+605,(i*16)+y_axis-2,35,17,BackGrnCol,C'61,61,61',1);
         SetPanel("SSRC"+IntegerToString(i),0,x_axis+640,(i*16)+y_axis-2,40,17,BackGrnCol,C'61,61,61',1); 
         SetPanel("SSRCsig"+IntegerToString(i),0,x_axis+680,(i*16)+y_axis-2,20,17,BackGrnCol,C'61,61,61',1);
         SetPanel("FL1/FL2"+IntegerToString(i),0,x_axis+700,(i*16)+y_axis-2,40,17,BackGrnCol,C'61,61,61',1); */       
        /* SetPanel("TP",0,x_axis+1300,y_axis-27,55,20,Black,White,1);
         SetPanel("TP1",0,x_axis+280,y_axis-50,125,20,Black,White,1);
         SetPanel("TP2",0,x_axis+405,y_axis-50,160,20,Black,White,1);
         SetPanel("TP3",0,x_axis+565,y_axis-50,160,20,Black,White,1);
         SetPanel("TP4",0,x_axis+725,y_axis-50,130,20,Black,White,1);
         SetPanel("TP5",0,x_axis+855,y_axis-50,130,20,Black,White,1);
         SetPanel("TP6",0,x_axis+155,y_axis-50,100,20,Black,White,1);
         SetPanel("TP7",0,x_axis+981,y_axis-50,130,20,Black,White,1);
         SetPanel("TP8",0,x_axis+1111,y_axis-50,22,20,Black,White,1);
         SetPanel("TP9",0,x_axis+1133,y_axis-50,22,20,Black,White,1);       */ 
         SetPanel("A2"+IntegerToString(i),0,x_axis+190,(i*16)+y_axis,270,17,C'30,30,30',C'61,61,61',2);          
       
        /// SetText("Pr1"+IntegerToString(i),StringSubstr(TradePairs[i],0,6),x_axis+594,(i*16)+y_axis,clrWhite,8);
       //  SetText("Pr2"+IntegerToString(i),StringSubstr(TradePairs[i],0,6),x_axis+985,(i*16)+y_axis,clrWhite,8);
         SetText("Spr1"+IntegerToString(i),0,x_axis+135,(i*16)+y_axis+2,Orange,9);
       //  SetText("Pp1"+IntegerToString(i),0,x_axis+95,(i*16)+y_axis,PipsColor,8);
         SetText("S1"+IntegerToString(i),0,x_axis+160,(i*16)+y_axis+2,Yellow,9);
         SetText("bLots"+IntegerToString(i),DoubleToStr(blots[i],2),x_axis+200,(i*16)+y_axis,C'61,61,61',8);
         SetText("sLots"+IntegerToString(i),DoubleToStr(slots[i],2),x_axis+238,(i*16)+y_axis,C'61,61,61',8);
         SetText("bPos"+IntegerToString(i),DoubleToStr(bpos[i],0),x_axis+278,(i*16)+y_axis,C'61,61,61',8);
         SetText("sPos"+IntegerToString(i),DoubleToStr(spos[i],0),x_axis+299,(i*16)+y_axis,C'61,61,61',8);
         SetText("TProf"+IntegerToString(i),DoubleToStr(MathAbs(bprofit[i]),2),x_axis+320,(i*16)+y_axis,C'61,61,61',8);
         SetText("SProf"+IntegerToString(i),DoubleToStr(MathAbs(sprofit[i]),2),x_axis+367,(i*16)+y_axis,C'61,61,61',8);
         SetText("TtlProf"+IntegerToString(i),DoubleToStr(MathAbs(tprofit[i]),2),x_axis+420,(i*16)+y_axis,C'61,61,61',8);
         SetText("TotProf",DoubleToStr(MathAbs(totalprofit),2),x_axis+420,y_axis-30,ProfitColor1,8);         
         SetText("Lowest","Lowest= "+DoubleToStr(SymbolMaxDD,2)+" ("+DoubleToStr(PercentMaxDDSymbol,2)+"%)",x_axis+470,y_axis+55,BearColor,8);
         SetText("Highest","Highest= "+DoubleToStr(SymbolMaxHi,2)+" ("+DoubleToStr(PercentFloatingSymbol,2)+"%)",x_axis+470,y_axis+40,BullColor,8);
         SetText("Lock","Lock= "+DoubleToStr(currentlock,2),x_axis+470,y_axis+70,BullColor,8);
         SetText("Won","Won: " + IntegerToString(profitbaskets,2),x_axis+470,y_axis+85,BullColor,8);
         SetText("Lost","Lost: " +IntegerToString(lossbaskets,2),x_axis+470,y_axis+100,BearColor,8);
         
         SetText("TPr","Basket TakeProfit =$ "+DoubleToStr(Basket_Target,0),x_axis+470,y_axis+8,clrLimeGreen,10);
         SetText("SL","Basket StopLoss =$ -"+DoubleToStr(Basket_StopLoss,0),x_axis+470,y_axis+20,clrRosyBrown,10);                 
         SetText("Symbol",/*"Sprd    PFO*/    "Sprd ADR"   /*BidRatio    RStrBSR LBS"*/"",x_axis+131,y_axis-15,White,8);               
      //   SetText("Symbol1a","MA",x_axis+320,y_axis-30,White,8);               
        // SetText("Symbol2"," Gap    m1 m5   RSI      HeatMap",x_axis+280,y_axis-17,White,8);               
     //    SetText("Symbol3","m1 m5m15m30h1 h4 d1",x_axis+430,y_axis-17,White,7);               
      //   SetText("Symbol4","Candle Direction",x_axis+445,y_axis-30,White,8);   
  //       SetText("Symbol5","Pobeda !",x_axis+650,y_axis-30,White,8);   
   //      SetText("Symbol6","Sl M1  Sl M5  Sl M15    ssrc fl1/fl2   sig     *   Cass ",x_axis+540,y_axis-17,White,8);          
         SetText("Trades","Long Short L  S  Long  Short   Total",x_axis+200,y_axis-17,White,10);
         SetText("TTr","   Lots   Orders",x_axis+200,y_axis-30,White,10);
        //ObjectSetText("BarTimer",TimeToStr(Time[0]+Period()*60-localtime-timeOffset,TIME_SECONDS ),14,"Courier",clrDarkOrange);
         Create_Button(IntegerToString(i)+"Pair",StringSubstr(TradePairs[i],0,6),50 ,14,x_axis+20 ,(i*16)+y_axis,C'35,35,35',clrWhite);
         Create_Button(IntegerToString(i)+"Hold","~",18 ,15,x_axis,(i*16)+y_axis,C'35,35,35',clrAqua);
         Create_Button(IntegerToString(i)+"BUY","L",20 ,15,x_axis+73,(i*16)+y_axis,clrDodgerBlue,clrBlack,8);           
         Create_Button(IntegerToString(i)+"SELL","S",20 ,15,x_axis+93 ,(i*16)+y_axis,clrRed,clrBlack,8);
         Create_Button(IntegerToString(i)+"CLOSE","c",20 ,15,x_axis+113,(i*16)+y_axis,clrDimGray,clrBlack,8);
   }
   
               
    //Basket Trades
   if(EnableCur)
   {
   int basket_x = x_axis + 3;
   int basket_y = y_axis + 450;
   int i = 0;
   
   //AUD
   Create_Button(button_AUD_basket,"AUD",50 ,18,basket_x+i ,basket_y,C'35,35,35',clrWhite);
   Create_Button(button_AUD_basket_buy,"BUY",50 ,18,basket_x+i ,basket_y+20,C'35,35,35',clrLime);
   Create_Button(button_AUD_basket_sell,"SELL",50 ,18,basket_x+i ,basket_y+40,C'35,35,35',clrRed);
   Create_Button(button_AUD_basket_close,"CLOSE",50 ,18,basket_x+i ,basket_y+60,C'35,35,35',clrOrange);
   //CAD
   i += 50;
   Create_Button(button_CAD_basket,"CAD",50 ,18,basket_x+i ,basket_y,C'35,35,35',clrWhite);
   Create_Button(button_CAD_basket_buy,"BUY",50 ,18,basket_x+i ,basket_y+20,C'35,35,35',clrLime);
   Create_Button(button_CAD_basket_sell,"SELL",50 ,18,basket_x+i ,basket_y+40,C'35,35,35',clrRed);
   Create_Button(button_CAD_basket_close,"CLOSE",50 ,18,basket_x+i ,basket_y+60,C'35,35,35',clrOrange);
   //CHF
   i += 50;
   Create_Button(button_CHF_basket,"CHF",50 ,18,basket_x+i ,basket_y,C'35,35,35',clrWhite);
   Create_Button(button_CHF_basket_buy,"BUY",50 ,18,basket_x+i ,basket_y+20,C'35,35,35',clrLime);
   Create_Button(button_CHF_basket_sell,"SELL",50 ,18,basket_x+i ,basket_y+40,C'35,35,35',clrRed);
   Create_Button(button_CHF_basket_close,"CLOSE",50 ,18,basket_x+i ,basket_y+60,C'35,35,35',clrOrange);
   //EUR
   i += 50;
   Create_Button(button_EUR_basket,"EUR",50 ,18,basket_x+i ,basket_y,C'35,35,35',clrWhite);
   Create_Button(button_EUR_basket_buy,"BUY",50 ,18,basket_x+i ,basket_y+20,C'35,35,35',clrLime);
   Create_Button(button_EUR_basket_sell,"SELL",50 ,18,basket_x+i ,basket_y+40,C'35,35,35',clrRed);
   Create_Button(button_EUR_basket_close,"CLOSE",50 ,18,basket_x+i ,basket_y+60,C'35,35,35',clrOrange);
   //GBP
   i += 50;
   Create_Button(button_GBP_basket,"GBP",50 ,18,basket_x+i ,basket_y,C'35,35,35',clrWhite);
   Create_Button(button_GBP_basket_buy,"BUY",50 ,18,basket_x+i ,basket_y+20,C'35,35,35',clrLime);
   Create_Button(button_GBP_basket_sell,"SELL",50 ,18,basket_x+i ,basket_y+40,C'35,35,35',clrRed);
   Create_Button(button_GBP_basket_close,"CLOSE",50 ,18,basket_x+i ,basket_y+60,C'35,35,35',clrOrange);
   //JPY
   i += 50;
   Create_Button(button_JPY_basket,"JPY",50 ,18,basket_x+i ,basket_y,C'35,35,35',clrWhite);
   Create_Button(button_JPY_basket_buy,"BUY",50 ,18,basket_x+i ,basket_y+20,C'35,35,35',clrLime);
   Create_Button(button_JPY_basket_sell,"SELL",50 ,18,basket_x+i ,basket_y+40,C'35,35,35',clrRed);
   Create_Button(button_JPY_basket_close,"CLOSE",50 ,18,basket_x+i ,basket_y+60,C'35,35,35',clrOrange);
   //NZD
   i += 50;
   Create_Button(button_NZD_basket,"NZD",50 ,18,basket_x+i ,basket_y,C'35,35,35',clrWhite);
   Create_Button(button_NZD_basket_buy,"BUY",50 ,18,basket_x+i ,basket_y+20,C'35,35,35',clrLime);
   Create_Button(button_NZD_basket_sell,"SELL",50 ,18,basket_x+i ,basket_y+40,C'35,35,35',clrRed);
   Create_Button(button_NZD_basket_close,"CLOSE",50 ,18,basket_x+i ,basket_y+60,C'35,35,35',clrOrange);
   //USD
   i += 50;
   Create_Button(button_USD_basket,"USD",50 ,18,basket_x+i ,basket_y,C'35,35,35',clrWhite);
   Create_Button(button_USD_basket_buy,"BUY",50 ,18,basket_x+i ,basket_y+20,C'35,35,35',clrLime);
   Create_Button(button_USD_basket_sell,"SELL",50 ,18,basket_x+i ,basket_y+40,C'35,35,35',clrRed);
   Create_Button(button_USD_basket_close,"CLOSE",50 ,18,basket_x+i ,basket_y+60,C'35,35,35',clrOrange);
   
   Create_Button(button_close_basket_All,"CLOSE ALL",90 ,18,x_axis+470 ,y_axis + 115,C'35,35,35',clrWhite);
   SetText("TotProf1",DoubleToStr(MathAbs(totalprofit),2),x_axis+570,y_axis+115,ProfitColor1,8);         
   Create_Button(button_close_basket_Prof,"CLOSE PROFIT",90 ,18,x_axis+470 ,y_axis + 135,C'35,35,35',clrLime);
   SetText("Prof1",DoubleToStr(MathAbs(tprof),2),x_axis+570,y_axis+135,ProfitColor1,8);      
   Create_Button(button_close_basket_Loss,"CLOSE LOSS",90 ,18,x_axis+470 ,y_axis + 155,C'35,35,35',clrRed);
   SetText("Loss1",DoubleToStr(MathAbs(tprof),2),x_axis+570,y_axis+155,ProfitColor1,8);
   Create_Button(button_reset_ea,"RESET EA",90 ,18,x_axis+470 ,y_axis + 175,C'35,35,35',clrOrange);
   }
  

   newday = 0;
   newm1=0;

/*  HP  */
   localday = 99;
   s1active = false;
   s2active = false;
   s3active = false;
   trailstarted = false;

   if (MaxTotalTrades == 0)
      maxtotaltrades = ArraySize(TradePairs) * MaxTrades;
   else
      maxtotaltrades = MaxTotalTrades;           
/*  HP  */





 
 
 
 /* dtlase */


   if ( autoTimeFrame )
   {
      userTimeFrame = Period();
   }
   else
   {   
		 userTimeFrame=timeFrame;
		
	}  
   
                 
  
    LastAlertTime = TimeCurrent();   
//--- indicator buffers mapping
   EventSetMillisecondTimer(1);
   //EventSetTimer(1);
   thisChart = ChartID();

   ObjectCreate(thisChart,"BarTimer",OBJ_LABEL,0,20,40);

   datetime srvtime,tmpOffset;
   // Use RefreshRates to get the current time from TimeCurrent
   // Otherwise you'll just get the last known time
   RefreshRates();
   
   srvtime = TimeCurrent();
   // Modified
   localtime = TimeLocal()+TimeGMTOffset();
   if(TimeHour(srvtime)>TimeHour(localtime)){
      // Server Time is still ahead of us
      int newOffset = TimeHour(srvtime)-TimeHour(localtime);
      ServerLocalOffset = (newOffset*60*60);
   }else if(TimeHour(srvtime)<TimeHour(localtime)){
      // Server Time is Behind us
      int newOffset = TimeHour(localtime)-TimeHour(srvtime);
      ServerLocalOffset = (newOffset*60*60);
   }else{
      // No modification required
      ServerLocalOffset = srvtime;
   }
   localtime = TimeLocal()-ServerLocalOffset;
   
   tmpOffset = TimeSeconds(srvtime) - TimeSeconds(localtime);
   if(tmpOffset < 30 && tmpOffset >= 0){
      timeOffset = TimeSeconds(srvtime) - TimeSeconds(localtime);
   }


 //==============================================
 





   //EventSetTimer(1);

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//--- destroy timer
   EventKillTimer();
   ObjectsDeleteAll();
   ObjectDelete("BarTimer");


  }

//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer() {
   Sleep(1);
   Trades();

   TradeManager();

   PlotTrades();

   PlotSpreadPips();

   //GetCandleDirection();
   //GetTrendChange();
   //GetSSRCDirr();
   

   GetSignals();  
   GetSignals2();
  // Get_M1_M5_MA();
   //GetFL();          
   //displayMeter();
   

   
   if (newday != iTime("EURUSD"+postfix,PERIOD_D1,0)) {
      GetAdrValues();
      PlotAdrValues();
      newday = iTime("EURUSD"+postfix,PERIOD_D1,0);
   }
          
   if (DashUpdate == 0 || (DashUpdate == 1 && newm1 != iTime("EURUSD"+postfix,PERIOD_M1,0)) || (DashUpdate == 5 && newm1 != iTime("EURUSD"+postfix,PERIOD_M5,0))) {

      
   for(int i=0;i<ArraySize(TradePairs);i++) 
   for(int a=0;a<5;a++){
     SetColors(i);
       ChngBoxCol((int)(signals[i].Signalperc * 100), i);      
       
     
  //   if(pairinfo[i].PipsSig==UP){SetObjText("Sigpips"+IntegerToString(i),CharToStr(233),x_axis+111,(i*16)+y_axis,clrLime,9);}
  //   else if(pairinfo[i].PipsSig==DOWN){SetObjText("Sigpips"+IntegerToString(i),CharToStr(234),x_axis+111,(i*16)+y_axis,clrFireBrick,9);}
  //   else {SetObjText("Sigpips"+IntegerToString(i),CharToStr(243),x_axis+111,(i*16)+y_axis,clrOrange,9);}
     
  //   SetText("BidRat"+IntegerToString(i),DoubleToStr(signals[i].ratio,2)+"%",x_axis+158,(i*16)+y_axis,Colorstr(signals[i].ratio),8); 
  //   SetText("RelStrgth"+IntegerToString(i),DoubleToStr(signals[i].calc,0),x_axis+215,(i*16)+y_axis,Colorsync(signals[i].calc),8);
  //   SetText("BSRat"+IntegerToString(i),DoubleToStr(signals[i].strength5,1),x_axis+231,(i*16)+y_axis,ColorBSRat(signals[i].strength5),8);
  //   SetText("LBS"+IntegerToString(i),DoubleToStr(signals[i].xLBSr,1),x_axis+257,(i*16)+y_axis,ColorBSRat(signals[i].strength5),8);
  //   SetText("gap"+signals[i].symbol, DoubleToStr(signals[i].strength_Gap,1),x_axis+280,(i*16)+y_axis,ColorGap(signals[i].strength_Gap),8);
  //   SetText("rsi"+signals[i].symbol, DoubleToStr(signals[i].RSI,1),x_axis+353,(i*16)+y_axis,ColorRSI(signals[i].RSI),8);
  //   SetText("Percent"+IntegerToString(i),+"   "+DoubleToStr(signals[i].Signalperc,2)+"%",x_axis+384,(i*16)+y_axis,clrBlack,8);
  //   SetText("ssrc"+signals[i].symbol, DoubleToStr(signals[i].SSRC,2),x_axis+640,(i*16)+y_axis,ColorSSRC(signals[i].SSRC),8);

     
     // if(signals[i].SignalhaM1==UP){SetObjText("SGD1"+IntegerToString(i),CharToStr(233),x_axis+319,(i*16)+y_axis,BullColor,8);}
  //    if(signals[i].SignalhaM1==DOWN){SetObjText("SGD1"+IntegerToString(i),CharToStr(234),x_axis+319,(i*16)+y_axis+2,BearColor,8);}
   //   if(signals[i].SignalhaM5==UP){SetObjText("SGD2"+IntegerToString(i),CharToStr(233),x_axis+335,(i*16)+y_axis,BullColor,8);}
    //  if(signals[i].SignalhaM5==DOWN){SetObjText("SGD2"+IntegerToString(i),CharToStr(234),x_axis+335,(i*16)+y_axis+2,BearColor,8);}
      
  /*    if(signals[i].Signalfl==UPfo){SetObjText("FL"+IntegerToString(i),CharToStr(140),x_axis+685,(i*16)+y_axis,clrPowderBlue,10);}
      if(signals[i].Signalfl==DOWNfo){SetObjText("FL"+IntegerToString(i),CharToStr(140),x_axis+685,(i*16)+y_axis,clrPink,10);}
      if(signals[i].Signalfl==UPFv){SetObjText("FL"+IntegerToString(i),CharToStr(142),x_axis+685,(i*16)+y_axis,clrDodgerBlue,10);}
      if(signals[i].Signalfl==DOWNFn){SetObjText("FL"+IntegerToString(i),CharToStr(142),x_axis+685,(i*16)+y_axis,BearColor,10);}
      if(signals[i].Signalfl==UPfv){SetObjText("FL"+IntegerToString(i),CharToStr(141),x_axis+685,(i*16)+y_axis,clrDodgerBlue,12);}
      if(signals[i].Signalfl==DOWNfn){SetObjText("FL"+IntegerToString(i),CharToStr(141),x_axis+685,(i*16)+y_axis,BearColor,12);}
*/
      
      
      
 
    /* if(signals[i].SigRatioPrev==UP){SetObjText("Sig"+IntegerToString(i),CharToStr(233),x_axis+196,(i*16)+y_axis,clrLime,10);}
     else if(signals[i].SigRatioPrev==DOWN){SetObjText("Sig"+IntegerToString(i),CharToStr(234),x_axis+196,(i*16)+y_axis,clrFireBrick,10);}
     else{SetObjText("Sig"+IntegerToString(i),CharToStr(243),x_axis+196,(i*16)+y_axis,clrOrange,10);}
     
     if(signals[i].SigGapPrev==UP){SetObjText("GapSign"+IntegerToString(i),CharToStr(217),x_axis+300,(i*16)+y_axis,clrLime,10);
     ColorPanel("GAP123"+IntegerToString(i),clrBlue,C'61,61,61');}
     else if(signals[i].SigGapPrev==DOWN){SetObjText("GapSign"+IntegerToString(i),CharToStr(218),x_axis+300,(i*16)+y_axis,clrFireBrick,10);
     ColorPanel("GAP123"+IntegerToString(i),clrIndianRed,C'61,61,61');}
     else {SetObjText("GapSign"+IntegerToString(i),CharToStr(216),x_axis+300,(i*16)+y_axis,clrOrange,10);
     ColorPanel("GAP123"+IntegerToString(i),clrBlack,C'61,61,61');}

     if(signals[i].Signalrsi==UP){SetObjText("RSI_Sig"+IntegerToString(i),CharToStr(233),x_axis+375,(i*16)+y_axis,clrLime,9);}
     else if(signals[i].Signalrsi==DOWN){SetObjText("RSI_Sig"+IntegerToString(i),CharToStr(234),x_axis+375,(i*16)+y_axis,clrFireBrick,9);}
     else {SetObjText("RSI_Sig"+IntegerToString(i),CharToStr(243),x_axis+375,(i*16)+y_axis,clrOrange,9);}

     if(signals[i].SignalSSRC==UP){SetObjText("SSRC_Sig"+IntegerToString(i),CharToStr(233),x_axis+665,(i*16)+y_axis,clrLime,9);}
     else if(signals[i].SignalSSRC==DOWN){SetObjText("SSRC_Sig"+IntegerToString(i),CharToStr(234),x_axis+665,(i*16)+y_axis,clrFireBrick,9);}
     else {SetObjText("SSRC_Sig"+IntegerToString(i),CharToStr(243),x_axis+665,(i*16)+y_axis,clrOrange,9);}
 */
//---------------------------------------------------------------------------------------------------------------------------+                
 /*     if (((pairinfo[i].PipsSig==UP && pairinfo[i].Pips > trade_MIN_pips) || trigger_use_Pips==false)
      && ((signals[i].SigRatioPrev==UP && signals[i].ratio>=trigger_buy_bidratio) || trigger_use_bidratio==false)
      &&  (signals[i].calc>=trigger_buy_relstrength || trigger_use_relstrength==false)
      &&(signals[i].SignaldirupScalp>0||trigger_Candle_DirectionScalp==false)
      &&(signals[i].SignaldirupSwing>0||trigger_Candle_DirectionSwing==false)
      &&(signals[i].SignalmaM1up>0||trigger_Moving_Average1==false)
      &&(signals[i].SignalmaM5up>0||trigger_Moving_Average2==false)
      &&  (signals[i].Signalrsi==UP || trigger_use_RSI==false)
      &&  (signals[i].strength5>=trigger_buy_buysellratio || trigger_use_buysellratio==false)
      && ((signals[i].SigGapPrev==UP && signals[i].strength_Gap>=trigger_gap_buy) || trigger_use_gap==false) 
      &&(signals[i].Signalperc >trade_MIN_HeatMap1 || trigger_UseHeatMap1==false))      
       {
         labelcolor = clrGreen;
         if ((bpos[i]+spos[i]) < MaxTrades && pairinfo[i].lastSignal != BUY && autotrade == true && (OnlyAddProfit == false || bprofit[i] >= 0.0) && pairinfo[i].Spread <= MaxSpread && inSession() == true && totaltrades <= maxtotaltrades) {
            pairinfo[i].lastSignal = BUY;
            
            while (IsTradeContextBusy()) Sleep(100);
            ticket=OrderSend(TradePairs[i],OP_BUY,lot,MarketInfo(TradePairs[i],MODE_ASK),100,0,0,comment,Magic_Number,0,Blue);
            if (OrderSelect(ticket,SELECT_BY_TICKET) == true) {
                if (Pipsl != 0.0)
                           stoploss=OrderOpenPrice() - Pipsl * pairinfo[i].PairPip;
                        else
                           if (Adr1sl != 0.0)
                              stoploss=OrderOpenPrice() - ((adrvalues[i].adr10/100)*Adr1sl) * pairinfo[i].PairPip;
                           else
                              stoploss = 0.0;

                        if (Piptp != 0.0)
                              takeprofit=OrderOpenPrice() + Piptp * pairinfo[i].PairPip;
                        else
                           if (Adr1tp != 0.0)
                              takeprofit=OrderOpenPrice() + ((adrvalues[i].adr10/100)*Adr1tp) * pairinfo[i].PairPip;
                           else
                              takeprofit = 0.0;
               
               while (IsTradeContextBusy()) Sleep(100);
               OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(stoploss,MarketInfo(TradePairs[i],MODE_DIGITS)),NormalizeDouble(takeprofit,MarketInfo(TradePairs[i],MODE_DIGITS)),0,clrBlue);
            }
         }
      } else {
         if (((pairinfo[i].PipsSig==DOWN && pairinfo[i].Pips < -trade_MIN_pips) || trigger_use_Pips==false) 
         && ((signals[i].SigRatioPrev==DOWN && signals[i].ratio<=trigger_sell_bidratio) || trigger_use_bidratio==false)
         &&  (signals[i].calc<=trigger_sell_relstrength || trigger_use_relstrength==false)
         &&  (signals[i].Signalrsi==DOWN  || trigger_use_RSI==false)
         &&(signals[i].SignaldirdnScalp>0||trigger_Candle_DirectionScalp==false)
         &&(signals[i].SignaldirdnSwing>0||trigger_Candle_DirectionSwing==false)
         &&(signals[i].SignalmaM1dn>0||trigger_Moving_Average1==false)
         &&(signals[i].SignalmaM5dn>0||trigger_Moving_Average2==false)
         &&  (signals[i].strength5<=trigger_sell_buysellratio || trigger_use_buysellratio==false)
         && ((signals[i].SigGapPrev==DOWN && signals[i].strength_Gap<=trigger_gap_sell) || trigger_use_gap==false)         
         &&(signals[i].Signalperc <-trade_MIN_HeatMap1 || trigger_UseHeatMap1==false))        
         {
            labelcolor = clrTomato;           
            if ((bpos[i]+spos[i]) < MaxTrades && pairinfo[i].lastSignal != SELL && autotrade == true && (OnlyAddProfit == false || sprofit[i] >= 0.0) && pairinfo[i].Spread <= MaxSpread && inSession() == true && totaltrades <= maxtotaltrades) {
               pairinfo[i].lastSignal = SELL;
               
               while (IsTradeContextBusy()) Sleep(100);
               ticket=OrderSend(TradePairs[i],OP_SELL,lot,MarketInfo(TradePairs[i],MODE_BID),100,0,0,comment,Magic_Number,0,Red);
               if (OrderSelect(ticket,SELECT_BY_TICKET) == true) {
                  if (Pipsl != 0.0)
                              stoploss=OrderOpenPrice() + Pipsl * pairinfo[i].PairPip;
                           else
                              if (Adr1sl != 0.0)
                                 stoploss=OrderOpenPrice()+((adrvalues[i].adr10/100)*Adr1sl)  *pairinfo[i].PairPip;
                              else
                                 stoploss = 0.0;
                                 
                                 
                           if (Piptp != 0.0)
                              takeprofit=OrderOpenPrice() - Piptp * pairinfo[i].PairPip;
                           else 
                              if (Adr1tp != 0.0)
                                 takeprofit=OrderOpenPrice() - ((adrvalues[i].adr10/100)*Adr1tp) * pairinfo[i].PairPip;
                              else
                                 takeprofit = 0.0;
                                 
                  while (IsTradeContextBusy()) Sleep(100);
                  OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(stoploss,MarketInfo(TradePairs[i],MODE_DIGITS)),NormalizeDouble(takeprofit,MarketInfo(TradePairs[i],MODE_DIGITS)),0,clrBlue);
               }
            }
         } else {
            labelcolor = BackGrnCol;
            pairinfo[i].lastSignal = NOTHING;
         }  
      }
      string HM0 = iCustom(NULL, 0, "HeatMapModokiV1",5, 10, "Arial", 1105 , 520, 0 , 0,i);
      string HM1 = iCustom(NULL, 0, "HeatMapModokiV1",15, 10, "Arial", 1140 , 520, 0 , 0,i);
      string HM2 = iCustom(NULL, 0, "HeatMapModokiV1",60, 10, "Arial", 1175 , 520, 0 , 0,i);
      string HM3 = iCustom(NULL, 0, "HeatMapModokiV1",240, 10, "Arial", 1210 , 520, 0 , 0,i);
      string HM4 = iCustom(NULL, 0, "HeatMapModokiV1",1440, 10, "Arial", 1245 , 520, 0 , 0,i);
      */
              
         ColorPanel("Spread"+IntegerToString(i),labelcolor,C'61,61,61');        
         ColorPanel("Pips"+IntegerToString(i),labelcolor,C'61,61,61');
         ColorPanel("Adr"+IntegerToString(i),labelcolor,C'61,61,61');         
         ColorPanel("TP",Black,White);
         ColorPanel("TP1",Black,White);
         ColorPanel("TP2",Black,White);
         ColorPanel("TP3",Black,White);
         ColorPanel("TP4",Black,White);
         ColorPanel("TP5",Black,White);         
         //ColorPanel("A2"+IntegerToString(i),labelcolor,C'61,61,61');          
       /*  ColorPanel("m1"+IntegerToString(i),Color2,White);
         ColorPanel("m5"+IntegerToString(i),Color3,White);
         ColorPanel("m15"+IntegerToString(i),Color4,White);
         ColorPanel("m30"+IntegerToString(i),Color5,White);
         ColorPanel("h1"+IntegerToString(i),Color6,White);
         ColorPanel("h4"+IntegerToString(i),Color7,White);
         ColorPanel("d1"+IntegerToString(i),Color8,White);*/

         
      }
      if (DashUpdate == 1)
         newm1 = iTime("EURUSD"+postfix,PERIOD_M1,0);
      else if (DashUpdate == 5)
         newm1 = iTime("EURUSD"+postfix,PERIOD_M5,0);
   }
   
   
   
    
   if(Period() >0 && Period() <1440)
   {
      localtime = TimeLocal()+(TimeGMTOffset()+((60*60)*Broker_Time_Offset));
      if(ObjectFind(thisChart,"BarTimer")>=0)
      {
         ObjectCreate(0,"BarTimer",OBJ_LABEL,0,0,0);
         ObjectSetInteger(0,"BarTimer",OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER);
         ObjectSet("BarTimer",OBJPROP_CORNER,1);
         ObjectSet("BarTimer",OBJPROP_XDISTANCE,0);
         ObjectSet("BarTimer",OBJPROP_YDISTANCE,70);
         ObjectSetText("BarTimer",TimeToStr(Time[0]+Period()*60-localtime-timeOffset,TIME_SECONDS ),14,"Courier",clrDarkOrange);
         //SetText("gh",TimeToStr(Time[0]+Period()*60-localtime-timeOffset,TIME_SECONDS ),x_axis,y_axis,White,8);               
   
     } 
   }
   
   
   WindowRedraw();    
}
  
//+------------------------------------------------------------------+

void SetText(string name,string text,int x,int y,color colour,int fontsize=12 )
  {
   if (ObjectFind(0,name)<0)
      ObjectCreate(0,name,OBJ_LABEL,0,0,0);

    ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
    ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
    ObjectSetInteger(0,name,OBJPROP_COLOR,colour);
    ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize);
    ObjectSetString(0,name,OBJPROP_FONT,_font);
    ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
    ObjectSetString(0,name,OBJPROP_TEXT,text);
  }
//+------------------------------------------------------------------+

void SetObjText(string name,string CharToStr,int x,int y,color colour,int fontsize=12)
  {
   if(ObjectFind(0,name)<0)
      ObjectCreate(0,name,OBJ_LABEL,0,0,0);

   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,fontsize);
   ObjectSetInteger(0,name,OBJPROP_COLOR,colour);
   ObjectSetInteger(0,name,OBJPROP_BACK,false);
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
   ObjectSetString(0,name,OBJPROP_TEXT,CharToStr);
   ObjectSetString(0,name,OBJPROP_FONT,"Wingdings");
  }  
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void SetPanel(string name,int sub_window,int x,int y,int width,int height,color bg_color,color border_clr,int border_width)
  {
   if(ObjectCreate(0,name,OBJ_RECTANGLE_LABEL,sub_window,0,0))
     {
      ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
      ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
      ObjectSetInteger(0,name,OBJPROP_XSIZE,width);
      ObjectSetInteger(0,name,OBJPROP_YSIZE,height);
      ObjectSetInteger(0,name,OBJPROP_COLOR,border_clr);
      ObjectSetInteger(0,name,OBJPROP_BORDER_TYPE,BORDER_FLAT);
      ObjectSetInteger(0,name,OBJPROP_WIDTH,border_width);
      ObjectSetInteger(0,name,OBJPROP_CORNER,CORNER_LEFT_UPPER);
      ObjectSetInteger(0,name,OBJPROP_STYLE,STYLE_SOLID);
      ObjectSetInteger(0,name,OBJPROP_BACK,true);
      ObjectSetInteger(0,name,OBJPROP_SELECTABLE,0);
      ObjectSetInteger(0,name,OBJPROP_SELECTED,0);
      ObjectSetInteger(0,name,OBJPROP_HIDDEN,true);
      ObjectSetInteger(0,name,OBJPROP_ZORDER,0);
     }
   ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bg_color);
  }
void ColorPanel(string name,color bg_color,color border_clr)
  {
   ObjectSetInteger(0,name,OBJPROP_COLOR,border_clr);
   ObjectSetInteger(0,name,OBJPROP_BGCOLOR,bg_color);
  }
//+------------------------------------------------------------------+
void Create_Button(string but_name,string label,int xsize,int ysize,int xdist,int ydist,int bcolor,int fcolor, int sz=9)
{
    
   if(ObjectFind(0,but_name)<0)
   {
      if(!ObjectCreate(0,but_name,OBJ_BUTTON,0,0,0))
        {
         Print(__FUNCTION__,
               ": failed to create the button! Error code = ",GetLastError());
         return;
        }
      ObjectSetString(0,but_name,OBJPROP_TEXT,label);
      ObjectSetInteger(0,but_name,OBJPROP_XSIZE,xsize);
      ObjectSetInteger(0,but_name,OBJPROP_YSIZE,ysize);
      ObjectSetInteger(0,but_name,OBJPROP_CORNER,CORNER_LEFT_UPPER);     
      ObjectSetInteger(0,but_name,OBJPROP_XDISTANCE,xdist);      
      ObjectSetInteger(0,but_name,OBJPROP_YDISTANCE,ydist);         
      ObjectSetInteger(0,but_name,OBJPROP_BGCOLOR,bcolor);
      ObjectSetInteger(0,but_name,OBJPROP_COLOR,fcolor);
      ObjectSetInteger(0,but_name,OBJPROP_FONTSIZE,sz);
      ObjectSetString(0,but_name,OBJPROP_FONT,_font);
      ObjectSetInteger(0,but_name,OBJPROP_HIDDEN,true);
      ObjectSetInteger(0,but_name,OBJPROP_WIDTH,2);
     // ObjectSetInteger(0,but_name,OBJPROP_LEVELCOLOR,clrDimGray);
    //  ObjectSetInteger(0,but_name,OBJPROP_LEVELWIDTH,3);
      //ObjectSetInteger(0,but_name,OBJPROP_BORDER_COLOR,ChartGetInteger(0,CHART_COLOR_FOREGROUND));
      ObjectSetInteger(0,but_name,OBJPROP_BORDER_TYPE,BORDER_RAISED);
      
      ChartRedraw();      
   }

}
void OnChartEvent(const int id,  const long &lparam, const double &dparam,  const string &sparam)
  {
   if(id==CHARTEVENT_OBJECT_CLICK)
  
      {
       if (sparam==button_AUD_basket_buy)
        {          
               buy_basket(AUD);
               sell_basket(AUD_R);
               ObjectSetInteger(0,button_AUD_basket_buy,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------  
      if (sparam==button_AUD_basket_sell)
        {          
               sell_basket(AUD);
               buy_basket(AUD_R);
               ObjectSetInteger(0,button_AUD_basket_sell,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------  
      if (sparam==button_CAD_basket_buy)
        {          
               buy_basket(CAD);
               sell_basket(CAD_R);
               ObjectSetInteger(0,button_CAD_basket_buy,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------  
      if (sparam==button_CAD_basket_sell)
        {          
               sell_basket(CAD);
               buy_basket(CAD_R);
               ObjectSetInteger(0,button_CAD_basket_sell,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------
      if (sparam==button_CHF_basket_buy)
        {          
               buy_basket(CHF);
               sell_basket(CHF_R);
               ObjectSetInteger(0,button_CHF_basket_buy,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------  
      if (sparam==button_CHF_basket_sell)
        {          
               sell_basket(CHF);
               buy_basket(CHF_R);
               ObjectSetInteger(0,button_CHF_basket_sell,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------
      if (sparam==button_EUR_basket_buy)
        {          
               buy_basket(EUR);
               ObjectSetInteger(0,button_EUR_basket_buy,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------  
      if (sparam==button_EUR_basket_sell)
        {          
               sell_basket(EUR);
               ObjectSetInteger(0,button_EUR_basket_sell,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------
      if (sparam==button_GBP_basket_buy)
        {          
               buy_basket(GBP);
               sell_basket(GBP_R);
               ObjectSetInteger(0,button_GBP_basket_buy,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------  
      if (sparam==button_GBP_basket_sell)
        {          
               sell_basket(GBP);
               buy_basket(GBP_R);
               ObjectSetInteger(0,button_GBP_basket_sell,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------
      if (sparam==button_JPY_basket_buy)
        {          
               sell_basket(JPY_R);
               ObjectSetInteger(0,button_JPY_basket_buy,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------  
      if (sparam==button_JPY_basket_sell)
        {          
               buy_basket(JPY_R);
               ObjectSetInteger(0,button_JPY_basket_sell,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------
      if (sparam==button_NZD_basket_buy)
        {          
               buy_basket(NZD);
               sell_basket(NZD_R);
               ObjectSetInteger(0,button_NZD_basket_buy,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------  
      if (sparam==button_NZD_basket_sell)
        {          
               sell_basket(NZD);
               buy_basket(NZD_R);
               ObjectSetInteger(0,button_NZD_basket_sell,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------
      if (sparam==button_USD_basket_buy)
        {          
               buy_basket(USD);
               sell_basket(USD_R);
               ObjectSetInteger(0,button_USD_basket_buy,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------  
      if (sparam==button_USD_basket_sell)
        {          
               sell_basket(USD);
               buy_basket(USD_R);
               ObjectSetInteger(0,button_USD_basket_sell,OBJPROP_STATE,0);
               return;
        }
//-----------------------------------------------------------------------------------------------------------------
      if (sparam==button_AUD_basket_close)
        {          
               close_cur_basket(AUD);
               close_cur_basket(AUD_R);
               ObjectSetInteger(0,button_AUD_basket_close,OBJPROP_STATE,0);
               return;
        }
//----------------------------------------------------------------------------------------------------------------- 
      if (sparam==button_CAD_basket_close)
        {          
               close_cur_basket(CAD);
               close_cur_basket(CAD_R);
               ObjectSetInteger(0,button_CAD_basket_close,OBJPROP_STATE,0);
               return;
        }
//----------------------------------------------------------------------------------------------------------------- 
      if (sparam==button_CHF_basket_close)
        {          
               close_cur_basket(CHF);
               close_cur_basket(CHF_R);
               ObjectSetInteger(0,button_CHF_basket_close,OBJPROP_STATE,0);
               return;
        }
//----------------------------------------------------------------------------------------------------------------- 
      if (sparam==button_EUR_basket_close)
        {          
               close_cur_basket(EUR);
               ObjectSetInteger(0,button_EUR_basket_close,OBJPROP_STATE,0);
               return;
        }
//----------------------------------------------------------------------------------------------------------------- 
      if (sparam==button_GBP_basket_close)
        {          
               close_cur_basket(GBP);
               close_cur_basket(GBP_R);
               ObjectSetInteger(0,button_GBP_basket_close,OBJPROP_STATE,0);
               return;
        }
//----------------------------------------------------------------------------------------------------------------- 
      if (sparam==button_JPY_basket_close)
        {          
               close_cur_basket(JPY_R);
               ObjectSetInteger(0,button_JPY_basket_close,OBJPROP_STATE,0);
               return;
        }
//----------------------------------------------------------------------------------------------------------------- 
      if (sparam==button_NZD_basket_close)
        {          
               close_cur_basket(NZD);
               close_cur_basket(NZD_R);
               ObjectSetInteger(0,button_NZD_basket_close,OBJPROP_STATE,0);
               return;
        }
//----------------------------------------------------------------------------------------------------------------- 
      if (sparam==button_USD_basket_close)
        {          
               close_cur_basket(USD);
               close_cur_basket(USD_R);
               ObjectSetInteger(0,button_USD_basket_close,OBJPROP_STATE,0);
               return;
        }
//----------------------------------------------------------------------------------------------------------------- 
      if (sparam==button_reset_ea)
        {          
               Reset_EA();
               ObjectSetInteger(0,button_reset_ea,OBJPROP_STATE,0);
               return;
        }

//-----------------------------------------------------------------------------------------------------------------
      if (sparam==button_close_basket_All)
        {
               ObjectSetString(0,button_close_basket_All,OBJPROP_TEXT,"Closing...");               
               close_basket(Magic_Number);
               ObjectSetInteger(0,button_close_basket_All,OBJPROP_STATE,0);
               ObjectSetString(0,button_close_basket_All,OBJPROP_TEXT,"Close Basket"); 
               return;
        }
//-----------------------------------------------------------------------------------------------------------------     
      if (sparam==button_close_basket_Prof)
        {
               ObjectSetString(0,button_close_basket_Prof,OBJPROP_TEXT,"Closing...");               
               close_profit();
               ObjectSetInteger(0,button_close_basket_Prof,OBJPROP_STATE,0);
               ObjectSetString(0,button_close_basket_Prof,OBJPROP_TEXT,"Close Basket"); 
               return;
        }
//----------------------------------------------------------------------------------------------------------------- 
      if (sparam==button_close_basket_Loss)
        {
               ObjectSetString(0,button_close_basket_Loss,OBJPROP_TEXT,"Closing...");               
               close_loss();
               ObjectSetInteger(0,button_close_basket_Loss,OBJPROP_STATE,0);
               ObjectSetString(0,button_close_basket_Loss,OBJPROP_TEXT,"Close Basket"); 
               return;
        }
//-----------------------------------------------------------------------------------------------------------------
     if (StringFind(sparam,"BUY") >= 0)
        {
               int ind = (int)StringToInteger(sparam);
               ticket=OrderSend(TradePairs[ind],OP_BUY,lot,MarketInfo(TradePairs[ind],MODE_ASK),100,0,0,"OFF",Magic_Number,0,Blue);
               if (OrderSelect(ticket,SELECT_BY_TICKET) == true) {
                  if (Pipsl != 0.0)
                           stoploss=OrderOpenPrice() - Pipsl * pairinfo[ind].PairPip;
                        else
                           if (Adr1sl != 0.0)
                              stoploss=OrderOpenPrice() - ((adrvalues[ind].adr10/100)*Adr1sl) * pairinfo[ind].PairPip;
                           else
                              stoploss = 0.0;

                        if (Piptp != 0.0)
                              takeprofit=OrderOpenPrice() + Piptp * pairinfo[ind].PairPip;
                        else
                           if (Adr1tp != 0.0)
                              takeprofit=OrderOpenPrice() + ((adrvalues[ind].adr10/100)*Adr1tp) * pairinfo[ind].PairPip;
                           else
                              takeprofit = 0.0;
                  if (OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(stoploss,(int)MarketInfo(TradePairs[ind],MODE_DIGITS)),NormalizeDouble(takeprofit,(int)MarketInfo(TradePairs[ind],MODE_DIGITS)),0,clrBlue)){}
               }
               ObjectSetInteger(0,IntegerToString(ind)+"BUY",OBJPROP_STATE,0);
               ObjectSetString(0,IntegerToString(ind)+"BUY",OBJPROP_TEXT,"L"); 
               return;
        }
     if (StringFind(sparam,"SELL") >= 0)
        {
               int ind = (int)StringToInteger(sparam);
               ticket=OrderSend(TradePairs[ind],OP_SELL,lot,MarketInfo(TradePairs[ind],MODE_BID),100,0,0,"OFF",Magic_Number,0,Red);
               if (OrderSelect(ticket,SELECT_BY_TICKET) == true) {
                   if (Pipsl != 0.0)
                              stoploss=OrderOpenPrice() + Pipsl * pairinfo[ind].PairPip;
                           else
                              if (Adr1sl != 0.0)
                                 stoploss=OrderOpenPrice()+((adrvalues[ind].adr10/100)*Adr1sl)  *pairinfo[ind].PairPip;
                              else
                                 stoploss = 0.0;
                                 
                                 
                           if (Piptp != 0.0)
                              takeprofit=OrderOpenPrice() - Piptp * pairinfo[ind].PairPip;
                           else 
                              if (Adr1tp != 0.0)
                                 takeprofit=OrderOpenPrice() - ((adrvalues[ind].adr10/100)*Adr1tp) * pairinfo[ind].PairPip;
                              else
                                 takeprofit = 0.0;
                  if (OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(stoploss,(int)MarketInfo(TradePairs[ind],MODE_DIGITS)),NormalizeDouble(takeprofit,(int)MarketInfo(TradePairs[ind],MODE_DIGITS)),0,clrBlue)){}
               }
               ObjectSetInteger(0,IntegerToString(ind)+"SELL",OBJPROP_STATE,0);
               ObjectSetString(0,IntegerToString(ind)+"SELL",OBJPROP_TEXT,"S");
               return;
        }
     if (StringFind(sparam,"CLOSE") >= 0)
        {
               int ind = (int)StringToInteger(sparam);
               closeOpenOrders(TradePairs[ind]);               
               ObjectSetInteger(0,IntegerToString(ind)+"CLOSE",OBJPROP_STATE,0);
               ObjectSetString(0,IntegerToString(ind)+"CLOSE",OBJPROP_TEXT,"CLOSE");
               return;
        }
         
      if (StringFind(sparam,"Hold") >= 0) {
         int ind = (int)StringToInteger(sparam);
         ObjectSetInteger(0,sparam,OBJPROP_STATE,0);
         OpenChart(ind);
         return;         
      }   
     }
}
void buy_basket(string &pairs[])
{
   int i;
  ticket=-1;
   
   for(i=0;i<ArraySize(pairs);i++)
   {
      ticket=OrderSend(pairs[i],OP_BUY,lot,MarketInfo(pairs[i],MODE_ASK),100,0,0,NULL,Magic_Number,0,clrNONE);
      if (OrderSelect(ticket,SELECT_BY_TICKET) == true) {
                  if (Pipsl != 0.0)
                           stoploss=OrderOpenPrice() - Pipsl * pairinfo[i].PairPip;
                        else
                           if (Adr1sl != 0.0)
                              stoploss=OrderOpenPrice() - ((adrvalues[i].adr10/100)*Adr1sl) * pairinfo[i].PairPip;
                           else
                              stoploss = 0.0;

                        if (Piptp != 0.0)
                              takeprofit=OrderOpenPrice() + Piptp * pairinfo[i].PairPip;
                        else
                           if (Adr1tp != 0.0)
                              takeprofit=OrderOpenPrice() + ((adrvalues[i].adr10/100)*Adr1tp) * pairinfo[i].PairPip;
                           else
                              takeprofit = 0.0;
                  if(OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(stoploss,(int)MarketInfo(pairs[i],MODE_DIGITS)),NormalizeDouble(takeprofit,(int)MarketInfo(pairs[i],MODE_DIGITS)),0,clrBlue)){}
   }
  }
}

void sell_basket(string &pairs[])
{
   int i;
   //int ticket;
   ticket = -1;
   for(i=0;i<ArraySize(pairs);i++)
   {
      ticket=OrderSend(pairs[i],OP_SELL,lot,MarketInfo(pairs[i],MODE_BID),100,0,0,NULL,Magic_Number,0,clrNONE);
      if (OrderSelect(ticket,SELECT_BY_TICKET) == true) {
                   if (Pipsl != 0.0)
                              stoploss=OrderOpenPrice() + Pipsl * pairinfo[i].PairPip;
                           else
                              if (Adr1sl != 0.0)
                                 stoploss=OrderOpenPrice()+((adrvalues[i].adr10/100)*Adr1sl)  *pairinfo[i].PairPip;
                              else
                                 stoploss = 0.0;
                                 
                                 
                           if (Piptp != 0.0)
                              takeprofit=OrderOpenPrice() - Piptp * pairinfo[i].PairPip;
                           else 
                              if (Adr1tp != 0.0)
                                 takeprofit=OrderOpenPrice() - ((adrvalues[i].adr10/100)*Adr1tp) * pairinfo[i].PairPip;
                              else
                                 takeprofit = 0.0;
                  if(OrderModify(ticket,OrderOpenPrice(),NormalizeDouble(stoploss,(int)MarketInfo(pairs[i],MODE_DIGITS)),NormalizeDouble(takeprofit,(int)MarketInfo(pairs[i],MODE_DIGITS)),0,clrBlue)){}
   }
  }
}

void close_cur_basket(string &pairs[])
{ 
  
   if (OrdersTotal() <= 0)
   return;

   int TradeList[][2];
   int ctTrade = 0;

   for (int i=0; i<OrdersTotal(); i++) 
   {
	   if (!OrderSelect(i, SELECT_BY_POS)) continue;
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true &&
         (OrderType()==0 || OrderType()==1) && 
         OrderMagicNumber()==Magic_Number &&
         InArray(pairs, OrderSymbol())) 
      {
	      ctTrade++;
		   ArrayResize(TradeList, ctTrade);
		   TradeList[ctTrade-1][0] = (int)OrderOpenTime();
		   TradeList[ctTrade-1][1] = OrderTicket();
	   }
   }
   ArraySort(TradeList,WHOLE_ARRAY,0,MODE_ASCEND);

   for (int i=0;i<ctTrade;i++) 
   {
       if (OrderSelect(TradeList[i][1], SELECT_BY_TICKET)==true) 
       {
            if (OrderType()==0)
               {
               ticket=OrderClose(OrderTicket(),OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), 100, clrNONE);
               if (ticket==-1) Print ("Error: ",  GetLastError());
               
               }
            if (OrderType()==1)
               {
               ticket=OrderClose(OrderTicket(),OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), 100, clrNONE);
               if (ticket==-1) Print ("Error: ",  GetLastError());
               
               }  
         }
         Sleep(500);
   }
      
}
//+------------------------------------------------------------------+
//| closeOpenOrders                                                  |
//+------------------------------------------------------------------+
void closeOpenOrders(string closecurr ) {
   int cnt = 0;

   for (cnt = OrdersTotal()-1 ; cnt >= 0 ; cnt--) {
      if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true) {
         if(OrderType()==OP_BUY && OrderSymbol() == closecurr && OrderMagicNumber()==Magic_Number)
            ticket=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Violet);
         else if(OrderType()==OP_SELL && OrderSymbol() == closecurr && OrderMagicNumber()==Magic_Number) 
            ticket=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Violet);
         else if(OrderType()>OP_SELL) //pending orders
            ticket=OrderDelete(OrderTicket());
                   
      }
   }
}
void close_basket(int magic_number)
{ 
  
if (OrdersTotal() <= 0)
   return;

int TradeList[][2];
int ctTrade = 0;

for (int i=0; i<OrdersTotal(); i++) {
	if(!OrderSelect(i, SELECT_BY_POS))continue;
   if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==true && (OrderType()==0 || OrderType()==1) && OrderMagicNumber()==Magic_Number) {
	   ctTrade++;
		ArrayResize(TradeList, ctTrade);
		TradeList[ctTrade-1][0] = (int)OrderOpenTime();
		TradeList[ctTrade-1][1] = OrderTicket();
	}
}
ArraySort(TradeList,WHOLE_ARRAY,0,MODE_ASCEND);

for (int i=0;i<ctTrade;i++) {
      
       if (OrderSelect(TradeList[i][1], SELECT_BY_TICKET)==true) {
            if (OrderType()==0)
               {
               ticket=OrderClose(OrderTicket(),OrderLots(), MarketInfo(OrderSymbol(),MODE_BID), 3,Red);
               if (ticket==-1) Print ("Error: ",  GetLastError());
               
               }
            if (OrderType()==1)
               {
               ticket=OrderClose(OrderTicket(),OrderLots(), MarketInfo(OrderSymbol(),MODE_ASK), 3,Red);
               if (ticket==-1) Print ("Error: ",  GetLastError());
               
               }  
            }
      }
  
   for (int i=0;i<ArraySize(TradePairs);i++)
      pairinfo[i].lastSignal = NOTHING; 
       
   currentlock = 0.0;
   trailstarted = false;   
   lockdistance = 0.0;    
   SymbolMaxDD = 0;
   SymbolMaxHi = 0;
   PercentFloatingSymbol=0;
   PercentMaxDDSymbol=0;    
}
void close_profit()
{
 int cnt = 0; 
 for (cnt = OrdersTotal()-1 ; cnt >= 0 ; cnt--)
            {
               if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)
               if (OrderProfit()+OrderSwap()+OrderCommission() > 0)
               {
                  if(OrderType()==OP_BUY && OrderMagicNumber()==Magic_Number)
                     ticket=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Violet);
                  if(OrderType()==OP_SELL && OrderMagicNumber()==Magic_Number) 
                     ticket=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Violet);
                  if(OrderType()>OP_SELL)
                     ticket=OrderDelete(OrderTicket());
               }
            } 
    }
void close_loss()
{
 int cnt = 0; 
 for (cnt = OrdersTotal()-1 ; cnt >= 0 ; cnt--)
            {
               if(OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES)==true)
               if (OrderProfit()+OrderSwap()+OrderCommission() < 0)
               {
                  if(OrderType()==OP_BUY && OrderMagicNumber()==Magic_Number)
                     ticket=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Violet);
                  if(OrderType()==OP_SELL && OrderMagicNumber()==Magic_Number) 
                     ticket=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Violet);
                  if(OrderType()>OP_SELL)
                     ticket=OrderDelete(OrderTicket());
               }
            } 
    } 

void Reset_EA()
{
   currentlock = 0.0;
   trailstarted = false;   
   lockdistance = 0.0;    
   SymbolMaxDD = 0;
   SymbolMaxHi = 0;
   PercentFloatingSymbol=0;
   PercentMaxDDSymbol=0;
  
   OnInit();
}
                               
//+------------------------------------------------------------------+
void Trades()
{
   int i, j;
   totallots=0;
   totalprofit=0;
   totaltrades = 0;

   for(i=0;i<ArraySize(TradePairs);i++)
   {
      
      bpos[i]=0;
      spos[i]=0;       
      blots[i]=0;
      slots[i]=0;     
      bprofit[i]=0;
      sprofit[i]=0;
      tprofit[i]=0;
      tloss = 0;
      tprof = 0;
   }
	for(i=0;i<OrdersTotal();i++)
	{
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
         break;

      for(j=0;j<ArraySize(TradePairs);j++)
      {	  
         if((TradePairs[j]==OrderSymbol() || TradePairs[j]=="") && OrderMagicNumber()==Magic_Number)
         {
            TradePairs[j]=OrderSymbol();                       
            tprofit[j]=tprofit[j]+OrderProfit()+OrderSwap()+OrderCommission();
           
           if(OrderType()==0){ bprofit[j]+=OrderProfit()+OrderSwap()+OrderCommission(); } 
           
           if(OrderType()==1){ sprofit[j]+=OrderProfit()+OrderSwap()+OrderCommission(); } 
           
           if(OrderType()==0){ blots[j]+=OrderLots(); } 
           if(OrderType()==1){ slots[j]+=OrderLots(); }
           if(OrderType()==0){ bpos[j]+=+1; } 
           if(OrderType()==1){ spos[j]+=+1; } 
                                
            totallots=totallots+OrderLots();
            totaltrades++;
            totalprofit = totalprofit+OrderProfit()+OrderSwap()+OrderCommission();
            if (OrderProfit()+OrderSwap()+OrderCommission()>0) tprof+=OrderProfit()+OrderSwap()+OrderCommission();
            if (OrderProfit()+OrderSwap()+OrderCommission()<0) tloss+=OrderProfit()+OrderSwap()+OrderCommission();
            break;
	     }
	     
	  }
   }
   if(OrdersTotal()==0)
      SetText("CTP","No Trades To Monitor",x_axis+225,y_axis-47,Yellow,8);
   else
      SetText("CTP","Monitoring Trades",x_axis+228,y_axis-47,Yellow,8);

   if (inSession() == true)
      SetText("CTPT","Trading On",x_axis+99,y_axis-48,Green,9);
   else
      SetText("CTPT","Closed",x_axis+99,y_axis-48,Red,9);
//         SetPanel("TP6",0,x_axis+95,y_axis-50,100,20,Black,White,1);

   }
//+------------------------------------------------------------------+ 

void OpenChart(int ind) {
long nextchart = ChartFirst();
   do {
      string sym = ChartSymbol(nextchart);
      if (StringFind(sym,TradePairs[ind]) >= 0) {
            ChartSetInteger(nextchart,CHART_BRING_TO_TOP,true);
            ChartSetSymbolPeriod(nextchart,TradePairs[ind],TimeFrame);
            ChartApplyTemplate(nextchart,usertemplate);
            return;
         }
   } while ((nextchart = ChartNext(nextchart)) != -1);
   long newchartid = ChartOpen(TradePairs[ind],TimeFrame);
   ChartApplyTemplate(newchartid,usertemplate);
 }
//+------------------------------------------------------------------+  

void TradeManager() {

   double AccBalance=AccountBalance();
         
      //- Target
      if(Basket_Target>0 && totalprofit>=Basket_Target) {
         profitbaskets++;
         close_basket(Magic_Number);
         return;
      }
      
      //- StopLoss
      if(Basket_StopLoss>0 && totalprofit<(0-Basket_StopLoss)) {
         lossbaskets++;
         close_basket(Magic_Number);
         return;
      }

      //- Out off session
      if(inSession() == false && totallots > 0.0 && CloseAllSession == true) {
         close_basket(Magic_Number);
         return;
      }

      //- Profit lock stoploss
      if (currentlock != 0.0 && totalprofit < currentlock) {
         profitbaskets++;
         close_basket(Magic_Number);
         return;
      }

      //- Profit lock trail
      if (trailstarted == true && totalprofit > currentlock + lockdistance)
         currentlock = totalprofit - lockdistance;

      //- Lock in profit 1
      if (BasketP1 != 0.0 && BasketL1 != 0.0 && currentlock < BasketL1) {
         if (totalprofit > BasketP1)
            currentlock = BasketL1;
         if (BasketP2 == 0.0 && TrailLastLock == true) {
            trailstarted = true;
            if (TrailDistance != 0.0)
               lockdistance = BasketP1 - TrailDistance;
            else
               lockdistance = BasketL1;
         }
      }
      //- Lock in profit 2
      if (BasketP2 != 0.0 && BasketL2 != 0.0 && currentlock < BasketL2) {
         if (totalprofit > BasketP2)
            currentlock = BasketL2;
         if (BasketP3 == 0.0 && TrailLastLock == true) {
            trailstarted = true;
            if (TrailDistance != 0.0)
               lockdistance = BasketP2 - TrailDistance;
            else
               lockdistance = BasketL2;
         }
      }
      //- Lock in profit 3
      if (BasketP3 != 0.0 && BasketL3 != 0.0 && currentlock < BasketL3) {
         if (totalprofit > BasketP3)
            currentlock = BasketL3;
         if (BasketP4 == 0.0 && TrailLastLock == true) {
            trailstarted = true;
            if (TrailDistance != 0.0)
               lockdistance = BasketP3 - TrailDistance;
            else
               lockdistance = BasketL3;
         }
      }
      //- Lock in profit 4
      if (BasketP4 != 0.0 && BasketL4 != 0.0 && currentlock < BasketL4) {
         if (totalprofit > BasketP4)
            currentlock = BasketL4;
         if (BasketP5 == 0.0 && TrailLastLock == true) {
            trailstarted = true;
            if (TrailDistance != 0.0)
               lockdistance = BasketP4 - TrailDistance;
            else
               lockdistance = BasketL4;
         }
      }
      //- Lock in profit 5
      if (BasketP5 != 0.0 && BasketL5 != 0.0 && currentlock < BasketL5) {
         if (totalprofit > BasketP5)
            currentlock = BasketL5;
         if (BasketP6 == 0.0 && TrailLastLock == true) {
            trailstarted = true;
            if (TrailDistance != 0.0)
               lockdistance = BasketP5 - TrailDistance;
            else
               lockdistance = BasketL5;
         }
      }
      //- Lock in profit 6
      if (BasketP6 != 0.0 && BasketL6 != 0.0 && currentlock < BasketL6) {
         if (totalprofit > BasketP6)
            currentlock = BasketL6;
         if (TrailLastLock == true) {
            trailstarted = true;
            if (TrailDistance != 0.0)
               lockdistance = BasketP6 - TrailDistance;
            else
               lockdistance = BasketL6;
         }
      }


     if(totalprofit<=SymbolMaxDD) {
        SymbolMaxDD=totalprofit;
        GetBalanceSymbol=AccBalance;
     }

     if(GetBalanceSymbol != 0)
      PercentMaxDDSymbol=(SymbolMaxDD*100)/GetBalanceSymbol;
     
     if(totalprofit>=SymbolMaxHi) {
        SymbolMaxHi=totalprofit;
        GetBalanceSymbol=AccBalance;
     }
     
     if(GetBalanceSymbol != 0)
      PercentFloatingSymbol=(SymbolMaxHi*100)/GetBalanceSymbol;

     ObjectSetText("Lowest","Lowest= "+DoubleToStr(SymbolMaxDD,2)+" ("+DoubleToStr(PercentMaxDDSymbol,2)+"%)",8,NULL,BearColor);
     ObjectSetText("Highest","Highest= "+DoubleToStr(SymbolMaxHi,2)+" ("+DoubleToStr(PercentFloatingSymbol,2)+"%)",8,NULL,BullColor);
     ObjectSetText("Lock","Lock= "+DoubleToStr(currentlock,2),8,NULL,BullColor);
     ObjectSetText("Won","Won: " +IntegerToString(profitbaskets,2),8,NULL,BullColor);
     ObjectSetText("Lost","Lost: " +IntegerToString(lossbaskets,2),8,NULL,BearColor);

}     
void PlotTrades() {

   for (int i=0; i<ArraySize(TradePairs);i++) {

     if(blots[i]>0){LotColor =clrTeal;}        
     if(blots[i]==0){LotColor =C'61,61,61';}
     if(slots[i]>0){LotColor1 =clrSienna;}        
     if(slots[i]==0){LotColor1 =C'61,61,61';}
     if(bpos[i]>0){OrdColor =clrTeal;}        
     if(bpos[i]==0){OrdColor =C'61,61,61';}
     if(spos[i]>0){OrdColor1 =clrSienna;}        
     if(spos[i]==0){OrdColor1 =C'61,61,61';}
     if(bprofit[i]>0){ProfitColor =BullColor;}
     if(bprofit[i]<0){ProfitColor =BearColor;}
     if(bprofit[i]==0){ProfitColor =C'61,61,61';}
     if(sprofit[i]>0){ProfitColor2 =BullColor;}
     if(sprofit[i]<0){ProfitColor2 =BearColor;}
     if(sprofit[i]==0){ProfitColor2 =C'61,61,61';}
     if(tprofit[i]>0){ProfitColor3 =BullColor;}
     if(tprofit[i]<0){ProfitColor3 =BearColor;}
     if(tprofit[i]==0){ProfitColor3 =C'61,61,61';}

     if(totalprofit>0){ProfitColor1 =BullColor;}
     if(totalprofit<0){ProfitColor1 =BearColor;}
     if(totalprofit==0){ProfitColor1 =clrWhite;}         

     ObjectSetText("bLots"+IntegerToString(i),DoubleToStr(blots[i],2),10,NULL,LotColor);
     ObjectSetText("sLots"+IntegerToString(i),DoubleToStr(slots[i],2),10,NULL,LotColor1);
     ObjectSetText("bPos"+IntegerToString(i),DoubleToStr(bpos[i],0),8,NULL,OrdColor);
     ObjectSetText("sPos"+IntegerToString(i),DoubleToStr(spos[i],0),8,NULL,OrdColor1);
     ObjectSetText("TProf"+IntegerToString(i),DoubleToStr(MathAbs(bprofit[i]),2),10,NULL,ProfitColor);
     ObjectSetText("SProf"+IntegerToString(i),DoubleToStr(MathAbs(sprofit[i]),2),10,NULL,ProfitColor2);
     ObjectSetText("TtlProf"+IntegerToString(i),DoubleToStr(MathAbs(tprofit[i]),2),10,NULL,ProfitColor3);
     ObjectSetText("TotProf",DoubleToStr(MathAbs(totalprofit) ,2),10,NULL,ProfitColor1);
     ObjectSetText("TotProf1",DoubleToStr(MathAbs(totalprofit),2)+ " $",10,NULL,ProfitColor1);
     ObjectSetText("Prof1",DoubleToStr(tprof,2)+ " $",10,NULL,BullColor);
     ObjectSetText("Loss1",DoubleToStr(tloss,2)+ " $",10,NULL,ProfitColor1);
   }
}
void PlotAdrValues() {

   for (int i=0;i<ArraySize(TradePairs);i++)
     ObjectSetText("S1"+IntegerToString(i),DoubleToStr(adrvalues[i].adr,0),8,NULL,Yellow);
}
bool inSession() {
 
   if ((localday != TimeDayOfWeek(TimeLocal()) && s1active == false && s2active == false && s3active == false) || localday == 99) {
      TimeToStruct(TimeLocal(),sess);
      StringSplit(sess1start,':',strspl);sess.hour=(int)strspl[0];sess.min=(int)strspl[1];sess.sec=0;
      s1start = StructToTime(sess);
      StringSplit(sess1end,':',strspl);sess.hour=(int)strspl[0];sess.min=(int)strspl[1];sess.sec=0;
      s1end = StructToTime(sess);
      StringSplit(sess2start,':',strspl);sess.hour=(int)strspl[0];sess.min=(int)strspl[1];sess.sec=0;
      s2start = StructToTime(sess);
      StringSplit(sess2end,':',strspl);sess.hour=(int)strspl[0];sess.min=(int)strspl[1];sess.sec=0;
      s2end = StructToTime(sess);
      StringSplit(sess3start,':',strspl);sess.hour=(int)strspl[0];sess.min=(int)strspl[1];sess.sec=0;
      s3start = StructToTime(sess);
      StringSplit(sess3end,':',strspl);sess.hour=(int)strspl[0];sess.min=(int)strspl[1];sess.sec=0;
      s3end = StructToTime(sess);
      if (s1end < s1start)
         s1end += 24*60*60;
      if (s2end < s2start)
         s2end += 24*60*60;
      if (s3end < s3start)
         s3end += 24*60*60;
      newSession();
      localday = TimeDayOfWeek(TimeLocal());
      Print("Sessions for today");
      if (UseSession1 == true)
         Print("Session 1 From:"+(string)s1start+" until "+(string)s1end);
      if (UseSession2 == true)
         Print("Session 2 From:"+(string)s2start+" until "+(string)s2end);
      if (UseSession3 == true)
         Print("Session 3 From:"+(string)s3start+" until "+(string)s3end);
   }


   if (UseSession1 && TimeLocal() >= s1start && TimeLocal() <= s1end) {
      comment = sess1comment;
      if (s1active == false)
         newSession();         
      else if ((StopProfit != 0 && profitbaskets >= StopProfit) || (StopLoss != 0 && lossbaskets >= StopLoss))
         return(false);
      s1active = true;
      return(true);
   } else {
      s1active = false;
   }   
   if (UseSession2 && TimeLocal() >= s2start && TimeLocal() <= s2end) {
      comment = sess2comment;
      if (s2active == false)
         newSession();
      else if ((StopProfit != 0 && profitbaskets >= StopProfit) || (StopLoss != 0 && lossbaskets >= StopLoss))
         return(false);
      s2active = true;
      return(true);
   } else {
      s2active = false;
   }
   if (UseSession3 && TimeLocal() >= s3start && TimeLocal() <= s3end) {
      comment = sess3comment;
      if (s3active == false)
         newSession();
      else if ((StopProfit != 0 && profitbaskets >= StopProfit) || (StopLoss != 0 && lossbaskets >= StopLoss))
         return(false);
      s3active = true;
      return(true);
   } else {
      s3active = false;
   }
   
   return(false);
}
void newSession() {
   
   profitbaskets = 0;
   lossbaskets = 0;
   SymbolMaxDD = 0.0;
   PercentMaxDDSymbol = 0.0;
   SymbolMaxHi=0.0;
   PercentFloatingSymbol = 0.0;
   currentlock = 0.0;
   trailstarted = false;   
   lockdistance = 0.0;
}

//-----------------------------------------------------------------------------
void ChngBoxCol(int mVal, int mBx)
 {
   if(mVal >= 0 && mVal < 10)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, White);
   if(mVal > 10 && mVal < 20)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, LightCyan);
   if(mVal > 20 && mVal < 30)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, PowderBlue);
   if(mVal > 30 && mVal < 40)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, PaleTurquoise);
   if(mVal > 40 && mVal < 50)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, LightBlue);
   if(mVal > 50 && mVal < 60)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, SkyBlue);
   if(mVal > 60 && mVal < 70)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, Turquoise);
   if(mVal > 70 && mVal < 80)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, DeepSkyBlue);
   if(mVal > 80 && mVal < 90)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, SteelBlue);
   if(mVal > 90 && mVal < 100)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, Blue);
   if(mVal > 100)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, MediumBlue);

   if(mVal < 0 && mVal > -10)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, White);
   if(mVal < -10 && mVal > -20)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, Seashell);
   if(mVal < -20 && mVal > -30)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, MistyRose);
   if(mVal < -30 && mVal > -40)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, Pink);
   if(mVal < -40 && mVal > -50)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, LightPink);
   if(mVal < -50 && mVal > -60)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, Plum);
   if(mVal < -60 && mVal >-70)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, Violet);
   if(mVal < -70 && mVal > -80)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, Orchid);
   if(mVal < -80 && mVal > -90)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, DeepPink);
   if(mVal < -90)
         ObjectSet("HM1"+(string)mBx, OBJPROP_BGCOLOR, Red);
   return;
 }
//-----------------------------------------------------------------------------

bool InArray(string &pairs[], string symbol)
{
   int arraysize = ArraySize(pairs);
   if(arraysize <= 0) return(false);
   if(symbol == NULL) return(false);
   
   int i;
   
   for(i=0;i<arraysize;i++)
      if(pairs[i] == symbol) return(true);

   return(false);
}
//-------------------------------------------------------------------+ 
void PlotSpreadPips() {
             
   for (int i=0;i<ArraySize(TradePairs);i++) {
      if(MarketInfo(TradePairs[i],MODE_POINT) != 0 && pairinfo[i].pipsfactor != 0) {
       pairinfo[i].Pips = (iClose(TradePairs[i],PERIOD_D1,0)-iOpen(TradePairs[i], PERIOD_D1,0))/MarketInfo(TradePairs[i],MODE_POINT)/pairinfo[i].pipsfactor; 
       pairinfo[i].Pipsprev = (iClose(TradePairs[i],PERIOD_D1,signals[i].shift+900)-iOpen(TradePairs[i], PERIOD_D1,0))/MarketInfo(TradePairs[i],MODE_POINT)/pairinfo[i].pipsfactor;    
       pairinfo[i].Spread=MarketInfo(TradePairs[i],MODE_SPREAD)/pairinfo[i].pipsfactor;
      // signals[i].Signalperc = (iClose(TradePairs[i], 1, 0) - iClose(TradePairs[i], trigger_TF_HM1, 1)) / iClose(TradePairs[i], trigger_TF_HM1, 1) * 100;
           
      }  
     if(pairinfo[i].Pips>0){PipsColor =BullColor;}
     if(pairinfo[i].Pips<0){PipsColor =BearColor;} 
     if(pairinfo[i].Pips==0){PipsColor =clrWhite;}       
     if(pairinfo[i].Spread > MaxSpread)
     
     ObjectSetText("Spr1"+IntegerToString(i),DoubleToStr(pairinfo[i].Spread,1),8,NULL,Red);
     else
      ObjectSetText("Spr1"+IntegerToString(i),DoubleToStr(pairinfo[i].Spread,1),8,NULL,Orange);
     ObjectSetText("Pp1"+IntegerToString(i),DoubleToStr(MathAbs(pairinfo[i].Pips),0),8,NULL,PipsColor);
     
     if(pairinfo[i].Pips > pairinfo[i].Pipsprev && pairinfo[i].Pips > trade_MIN_pips){
         pairinfo[i].PipsSig=UP;
        } else{
     if(pairinfo[i].Pips < pairinfo[i].Pipsprev && pairinfo[i].Pips < -trade_MIN_pips)
         pairinfo[i].PipsSig=DOWN;
        }  
      

   }
}
//----------------------------------------------------------------------+
 void GetAdrValues() {

   double s=0.0;

   for (int i=0;i<ArraySize(TradePairs);i++) {

      for(int a=1;a<=20;a++) {
         if(pairinfo[i].PairPip != 0)
            s=s+(iHigh(TradePairs[i],PERIOD_D1,a)-iLow(TradePairs[i],PERIOD_D1,a))/pairinfo[i].PairPip;
         if(a==1)
            adrvalues[i].adr1=MathRound(s);
         if(a==5)
            adrvalues[i].adr5=MathRound(s/5);
         if(a==10)
            adrvalues[i].adr10=MathRound(s/10);
         if(a==20)
            adrvalues[i].adr20=MathRound(s/20);
      }
      adrvalues[i].adr=MathRound((adrvalues[i].adr1+adrvalues[i].adr5+adrvalues[i].adr10+adrvalues[i].adr20)/4.0);
      s=0.0;
   }
 }
//-----------------------------------------------------------------------------------------------+ 
void GetSignals() {
   int cnt = 0;
   ArrayResize(signals,ArraySize(TradePairs));
   for (int i=0;i<ArraySize(signals);i++) {
      signals[i].symbol=TradePairs[i]; 
      signals[i].point=MarketInfo(signals[i].symbol,MODE_POINT);
      signals[i].open=iOpen(signals[i].symbol,PERIOD_D1,0);      
      signals[i].close=iClose(signals[i].symbol,PERIOD_D1,0);
      signals[i].hi=MarketInfo(signals[i].symbol,MODE_HIGH);
      signals[i].lo=MarketInfo(signals[i].symbol,MODE_LOW);
      signals[i].bid=MarketInfo(signals[i].symbol,MODE_BID);
      signals[i].range=(signals[i].hi-signals[i].lo);
      signals[i].shift = iBarShift(signals[i].symbol,PERIOD_M1,TimeCurrent()-1800);
      signals[i].prevbid = iClose(signals[i].symbol,PERIOD_M1,signals[i].shift);
      //signals[i].RSI = RSI_Value(signals[i].symbol);
      //signals[i].SSRC = SSRC_znach(signals[i].symbol);
      //signals[i].FL = SignalFL(signals[i].symbol);
      signals[i].highRatio=(signals[i].hi - signals[i].bid)/signals[i].point/10;
      signals[i].lowRatio=(signals[i].bid - signals[i].lo)/signals[i].point/10;
      
      
           
    // if(signals[i].range!=0) {            
    //  signals[i].ratio=MathMin(((signals[i].bid-signals[i].lo)/signals[i].range*100 ),100);
   //   signals[i].prevratio=MathMin(((signals[i].prevbid-signals[i].lo)/signals[i].range*100 ),100);     
           
      /*for (int j = 0; j < 8; j++){
            
      if(signals[i].ratio <= 3.0) signals[i].fact = 0;
      if(signals[i].ratio > 3.0)  signals[i].fact = 1;
      if(signals[i].ratio > 10.0) signals[i].fact = 2;
      if(signals[i].ratio > 25.0) signals[i].fact = 3;
      if(signals[i].ratio > 40.0) signals[i].fact = 4;
      if(signals[i].ratio > 50.0) signals[i].fact = 5;
      if(signals[i].ratio > 60.0) signals[i].fact = 6;
      if(signals[i].ratio > 75.0) signals[i].fact = 7;
      if(signals[i].ratio > 90.0) signals[i].fact = 8;
      if(signals[i].ratio > 97.0) signals[i].fact = 9;
       cnt++;
      
      if(curr[j]==StringSubstr(signals[i].symbol,3,3))
               signals[i].fact=9-signals[i].fact;

      if(curr[j]==StringSubstr(signals[i].symbol,0,3)) {
               signals[i].strength1=signals[i].fact;
              }  else{
      if(curr[j]==StringSubstr(signals[i].symbol,3,0))
               signals[i].strength2=signals[i].fact;
              }

      signals[i].calc =signals[i].strength1-signals[i].strength2;
      
      //signals[i].strength=currency_strength(curr[j]);

            if(curr[j]==StringSubstr(signals[i].symbol,0,3)){
               signals[i].strength3=signals[i].strength;
            } else{
            if(curr[j]==StringSubstr(signals[i].symbol,3,0))
               signals[i].strength4=signals[i].strength;
            }
            signals[i].strength5=(signals[i].strength3-signals[i].strength4);
            
      // signals[i].strength=old_currency_strength(curr[j]);

            if(curr[j]==StringSubstr(signals[i].symbol,0,3)){
               signals[i].strength6=signals[i].strength;
            } else {
            if(curr[j]==StringSubstr(signals[i].symbol,3,0))
               signals[i].strength7=signals[i].strength;
            }
      //      signals[i].strength8=(signals[i].strength6-signals[i].strength7);     
          //  signals[i].strength_Gap=signals[i].strength5 - signals[i].xLBSr;
            //signals[i].strength_Gap=signals[i].strength5-signals[i].strength8;
    /*     
        if(signals[i].ratio>=trigger_buy_bidratio){
               signals[i].SigRatio=UP;
           } else {
         if(signals[i].ratio<=trigger_sell_bidratio)
               signals[i].SigRatio=DOWN;
           }  
        signals[i].SigRatioPrev=NONE;
        if(signals[i].ratio>signals[i].prevratio && signals[i].ratio>=trigger_buy_bidratio){
                signals[i].SigRatioPrev=UP;
           } else {
        if(signals[i].ratio<signals[i].prevratio && signals[i].ratio<=trigger_sell_bidratio)
                signals[i].SigRatioPrev=DOWN;
           }      
                    
        if(signals[i].calc>=trigger_buy_relstrength){
               signals[i].SigRelStr=UP;
             } else {
        if (signals[i].calc<=trigger_sell_relstrength) 
              signals[i].SigRelStr=DOWN;
             } 
             
         if(signals[i].strength5>=trigger_buy_buysellratio){
               signals[i].SigBSRatio=UP;
             } else {
       if (signals[i].calc<=trigger_sell_buysellratio) 
              signals[i].SigBSRatio=DOWN;
             }       
        
        if(signals[i].strength_Gap>=trigger_gap_buy){
               signals[i].SigGap=UP;
             } else {
        if (signals[i].strength_Gap<=trigger_gap_sell) 
              signals[i].SigGap=DOWN;
             }

        if(signals[i].RSI>=trigger_buy_RSI){
               signals[i].SigRSI=UP;
             } else {
        if (signals[i].RSI<=trigger_sell_RSI) 
              signals[i].SigRSI=DOWN;
             }
             
         if(signals[i].SSRC>=trigger_high_SSRC){
               signals[i].DirrSSRC=UP;
             } else {
        if (signals[i].SSRC<=trigger_low_SSRC) 
              signals[i].DirrSSRC=DOWN;
             }
                
           if (signals[i].SSRC>=trigger_buy_SSRC && signals[i].DirrSSRC==UP){
               signals[i].SSRCSig=BUY;
             } else {
        if (signals[i].SSRC<=trigger_sell_SSRC && signals[i].DirrSSRC==DOWN ) 
               signals[i].SSRCSig=SELL;
               }
         
   */     
        
        
        
        
        
        
    /*    
              
        
        
         signals[i].SigGapPrev=NONE;
        if(signals[i].strength5>signals[i].xLBSr && signals[i].strength_Gap>=trigger_gap_buy && signals[i].strength_Gap>0)
        {
              signals[i].SigGapPrev=UP;
        } 
        if(signals[i].strength5<signals[i].xLBSr && signals[i].strength_Gap<=trigger_gap_sell && signals[i].strength_Gap<0)
        {      
               signals[i].SigGapPrev=DOWN;
             }          */
      }
     
   //  }
      
   // }
    
    

    
        

}
//+------------------------------------------------------------------+       
/*
color Colorstr(double tot) 
  {
   if(tot>=trigger_buy_bidratio)
      return (BullColor);
   if(tot<=trigger_sell_bidratio)
      return (BearColor);
   return (clrOrange);
  }
color ColorBSRat(double tot) 
  {
   if(tot>=trigger_buy_buysellratio)
      return (BullColor);
   if(tot<=trigger_sell_buysellratio)
      return (BearColor);
   return (clrOrange);
  } 
color ColorGap(double tot) 
  {
   if(tot>=trigger_gap_buy)
      return (BullColor);
   if(tot<=trigger_gap_sell)
      return (clrDarkRed);
   return (clrOrange);
  } 
color ColorRSI(double tot) 
  {
   if(tot>=trigger_buy_RSI)
      return (BullColor);
   if(tot<=trigger_sell_RSI)
      return (BearColor);
   return (clrOrange);
  }     
color ColorSSRC(double tot) 
  {
   if(tot>=trigger_high_SSRC)
      return (BearColor);
   if(tot<=trigger_low_SSRC)
      return (BullColor);
   return (clrWhiteSmoke);
  }  */
//+------------------------------------------------------------------+ 
/*void displayMeter() {
   
   double arrt[8][3];
   int arr2,arr3;
   /*arrt[0][0] = currency_strength(curr[0]); arrt[1][0] = currency_strength(curr[1]); arrt[2][0] = currency_strength(curr[2]);
   arrt[3][0] = currency_strength(curr[3]); arrt[4][0] = currency_strength(curr[4]); arrt[5][0] = currency_strength(curr[5]);
   arrt[6][0] = currency_strength(curr[6]); arrt[7][0] = currency_strength(curr[7]);
   arrt[0][2] = old_currency_strength(curr[0]); arrt[1][2] = old_currency_strength(curr[1]);arrt[2][2] = old_currency_strength(curr[2]);
   arrt[3][2] = old_currency_strength(curr[3]); arrt[4][2] = old_currency_strength(curr[4]);arrt[5][2] = old_currency_strength(curr[5]);
   arrt[6][2] = old_currency_strength(curr[6]);arrt[7][2] = old_currency_strength(curr[7]);
   arrt[0][1] = 0; arrt[1][1] = 1; arrt[2][1] = 2; arrt[3][1] = 3; arrt[4][1] = 4;arrt[5][1] = 5; arrt[6][1] = 6; arrt[7][1] = 7;
   ArraySort(arrt, WHOLE_ARRAY, 0, MODE_DESCEND);
     
   for (int m = 0; m < 8; m++) {
      arr2 = (int)arrt[m][1];
      arr3=(int)arrt[m][2];
      currstrength[m] = arrt[m][0];
      prevstrength[m] = arrt[m][2]; 
         SetText(curr[arr2]+"pos",IntegerToString(m+1)+".",x_axis+1285,(m*18)+y_axis+467,color_for_profit(arrt[m][0]),12);
         SetText(curr[arr2]+"curr", curr[arr2],x_axis+1300,(m*18)+y_axis+467,color_for_profit(arrt[m][0]),12);
         SetText(curr[arr2]+"currdig", DoubleToStr(arrt[m][0],1),x_axis+1340,(m*18)+y_axis+467,color_for_profit(arrt[m][0]),12);
        // SetText(curr[arr2]+"currdig", DoubleToStr(ratio[m][0],1),x_axis+280,(m*18)+y_axis+17,color_for_profit(arrt[m][0]),12);
        
        if(currstrength[m] > prevstrength[m]){SetObjText("Sdir"+IntegerToString(m),CharToStr(233),x_axis+1370,(m*18)+y_axis+467,BullColor,12);}
         else if(currstrength[m] < prevstrength[m]){SetObjText("Sdir"+IntegerToString(m),CharToStr(234),x_axis+1370,(m*18)+y_axis+467,BearColor,12);}
         else {SetObjText("Sdir"+IntegerToString(m),CharToStr(243),x_axis+1370,(m*18)+y_axis+467,clrYellow,12);}
         
         
         }
 ChartRedraw(); 
}
*/
color color_for_profit(double total) 
  {
  if(total<2.0)
      return (clrRed);
   if(total<=3.0)
      return (clrOrangeRed);
   if(total>7.0)
      return (clrLime);
   if(total>6.0)
      return (clrGreen);
   if(total>5.0)
      return (clrSandyBrown);
   if(total<=5.0)
      return (clrYellow);       
   return(clrSteelBlue);
  }
/*
double currency_strength(string pair) {
   int fact;
   string sym;
   double range;
   double ratio;
   double strength = 0;
   int cnt1 = 0;
   
   for (int x = 0; x < ArraySize(TradePairs); x++) {
      fact = 0;
      sym = TradePairs[x];
      if (pair == StringSubstr(sym, 0, 3) || pair == StringSubstr(sym, 3, 3)) {
        // sym = sym + tempsym;
         range = (MarketInfo(sym, MODE_HIGH) - MarketInfo(sym, MODE_LOW)) ;
         if (range != 0.0) {
            ratio = 100.0 * ((MarketInfo(sym, MODE_BID) - MarketInfo(sym, MODE_LOW)) / range );
            if (ratio > 3.0)  fact = 1;
            if (ratio > 10.0) fact = 2;
            if (ratio > 25.0) fact = 3;
            if (ratio > 40.0) fact = 4;
            if (ratio > 50.0) fact = 5;
            if (ratio > 60.0) fact = 6;
            if (ratio > 75.0) fact = 7;
            if (ratio > 90.0) fact = 8;
            if (ratio > 97.0) fact = 9;
            cnt1++;
            if (pair == StringSubstr(sym, 3, 3)) fact = 9 - fact;
            strength += fact;
           // signals[x].strength += fact;
         }
      } 
           
   }
  // for (int x = 0; x < ArraySize(TradePairs); x++) 
   //if(cnt1!=0)signals[x].strength /= cnt1;
   if(cnt1!=0)strength /= cnt1;
   return (strength);
   
 }
//-----------------------------------------------------------------------------------+
double old_currency_strength(string pair) 
  {
   int fact;
   string sym;
   double range;
   double ratio;
   double strength=0;
   int cnt1=0;

   for(int x=0; x<ArraySize(TradePairs); x++) 
     {
      fact= 0;
      sym = TradePairs[x];
      int bar = iBarShift(TradePairs[x],PERIOD_M1,TimeCurrent()-1800);
      double prevbid = iClose(TradePairs[x],PERIOD_M1,bar);
      
      if(pair==StringSubstr(sym,0,3) || pair==StringSubstr(sym,3,3)) 
        {
         // sym = sym + tempsym;
         range=(MarketInfo(sym,MODE_HIGH)-MarketInfo(sym,MODE_LOW));
         if(range!=0.0) 
           {
            ratio=100.0 *((prevbid-MarketInfo(sym,MODE_LOW))/range);

            if(ratio > 3.0)  fact = 1;
            if(ratio > 10.0) fact = 2;
            if(ratio > 25.0) fact = 3;
            if(ratio > 40.0) fact = 4;
            if(ratio > 50.0) fact = 5;
            if(ratio > 60.0) fact = 6;
            if(ratio > 75.0) fact = 7;
            if(ratio > 90.0) fact = 8;
            if(ratio > 97.0) fact = 9;
            
            cnt1++;

            if(pair==StringSubstr(sym,3,3))
               fact=9-fact;

            strength+=fact;

           }
        }
     }
   if(cnt1!=0)
      strength/=cnt1;

   return (strength);
  
} */
//-----------------------------------------------------------------------+
/*
color Colorsync(double tot) 
  {
   if(tot>=trigger_buy_relstrength)
      return (BullColor);
   if(tot<=trigger_sell_relstrength)
      return (BearColor);
   return (clrOrange);
  }
//-----------------------------------------------------------------------+
color ColorHL(double tot) 
  {
   if(tot>0)
      return (BullColor);
   if(tot<=0)
      return (BearColor);
   return (clrOrange);
  }  */
//-----------------------------------------------------------------------+
/*
 
 double RSI_Value(string sym)
  {    
    double  valu;
    int    i; 
    double RSI_PRES;
    

            for(i=0; i<ArraySize(TradePairs); i++)
            {                         
               RSI_PRES    = iRSI(sym,trigger_RSI_Timeframe,trigger_RSI_period,trigger_RSI_Applied,trigger_RSI_shift);   //i+1 => previous bar           
            }
            valu=RSI_PRES;
         
         return(valu);
  
   } 
  */ 
//-----------------------------------------------------------------------+
/*
void GetTrendChange() {
   for (int i=0;i<ArraySize(TradePairs);i++) {

      signals[i].Signalrsi = NONE;

      double Closelast = iRSI(TradePairs[i],trigger_RSI_Timeframe,trigger_RSI_period,trigger_RSI_Applied,0);
      double Closebefore = iRSI(TradePairs[i],trigger_RSI_Timeframe,trigger_RSI_period,trigger_RSI_Applied,1);

     if (Closelast<Closebefore && Closelast<=trigger_sell_RSI) {
        
            signals[i].Signalrsi = DOWN;
      }

      if (Closelast>Closebefore && Closelast>=trigger_buy_RSI)  {

            signals[i].Signalrsi = UP;
      }   
   }
 }*/
 
 //-----------------------------------------------------------------------+

 /*
 double SSRC_znach(string sym)
  {    
    double  val;
    int    i; 
    double SSRC_PRES;
    

            for(i=0; i<ArraySize(TradePairs); i++)
            {                         
               SSRC_PRES    =iCustom(sym,1,"SSRC",trigger_SSRC_snakerange,trigger_SSRC_filtperiod,trigger_SSRC_martfiltr,trigger_SSRC_Applied,0,trigger_SSRC_shift);   //i+1 => previous bar           
            }                
            val=SSRC_PRES;
         
         return(val);
  
   } 
 */
//-----------------------------------------------------------------------+ 
 
   
//-----------------------------------------------------------------------+
/*
void GetSSRCDirr() {
   for (int i=0;i<ArraySize(TradePairs);i++) {

      signals[i].SignalSSRC = NONE;

      double Closelast = iCustom(TradePairs[i], 1, "SSRC",trigger_SSRC_snakerange,trigger_SSRC_filtperiod,trigger_SSRC_martfiltr,trigger_SSRC_Applied,0,0);
      double Closebefore =iCustom(TradePairs[i], 1, "SSRC",trigger_SSRC_snakerange,trigger_SSRC_filtperiod,trigger_SSRC_martfiltr,trigger_SSRC_Applied,0,2);

     if (Closelast<Closebefore) {
        
            signals[i].SignalSSRC = DOWN;
      }

      if (Closelast>Closebefore)  {

            signals[i].SignalSSRC = UP;
      }   
   }
 }
 

*/











 
 void GetSignals2(){
 
 
    if ((Alert_Mod == 1) && (LastAlertTime < Time[0]))
   {
      //Alert("New Bar  -  ", Symbol(), "  GAP - " + userTimeFrame  + "  -  " + AccountCompany());   
      LastAlertTime = Time[0];
      
         ArrayResize(signals,ArraySize(TradePairs));
         for (int i=0;i<ArraySize(signals);i++) {
            signals[i].xLBSr = signals[i].strength5;

    }
 }
 
 }
 
 
 void GetCandleDirection() {

   for (int i=0;i<ArraySize(TradePairs);i++) {
      double Openm1    = iOpen(TradePairs[i], PERIOD_M1,0);
      double Closem1   = iClose(TradePairs[i],PERIOD_M1,0);
      double Openm5    = iOpen(TradePairs[i], PERIOD_M5,0);
      double Closem5   = iClose(TradePairs[i],PERIOD_M5,0);
      double Openm15   = iOpen(TradePairs[i], PERIOD_M15,0);
      double Closem15  = iClose(TradePairs[i],PERIOD_M15,0);
      double Openm30   = iOpen(TradePairs[i], PERIOD_M30,0);
      double Closem30  = iClose(TradePairs[i],PERIOD_M30,0);
      double Openh1    = iOpen(TradePairs[i], PERIOD_H1,0);
      double Closeh1   = iClose(TradePairs[i],PERIOD_H1,0);      
      double Openh4     = iOpen(TradePairs[i], PERIOD_H4,0);
      double Closeh4    = iClose(TradePairs[i],PERIOD_H4,0);
      double Opend     = iOpen(TradePairs[i], PERIOD_D1,0);
      double Closed    = iClose(TradePairs[i],PERIOD_D1,0);
      double Openw     = iOpen(TradePairs[i], PERIOD_W1,0);
      double Closew    = iClose(TradePairs[i],PERIOD_W1,0);
      double Openmn    = iOpen(TradePairs[i], PERIOD_MN1,0);
      double Closemn   = iClose(TradePairs[i],PERIOD_MN1,0);

      
      if(Closem1>Openm1)signals[i].Signalm1=UP;
      if(Closem1<Openm1)signals[i].Signalm1=DOWN;
      if(Closem5>Openm5)signals[i].Signalm5=UP;
      if(Closem5<Openm5)signals[i].Signalm5=DOWN;
      if(Closem15>Openm15)signals[i].Signalm15=UP;
      if(Closem15<Openm15)signals[i].Signalm15=DOWN;
      if(Closem30>Openm30)signals[i].Signalm30=UP;
      if(Closem30<Openm30)signals[i].Signalm30=DOWN;
      if(Closeh1>Openh1)signals[i].Signalh1=UP;
      if(Closeh1<Openh1)signals[i].Signalh1=DOWN;
      if(Closeh4>Openh4)signals[i].Signalh4=UP;
      if(Closeh4<Openh4)signals[i].Signalh4=DOWN;
      if(Closed>Opend)signals[i].Signald1=UP;
      if(Closed<Opend)signals[i].Signald1=DOWN;
      if(Closew>Openw)signals[i].Signalw1=UP;
      if(Closew<Openw)signals[i].Signalw1=DOWN;
      if(Closemn>Openmn)signals[i].Signalmn=UP;
      if(Closemn<Openmn)signals[i].Signalmn=DOWN;
      
      signals[i].SignaldirupScalp=signals[i].Signalm1==UP&&signals[i].Signalm5==UP;
      signals[i].SignaldirdnScalp=signals[i].Signalm1==DOWN&&signals[i].Signalm5==DOWN;
      signals[i].SignaldirupSwing=signals[i].Signalm15==UP&&signals[i].Signalm30==UP&&signals[i].Signalh1==UP&&signals[i].Signalh4==UP&&signals[i].Signald1==UP&&signals[i].Signalw1==UP&&signals[i].Signalmn==UP;
      signals[i].SignaldirdnSwing=signals[i].Signalm15==DOWN&&signals[i].Signalm30==DOWN&&signals[i].Signalh1==DOWN&&signals[i].Signalh4==DOWN&&signals[i].Signald1==DOWN&&signals[i].Signalw1==DOWN&&signals[i].Signalmn==DOWN;
   }
}

void SetColors(int i) {
         if(signals[i].Signalm1==1){Color=BullColor;}
         if(signals[i].Signalm1==-1){Color=BearColor;}
         if(signals[i].Signalm5==1){Color1=BullColor;}         
         if(signals[i].Signalm5==-1){Color1 =BearColor;}
         if(signals[i].Signalm15==1){Color2 =BullColor;}
         if(signals[i].Signalm15==-1){Color2=BearColor;}
         if(signals[i].Signalm30==1){Color3=BullColor;}
         if(signals[i].Signalm30==-1){Color3=BearColor;}
         if(signals[i].Signalh1==1){Color4=BullColor;}
         if(signals[i].Signalh1==-1){Color4=BearColor;}
         if(signals[i].Signalh4==1){Color5=BullColor;}
         if(signals[i].Signalh4==-1){Color5=BearColor;}
         if(signals[i].Signald1==1){Color6=BullColor;}
         if(signals[i].Signald1==-1){Color6=BearColor;}
         if(signals[i].Signalw1==1){Color7=BullColor;}
         if(signals[i].Signalw1==-1){Color7=BearColor;}
         if(signals[i].Signalmn==1){Color8=BullColor;}
         if(signals[i].Signalmn==-1){Color8=BearColor;}
 }
 /*
 void Get_M1_M5_MA() {

   for (int i=0;i<ArraySize(TradePairs);i++) {
   
      double BB00=iMA(TradePairs[i],PERIOD_M1,trade_Period_MA1,0,MODE_SMA,PRICE_CLOSE,0);      
      double BB0=iMA(TradePairs[i],PERIOD_M1,trade_Period_MA2,0,MODE_SMA,PRICE_CLOSE,0);      
      double BB1=iMA(TradePairs[i],PERIOD_M5,trade_Period_MA1,0,MODE_SMA,PRICE_CLOSE,0);      
      double BB10 = iMA(TradePairs[i],PERIOD_M5,trade_Period_MA2,0,MODE_SMA,PRICE_CLOSE,0);       
      
      if(iClose(TradePairs[i],PERIOD_M1,0)>BB00 && iClose(TradePairs[i],PERIOD_M1,0)>BB0 && BB00>BB0)
         signals[i].SignalhaM1=UP;
      if(iClose(TradePairs[i],PERIOD_M1,0)<BB00 && iClose(TradePairs[i],PERIOD_M1,0)<BB0 && BB00<BB0)
         signals[i].SignalhaM1=DOWN;
      if(iClose(TradePairs[i],PERIOD_M5,0)>BB1 && iClose(TradePairs[i],PERIOD_M5,0)>BB10 && BB1>BB10)
         signals[i].SignalhaM5=UP;
      if(iClose(TradePairs[i],PERIOD_M5,0)<BB1 && iClose(TradePairs[i],PERIOD_M5,0)<BB10 && BB1<BB10)
         signals[i].SignalhaM5=DOWN;
      
         
      signals[i].SignalmaM1up=(signals[i].SignalhaM1==UP);
      signals[i].SignalmaM1dn=(signals[i].SignalhaM1==DOWN);   
      
      signals[i].SignalmaM5up=(signals[i].SignalhaM5==UP);
      signals[i].SignalmaM5dn=(signals[i].SignalhaM5==DOWN);   
}
}*/
/*
void GetFL() {

   for (int i=0;i<ArraySize(TradePairs);i++) {
   
      double BBfn=iCustom(TradePairs[i],PERIOD_M1, "FL01","All tf",61,0,2.6,110,true,false,false,false,false,false,false,2,0);      
      double BBfv=iCustom(TradePairs[i],PERIOD_M1, "FL01","All tf",61,0,2.6,110,true,false,false,false,false,false,false,1,0);  
      double BBf0=iCustom(TradePairs[i],PERIOD_M1, "FL01","All tf",61,0,2.6,110,true,false,false,false,false,false,false,0,0);     
      double BBFn=iCustom(TradePairs[i],PERIOD_M1, "FL01","All tf",61,0,5.0,110,true,false,false,false,false,false,false,2,0);      
      double BBFv=iCustom(TradePairs[i],PERIOD_M1, "FL01","All tf",61,0,5.0,110,true,false,false,false,false,false,false,1,0);   
      
      
      if(iClose(TradePairs[i],PERIOD_M1,0)>BBFv)
         {signals[i].Signalfl=UPFv;}
        // else { signals[i].Signalfl= NONE;}
      if(iClose(TradePairs[i],PERIOD_M1,0)<BBFn)
         {signals[i].Signalfl=DOWNFn;}
        // else { signals[i].Signalfl= NONE;}  
      
      if(iClose(TradePairs[i],PERIOD_M1,0)>BBfv && iClose(TradePairs[i],PERIOD_M1,0)<BBFv)
         {signals[i].Signalfl=UPfv;}
        // else { signals[i].Signalfl= NONE;}
      if(iClose(TradePairs[i],PERIOD_M1,0)<BBfn && iClose(TradePairs[i],PERIOD_M1,0)>BBFn)
         {signals[i].Signalfl=DOWNfn;}
        // else { signals[i].Signalfl= NONE;}
      if(iClose(TradePairs[i],PERIOD_M1,0)>BBf0 && iClose(TradePairs[i],PERIOD_M1,0)<BBfv)
         {signals[i].Signalfl=UPfo;}
        // else { signals[i].Signalfl= NONE;}
      if(iClose(TradePairs[i],PERIOD_M1,0)<BBf0 && iClose(TradePairs[i],PERIOD_M1,0)>BBfn)
         {signals[i].Signalfl=DOWNfo;}
        // else { signals[i].Signalfl= NONE;}
      
      //signals[i].Signalfl0up=(signals[i].Signalfl0==UP);
      //signals[i].Signalfl0dn=(signals[i].Signalfl0==DOWN);    
      
      //signals[i].Signalfl1up=(signals[i].Signalfl1==UP);
      //signals[i].Signalfl1dn=(signals[i].Signalfl2==DOWN);   
      
      //signals[i].Signalfl2up=(signals[i].SignalhaM5==UP);
      //signals[i].Signalfl2dn=(signals[i].SignalhaM5==DOWN);   
}
}*/