#define SIGNAL_NONE 0
#define SIGNAL_BUY   1
#define SIGNAL_SELL  2
#define SIGNAL_CLOSEBUY 3
#define SIGNAL_CLOSESELL 4

#property copyright "tomhliles@yahoo.com"

extern bool only_one_entry_per_signal = False;

extern bool use_ma = False;
extern int period=95;
extern int shift=0;
extern int method=0;
extern int apply=1;

extern string for_opening_trades="";
extern bool open_trades = True;
extern bool open_with_qqea = True;
extern bool open_with_t3 = True;
extern bool open_with_dmi = True;
extern bool open_with_mom = True;
extern string momentum="";
extern int MomPeriod=14;
extern string dmi="";
extern int Smooth   = 5;
bool Hide_DI_Plus  = False;
bool Hide_DI_Minus = False;
bool Hide_DX   = true;
bool Hide_ADX  = true;
bool Hide_ADXR = true;
extern string t3="";
extern int Periods         = 3; //12 
extern double VolumeFactor = 0.7; //0.8
extern string qqea="";
extern int SF = 1; // original 5
extern int RSI_Period = 10; // original 14
extern double DARFACTOR = 4.05; //original 4.236

extern string for_closing_trades="";
extern bool close_trades = True;
extern bool close_with_qqea = True;
extern bool close_with_t3 = False;
extern bool close_with_dmi = False;
extern bool close_with_mom = False;
extern string cmomentum="";
extern int cMomPeriod=14;
extern string cdmi="";
extern int cSmooth   = 5;
 bool cHide_DI_Plus  = False;
bool cHide_DI_Minus = False;
bool cHide_DX   = true;
bool cHide_ADX  = true;
bool cHide_ADXR = true;
extern string ct3="";
extern int cPeriods         = 3; //12 
extern double cVolumeFactor = 0.7; //0.8
extern string cqqea="";
extern int cSF = 1; // original 5
extern int cRSI_Period = 14; // original 14
extern double cDARFACTOR = 4.05; //original 4.236

extern string mm="";
extern double Maximum_Risk = 1;
double losses_without_a_break = 0;
double lots_increase_when_losing = 0;
extern double Dis_Mm_If_Lots_Under = 0.01;
extern double Lots = 0.01;
extern double MaxLots = 50;
extern string other_settings="";
extern int MagicNumber = 22;
extern bool         Use_Sound_only = False;
extern bool         UseAlert = False;
extern bool SignalMail = False;
extern bool EachTickMode = true;
extern int Slippage = 20;
extern int StopLoss = 2000;
extern int TakeProfit = 2000;
extern int TrailingStop = 2000;
string              Message = "new alert from trendchaser";
string              NameFileSound = "alert.wav";
string              mode = "none";
string              qmode = "none";
string              tmode = "none";
string              clmode = "none";
string              mamode = "none";
bool   TradeAllowed=true; 
datetime bartime=1;                          // used to determine when a bar has moved
int      bartick=0;                          // number of times bars have moved

int BarCount;
int Current;
bool TickCheck = False;

double LotsOptimized()
  {
   double lot=Lots;
   int    orders=HistoryTotal();     // history orders total
   int    losses=losses_without_a_break;                  // number of losses orders without a break
//---- select lot size
   lot=NormalizeDouble(AccountFreeMargin()*Maximum_Risk/5000.0,10);
//---- calcuulate number of losses orders without a break
   if(lots_increase_when_losing>0)
     {
      for(int i=orders-1;i>=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==false) { Print("Error in history!"); break; }
         if(OrderSymbol()!=Symbol() || OrderType()>OP_SELL) continue;
         //----
         if(OrderProfit()>0) break;
         if(OrderProfit()<0) losses++;
        }
      if(losses>1) lot=NormalizeDouble(lot+lot+losses/lots_increase_when_losing,2);
     }
//---- return lot size
   if(lot<Dis_Mm_If_Lots_Under) lot=Lots;
   if(lot> MaxLots) lot=MaxLots;
   return(lot);
  }
int init() {
   BarCount = Bars;

   if (EachTickMode) Current = 0; else Current = 1;

   return(0);
}

int deinit() {
   return(0);
}
int start() {

static bool ITradedOnThisBar;
  int      OrdersPerSymbol=0;
  int      cnt=0;
  if(bartime!=Time[0]) 
     {
      bartime=Time[0];
      bartick++; 
      OrdersPerSymbol=0;
      for(cnt=OrdersTotal();cnt>=0;cnt--)
        {
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
         if( OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber) OrdersPerSymbol++;
        } 

      // this allows only one trade per bar preventing
      // lots of trades on big, single bar news moves
      if(OrdersPerSymbol==0) TradeAllowed=true;
     }
if (use_ma){
   mamode ="yes";
     {

     }
   }
   if (use_ma==False){
   mamode ="no";
     {

     }
   }

if (EachTickMode){
   tmode ="on";
     {

     }
   }
   if (EachTickMode==False){
   tmode ="off";
     {

     }
   }
 if (only_one_entry_per_signal){
   mode ="single entry";
     {

     }
   }
   if (only_one_entry_per_signal==False){
   mode ="re-entry";
     {

     }
   }
   if (open_with_qqea&&open_with_t3==False&&open_with_dmi==False&&open_with_mom==False){
   qmode ="qqea";
     {

     }
   }
   if (open_with_qqea&&open_with_t3&&open_with_dmi==False&&open_with_mom==False){
   qmode ="qqea t3";
     {

     }
   }
   if (open_with_qqea&&open_with_t3&&open_with_dmi&&open_with_mom==False){
   qmode ="qqea t3 dmi";
     {

     }
   }
      if (open_with_qqea&&open_with_t3&&open_with_dmi&&open_with_mom){
   qmode ="qqea t3 dmi mom";
     {

     }
   }
   if (open_with_qqea&&open_with_t3==False&&open_with_dmi&&open_with_mom==False){
   qmode ="qqea dmi";
     {

     }
   }
   if (open_with_qqea&&open_with_t3==False&&open_with_dmi&&open_with_mom){
   qmode ="qqea dmi mom";
     {

     }
   }
   if (open_with_qqea&&open_with_t3&&open_with_dmi==False&&open_with_mom){
   qmode ="qqea t3 mom";
     {

     }
   }
   if (open_with_qqea&&open_with_t3==False&&open_with_dmi==False&&open_with_mom){
   qmode ="qqea mom";
     {

     }
   }
      if (open_with_qqea==False&&open_with_t3&&open_with_dmi&&open_with_mom){
   qmode ="t3 dmi mom";
     {

     }
   }
   if (open_with_qqea==False&&open_with_t3&&open_with_dmi&&open_with_mom==False){
   qmode ="t3 dmi";
     {

     }
   }
   if (open_with_qqea==False&&open_with_t3&&open_with_dmi==False&&open_with_mom){
   qmode ="t3 mom";
     {

     }
   }
   if (open_with_qqea==False&&open_with_t3&&open_with_dmi==False&&open_with_mom==False){
   qmode ="t3";
     {

     }
   }
   if (open_with_qqea==False&&open_with_t3==False&&open_with_dmi&&open_with_mom){
   qmode ="dmi mom";
     {

     }
   }
   if (open_with_qqea==False&&open_with_t3==False&&open_with_dmi&&open_with_mom==False){
   qmode ="dmi";
     {

     }
   }
   if (open_with_qqea==False&&open_with_t3==False&&open_with_dmi==False&&open_with_mom){
   qmode ="mom";
     {

     }
   }
   if (close_with_qqea&&close_with_t3==False&&close_with_dmi==False&&close_with_mom==False){
   clmode ="qqea";
     {

     }
   }
   if (close_with_qqea&&close_with_t3&&close_with_dmi==False&&close_with_mom==False){
   clmode ="qqea t3";
     {

     }
   }
   if (close_with_qqea&&close_with_t3&&close_with_dmi&&close_with_mom==False){
   clmode ="qqea t3 dmi";
     {

     }
   }
      if (close_with_qqea&&close_with_t3&&close_with_dmi&&close_with_mom){
   clmode ="qqea t3 dmi mom";
     {

     }
   }
   if (close_with_qqea&&close_with_t3==False&&close_with_dmi&&close_with_mom==False){
   clmode ="qqea dmi";
     {

     }
   }
   if (close_with_qqea&&close_with_t3==False&&close_with_dmi&&close_with_mom){
   clmode ="qqea dmi mom";
     {

     }
   }
   if (close_with_qqea&&close_with_t3&&close_with_dmi==False&&close_with_mom){
   clmode ="qqea t3 mom";
     {

     }
   }
   if (close_with_qqea&&close_with_t3==False&&close_with_dmi==False&&close_with_mom){
   clmode ="qqea mom";
     {

     }
   }
      if (close_with_qqea==False&&close_with_t3&&close_with_dmi&&close_with_mom){
   clmode ="t3 dmi mom";
     {

     }
   }
   if (close_with_qqea==False&&close_with_t3&&close_with_dmi&&close_with_mom==False){
   clmode ="t3 dmi";
     {

     }
   }
   if (close_with_qqea==False&&close_with_t3&&close_with_dmi==False&&close_with_mom){
   clmode ="t3 mom";
     {

     }
   }
   if (close_with_qqea==False&&close_with_t3&&close_with_dmi==False&&close_with_mom==False){
   clmode ="t3";
     {

     }
   }
   if (close_with_qqea==False&&close_with_t3==False&&close_with_dmi&&close_with_mom){
   clmode ="dmi mom";
     {

     }
   }
   if (close_with_qqea==False&&close_with_t3==False&&close_with_dmi&&close_with_mom==False){
   clmode ="dmi";
     {

     }
   }
   if (close_with_qqea==False&&close_with_t3==False&&close_with_dmi==False&&close_with_mom){
   clmode ="mom";
     {

     }
   }


    int Leverage=AccountLeverage(); 
   double Balance=AccountBalance(); 
   double FreeMargin=AccountFreeMargin();
    double profit=AccountProfit();
    double equity=AccountEquity();
    int    MAXLOT=MarketInfo("GBPJPYm",MODE_MAXLOT);
    
    
Comment("\n"," --***--supernova by trendchaser v3.1--***--",(""),
"\n","entry mode=",(mode),
"   tick mode=",(tmode),
"   use ma=",(mamode),
"\n","ind used to open trades=",(qmode),
"     ind used to close trades=",(clmode),
"\n","tp= ",DoubleToStr(TakeProfit,0),
"     sl=",DoubleToStr(StopLoss,0),
"     ts=",DoubleToStr(TrailingStop,0),
"\n","ma=",DoubleToStr(period,0),
"     shift=",DoubleToStr(shift,0),
"     method=",DoubleToStr(method,0),
"     apply=",DoubleToStr(apply,0),
"\n","qqea SF= ",DoubleToStr(SF,0),
"     RSI_Period= ",DoubleToStr(RSI_Period,0),
"     DARFACTOR= ",DoubleToStr(DARFACTOR,4),
"\n","t3 period= ",DoubleToStr(Periods,0),
"     VolumeFactor= ",DoubleToStr(VolumeFactor,1),
"\n","dmi smooth= ",DoubleToStr(Smooth,0),
"\n","momentum period= ",DoubleToStr(MomPeriod,0),

"\n",
"     profit= ",DoubleToStr(profit,2),
"     Equity= ",DoubleToStr(equity,2),
"     FREE MARGIN= ",DoubleToStr(FreeMargin,2),
"     risk= ",DoubleToStr(Maximum_Risk,2),
"\n","     Broker time= ",TimeToStr(TimeCurrent()),
"\n","     Magic Number= ",DoubleToStr(MagicNumber,0));

   int Order = SIGNAL_NONE;
   int Total, Ticket;
   double StopLossLevel, TakeProfitLevel;



   if (EachTickMode && Bars != BarCount) TickCheck = False;
   Total = OrdersTotal();
   Order = SIGNAL_NONE;


double Buy20_1 = iClose(NULL, 0, Current + 0);
double Buy20_2 = iMA(NULL, 0, period, shift, method, apply, Current + 0);
double Buy1_1 = iCustom(NULL, 0, "QQEA", SF,RSI_Period,DARFACTOR,0, Current + 0);
double Buy1_2 = iCustom(NULL, 0, "QQEA", SF,RSI_Period,DARFACTOR,1, Current + 0);
double Buy2_1 = iCustom(NULL, 0, "QQEA", SF,RSI_Period,DARFACTOR,0, Current + 1);
double Buy2_2 = iCustom(NULL, 0, "QQEA", SF,RSI_Period,DARFACTOR,1, Current + 1);

double Buy3_1 = iLow(NULL, 0, Current + 0);
double Buy3_2 = iCustom(NULL, 0,  "T3", Periods, VolumeFactor, Current + 0);

double Buy6_1 = iLow(NULL, 0, Current + 1);
double Buy6_2 = iCustom(NULL, 0,  "T3", Periods, VolumeFactor, Current + 0);

double Buy7_1 = iLow(NULL, 0, Current + 2);
double Buy7_2 = iCustom(NULL, 0,  "T3", Periods, VolumeFactor, Current + 0);

double Buy4_1 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,0, Current + 0);
double Buy4_2 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,1, Current + 0);

double Buy8_1 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,0, Current + 0);
double Buy8_2 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,1, Current + 0);

double Buy9_1 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,0, Current + 0);
double Buy9_2 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,1, Current + 0);

double Buy5_1 = iCustom(NULL, 0, "MomentumVT", MomPeriod,0, Current + 0);
double Buy5_2 = 0;

double Buy10_1 = iCustom(NULL, 0, "MomentumVT", MomPeriod,0, Current + 0);
double Buy10_2 = 0;

double Sell20_1 = iClose(NULL, 0, Current + 0);
double Sell20_2 = iMA(NULL, 0, period, shift, method, apply, Current + 0);
double Sell1_1 = iCustom(NULL, 0, "QQEAopen", SF,RSI_Period,DARFACTOR,0, Current + 0);
double Sell1_2 = iCustom(NULL, 0, "QQEAopen", SF,RSI_Period,DARFACTOR,1,Current + 0);
double Sell2_1 = iCustom(NULL, 0, "QQEAopen", SF,RSI_Period,DARFACTOR,0, Current + 1);
double Sell2_2 = iCustom(NULL, 0, "QQEAopen", SF,RSI_Period,DARFACTOR,1,Current + 1);

double Sell3_1 = iHigh(NULL, 0, Current + 0);
double Sell3_2 = iCustom(NULL, 0,  "T3", Periods, VolumeFactor, Current + 0);

double Sell6_1 = iHigh(NULL, 0, Current + 0);
double Sell6_2 = iCustom(NULL, 0,  "T3", Periods, VolumeFactor, Current + 0);

double Sell7_1 = iHigh(NULL, 0, Current + 0);
double Sell7_2 = iCustom(NULL, 0,  "T3", Periods, VolumeFactor, Current + 0);

double Sell4_1 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,0, Current + 0);
double Sell4_2 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,1, Current + 0);

double Sell8_1 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,0, Current + 0);
double Sell8_2 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,1, Current + 0);

double Sell9_1 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,0, Current + 0);
double Sell9_2 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,1, Current + 0);

double Sell5_1 = iCustom(NULL, 0, "MomentumVT", MomPeriod,0, Current + 0);
double Sell5_2 = 0;

double Sell10_1 = iCustom(NULL, 0, "MomentumVT", MomPeriod,0, Current + 0);
double Sell10_2 = 0;
 
 
double CloseBuy1_1 = iCustom(NULL, 0, "QQEAopen", SF,RSI_Period,DARFACTOR,0, Current + 0);
double CloseBuy1_2 = iCustom(NULL, 0, "QQEAopen", SF,RSI_Period,DARFACTOR,1, Current + 0);
double CloseSell1_1 = iCustom(NULL, 0, "QQEAopen", SF,RSI_Period,DARFACTOR,0, Current + 0);
double CloseSell1_2 = iCustom(NULL, 0, "QQEAopen", SF,RSI_Period,DARFACTOR,1, Current + 0);


double CloseBuy3_1 = iLow(NULL, 0, Current + 0);
double CloseBuy3_2 = iCustom(NULL, 0,  "T3", Periods, VolumeFactor, Current + 0);

double CloseBuy4_1 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,0, Current + 0);
double CloseBuy4_2 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,1, Current + 0);

double CloseBuy5_1 = iCustom(NULL, 0, "MomentumVT", MomPeriod,0, Current + 0);
double CloseBuy5_2 = 0;


double CloseSell3_1 = iHigh(NULL, 0, Current + 0);
double CloseSell3_2 = iCustom(NULL, 0,  "T3", Periods, VolumeFactor, Current + 0);

double CloseSell4_1 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,0, Current + 0);
double CloseSell4_2 = iCustom(NULL, 0, "DMI", Smooth,Hide_DI_Plus,Hide_DI_Minus,Hide_DX,Hide_ADX,Hide_ADXR,1, Current + 0);

double CloseSell5_1 = iCustom(NULL, 0, "MomentumVT", MomPeriod,0, Current + 0);
double CloseSell5_2 = 0;


   bool IsTrade = False;

   for (int i = 0; i < Total; i ++) {
      OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
      if(OrderType() <= OP_SELL &&  OrderSymbol() == Symbol()) {
         IsTrade = True;
         if(OrderType() == OP_BUY) {
         

          if(ITradedOnThisBar != Bars)
         if (close_trades&&close_with_qqea&&close_with_t3==False&&close_with_dmi==False&&close_with_mom==False){
         if(ITradedOnThisBar != Bars)
  if (CloseBuy1_1 < CloseBuy1_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_t3&&close_with_dmi==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy1_1 < CloseBuy1_2&&CloseBuy3_1 < CloseBuy3_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_dmi&&close_with_t3==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy1_1 < CloseBuy1_2&&CloseBuy4_1 < CloseBuy4_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_mom&&close_with_dmi==False&&close_with_t3==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy1_1 < CloseBuy1_2&&CloseBuy5_1 < CloseBuy5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_t3&&close_with_dmi&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy1_1 < CloseBuy1_2&&CloseBuy3_1 < CloseBuy3_2&&CloseBuy4_1 < CloseBuy4_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_t3&&close_with_mom&&close_with_dmi==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy1_1 < CloseBuy1_2&&CloseBuy3_1 < CloseBuy3_2&&CloseBuy5_1 < CloseBuy5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_dmi&&close_with_mom&&close_with_t3==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy1_1 < CloseBuy1_2&&CloseBuy4_1 < CloseBuy4_2&&CloseBuy5_1 < CloseBuy5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_t3&&close_with_qqea==False&&close_with_dmi==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy3_1 < CloseBuy3_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_t3&&close_with_dmi&&close_with_qqea==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy3_1 < CloseBuy3_2&&CloseBuy4_1 < CloseBuy4_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_t3&&close_with_mom&&close_with_dmi==False&&close_with_qqea==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy3_1 < CloseBuy3_2&&CloseBuy5_1 < CloseBuy5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_t3&&close_with_dmi&&close_with_mom&&close_with_qqea==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy3_1 < CloseBuy3_2&&CloseBuy4_1 < CloseBuy4_2&&CloseBuy5_1 < CloseBuy5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_dmi&&close_with_qqea==False&&close_with_t3==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy4_1 < CloseBuy4_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_dmi&&close_with_mom&&close_with_t3==False&&close_with_qqea==False){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy4_1 < CloseBuy4_2&&CloseBuy5_1 < CloseBuy5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
    if (close_trades&&close_with_mom&&close_with_t3==False&&close_with_qqea==False&&close_with_dmi==False){
    if(ITradedOnThisBar != Bars)
  if (CloseBuy5_1 < CloseBuy5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_mom&&close_with_qqea&&close_with_t3&&close_with_dmi){
   if(ITradedOnThisBar != Bars)
  if (CloseBuy5_1 < CloseBuy5_2&&CloseBuy4_1 < CloseBuy4_2&&CloseBuy3_1 < CloseBuy3_2&&CloseBuy1_1 < CloseBuy1_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
 

            if (Order == SIGNAL_CLOSEBUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;
               if (Use_Sound_only) PlaySound(NameFileSound);
               if (UseAlert) Alert(Message);
               IsTrade = False;
               continue;
            }
            if(true && TrailingStop > 0) {                 
               if(Bid - OrderOpenPrice() > Point * TrailingStop) {
                  if(OrderStopLoss() < Bid - Point * TrailingStop) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderTakeProfit(), 0, MediumSeaGreen);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         } else {
         
 if(ITradedOnThisBar != Bars)
   if (close_trades&&close_with_qqea&&close_with_t3==False&&close_with_dmi==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell1_1 > CloseSell1_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_t3&&close_with_dmi==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell1_1 > CloseSell1_2&&CloseSell3_1 > CloseSell3_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_dmi&&close_with_t3==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell1_1 > CloseSell1_2&&CloseSell4_1 > CloseSell4_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_mom&&close_with_dmi==False&&close_with_t3==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell1_1 > CloseSell1_2&&CloseSell5_1 > CloseSell5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_t3&&close_with_dmi&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell1_1 > CloseSell1_2&&CloseSell3_1 > CloseSell3_2&&CloseSell4_1 > CloseSell4_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_t3&&close_with_mom&&close_with_dmi==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell1_1 > CloseSell1_2&&CloseSell3_1 > CloseSell3_2&&CloseSell5_1 > CloseSell5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_qqea&&close_with_dmi&&close_with_mom&&close_with_t3==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell1_1 > CloseSell1_2&&CloseSell4_1 > CloseSell4_2&&CloseSell5_1 > CloseSell5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_t3&&close_with_qqea==False&&close_with_dmi==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell3_1 > CloseSell3_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSEBUY;
     else
     {

     }
   }
   if (close_trades&&close_with_t3&&close_with_dmi&&close_with_qqea==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell3_1 > CloseSell3_2&&CloseSell4_1 > CloseSell4_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_t3&&close_with_mom&&close_with_dmi==False&&close_with_qqea==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell3_1 > CloseSell3_2&&CloseSell5_1 > CloseSell5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_t3&&close_with_dmi&&close_with_mom&&close_with_qqea==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell3_1 > CloseSell3_2&&CloseSell4_1 > CloseSell4_2&&CloseSell5_1 > CloseSell5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_dmi&&close_with_qqea==False&&close_with_t3==False&&close_with_mom==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell4_1 > CloseSell4_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_dmi&&close_with_mom&&close_with_t3==False&&close_with_qqea==False){
   if(ITradedOnThisBar != Bars)
  if (CloseSell4_1 > CloseSell4_2&&CloseSell5_1 > CloseSell5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
    if (close_trades&&close_with_mom&&close_with_t3==False&&close_with_qqea==False&&close_with_dmi==False){
    if(ITradedOnThisBar != Bars)
  if (CloseSell5_1 > CloseSell5_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
   if (close_trades&&close_with_mom&&close_with_qqea&&close_with_t3&&close_with_dmi){
   if(ITradedOnThisBar != Bars)
  if (CloseSell5_1 > CloseSell5_2&&CloseSell4_1 > CloseSell4_2&&CloseSell3_1 > CloseSell3_2&&CloseSell1_1 > CloseSell1_2&&MagicNumber==MagicNumber) Order = SIGNAL_CLOSESELL;
     else
     {

     }
   }
 

           
            if (Order == SIGNAL_CLOSESELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
               OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;
               if (Use_Sound_only) PlaySound(NameFileSound);
               if (UseAlert) Alert(Message);
               IsTrade = False;
               continue;
            }
            if(true && TrailingStop > 0) {                 
               if((OrderOpenPrice() - Ask) > (Point * TrailingStop)) {
                  if((OrderStopLoss() > (Ask + Point * TrailingStop)) || (OrderStopLoss() == 0)) {
                     OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderTakeProfit(), 0, DarkOrange);
                     if (!EachTickMode) BarCount = Bars;
                     continue;
                  }
               }
            }
         }
      }
   }
   datetime tLastLongEntry = Time[1];
datetime tLastShortEntry = Time[1];

 if(ITradedOnThisBar != Bars)
if (use_ma==False&&only_one_entry_per_signal&&open_with_qqea&&open_with_t3==False&&open_with_dmi==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_qqea&&open_with_t3&&open_with_dmi==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_qqea&&open_with_dmi&&open_with_t3==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy4_1 > Buy4_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_qqea&&open_with_mom&&open_with_t3==False&&open_with_dmi==False){
    if(ITradedOnThisBar != Bars)
   if (Buy5_1 > Buy5_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell5_1 < Sell5_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_qqea&&open_with_t3&&open_with_dmi&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy4_1 > Buy4_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell4_1 < Sell4_2 &&Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
    if (use_ma==False&&only_one_entry_per_signal&&open_with_qqea&&open_with_t3&&open_with_mom&&open_with_dmi==False){
    if(ITradedOnThisBar != Bars)
   if (Buy5_1 > Buy5_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell5_1 < Sell5_2 &&Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_qqea&&open_with_dmi&&open_with_mom&&open_with_t3==False){
    if(ITradedOnThisBar != Bars)
   if (Buy5_1 > Buy5_2 &&Buy4_1 > Buy4_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell5_1 < Sell5_2 &&Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_t3&&open_with_qqea==False&&open_with_dmi==False&&open_with_mom==False){
   if(ITradedOnThisBar != Bars)
   if (Buy6_1 > Buy6_2 && Buy7_1 <= Buy7_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell6_1 < Sell6_2 && Sell7_1 >= Sell7_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_t3&&open_with_dmi&&open_with_qqea==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy4_1 > Buy4_2 &&Buy6_1 > Buy6_2 && Buy7_1 <= Buy7_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell4_1 < Sell4_2 &&Sell6_1 < Sell6_2 && Sell7_1 >= Sell7_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_t3&&open_with_mom&&open_with_qqea==False&&open_with_dmi==False){
    if(ITradedOnThisBar != Bars)
   if (Buy5_1 > Buy5_2 &&Buy6_1 > Buy6_2 && Buy7_1 <= Buy7_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell5_1 < Sell5_2 &&Sell6_1 < Sell6_2 && Sell7_1 >= Sell7_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_t3&&open_with_mom&&open_with_dmi&&open_with_qqea==False){
   if(ITradedOnThisBar != Bars)
   if (Buy4_1 > Buy4_2 &&Buy5_1 > Buy5_2 &&Buy6_1 > Buy6_2 && Buy7_1 <= Buy7_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell4_1 < Sell4_2 &&Sell5_1 < Sell5_2 &&Sell6_1 < Sell6_2 && Sell7_1 >= Sell7_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_dmi&&open_with_t3==False&&open_with_qqea==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy8_1 > Buy8_2 && Buy9_1 <= Buy9_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell8_1 < Sell8_2 && Sell9_1 >= Sell9_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal&&open_with_qqea&&open_with_dmi&&open_with_t3&&open_with_mom){
    if(ITradedOnThisBar != Bars)
   if (Buy5_1 > Buy5_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell5_1 < Sell5_2 &&Sell3_1 < Sell3_2 &&Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   
   
   /////////////////////////////////////////////////////////////////////////////////////////
   
   
   
   
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_t3==False&&open_with_dmi==False&&open_with_mom==False){
   if (Buy1_1 > Buy1_2 ) Order = SIGNAL_BUY;
   if (Sell1_1 < Sell1_2 ) Order = SIGNAL_SELL;
   else
     {
   }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_t3&&open_with_dmi==False&&open_with_mom==False){
   if (Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_dmi&&open_with_t3==False&&open_with_mom==False){
   if (Buy4_1 > Buy4_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_mom&&open_with_t3==False&&open_with_dmi==False){
   if (Buy5_1 > Buy5_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell5_1 < Sell5_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_t3&&open_with_dmi&&open_with_mom==False){
   if (Buy4_1 > Buy4_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell4_1 < Sell4_2 &&Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
    if (use_ma==False&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_t3&&open_with_mom&&open_with_dmi==False){
   if (Buy5_1 > Buy5_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell5_1 < Sell5_2 &&Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_dmi&&open_with_mom&&open_with_t3==False){
   if (Buy5_1 > Buy5_2 &&Buy4_1 > Buy4_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell5_1 < Sell5_2 &&Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_t3&&open_with_qqea==False&&open_with_dmi==False&&open_with_mom==False){
   if (Buy6_1 > Buy6_2 && Buy7_1 > Buy7_2) Order = SIGNAL_BUY;
   if (Sell6_1 < Sell6_2 && Sell7_1 < Sell7_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_t3&&open_with_dmi&&open_with_qqea==False&&open_with_mom==False){
   if (Buy4_1 > Buy4_2 &&Buy6_1 > Buy6_2 && Buy7_1 > Buy7_2) Order = SIGNAL_BUY;
   if (Sell4_1 < Sell4_2 &&Sell6_1 < Sell6_2 && Sell7_1 < Sell7_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_t3&&open_with_mom&&open_with_dmi==False&&open_with_qqea==False){
   if (Buy5_1 > Buy5_2 &&Buy6_1 > Buy6_2 && Buy7_1 > Buy7_2) Order = SIGNAL_BUY;
   if (Sell5_1 < Sell5_2 &&Sell6_1 < Sell6_2 && Sell7_1 < Sell7_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_t3&&open_with_mom&&open_with_dmi&&open_with_qqea==False){
   if (Buy4_1 > Buy4_2 &&Buy5_1 > Buy5_2 &&Buy6_1 > Buy6_2 && Buy7_1 > Buy7_2) Order = SIGNAL_BUY;
   if (Sell4_1 < Sell4_2 &&Sell5_1 < Sell5_2 &&Sell6_1 < Sell6_2 && Sell7_1 < Sell7_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_dmi&&open_with_t3==False&&open_with_mom==False&&open_with_qqea==False){
   if (Buy8_1 > Buy8_2 && Buy9_1 > Buy9_2) Order = SIGNAL_BUY;
   if (Sell8_1 < Sell8_2 && Sell9_1 < Sell9_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma==False&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_dmi&&open_with_t3&&open_with_mom){
   if (Buy5_1 > Buy5_2 &&Buy3_1 > Buy3_2 &&Buy4_1 > Buy4_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell5_1 < Sell5_2 &&Sell3_1 < Sell3_2 &&Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_qqea&&open_with_t3==False&&open_with_dmi==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_qqea&&open_with_t3&&open_with_dmi==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_qqea&&open_with_dmi&&open_with_t3==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy4_1 > Buy4_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_qqea&&open_with_mom&&open_with_t3==False&&open_with_dmi==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy5_1 > Buy5_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell5_1 < Sell5_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_qqea&&open_with_t3&&open_with_dmi&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy4_1 > Buy4_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell4_1 < Sell4_2 &&Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
    if (use_ma&&only_one_entry_per_signal&&open_with_qqea&&open_with_t3&&open_with_mom&&open_with_dmi==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy5_1 > Buy5_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell5_1 < Sell5_2 &&Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_qqea&&open_with_dmi&&open_with_mom&&open_with_t3==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy5_1 > Buy5_2 &&Buy4_1 > Buy4_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell5_1 < Sell5_2 &&Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_t3&&open_with_qqea==False&&open_with_dmi==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy6_1 > Buy6_2 && Buy7_1 <= Buy7_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell6_1 < Sell6_2 && Sell7_1 >= Sell7_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_t3&&open_with_dmi&&open_with_qqea==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy4_1 > Buy4_2 &&Buy6_1 > Buy6_2 && Buy7_1 <= Buy7_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell4_1 < Sell4_2 &&Sell6_1 < Sell6_2 && Sell7_1 >= Sell7_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_t3&&open_with_mom&&open_with_qqea==False&&open_with_dmi==False){
   if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy5_1 > Buy5_2 &&Buy6_1 > Buy6_2 && Buy7_1 <= Buy7_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell5_1 < Sell5_2 &&Sell6_1 < Sell6_2 && Sell7_1 >= Sell7_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_t3&&open_with_mom&&open_with_dmi&&open_with_qqea==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy4_1 > Buy4_2 &&Buy5_1 > Buy5_2 &&Buy6_1 > Buy6_2 && Buy7_1 <= Buy7_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell4_1 < Sell4_2 &&Sell5_1 < Sell5_2 &&Sell6_1 < Sell6_2 && Sell7_1 >= Sell7_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_dmi&&open_with_t3==False&&open_with_qqea==False&&open_with_mom==False){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy8_1 > Buy8_2 && Buy9_1 <= Buy9_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell8_1 < Sell8_2 && Sell9_1 >= Sell9_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal&&open_with_qqea&&open_with_dmi&&open_with_t3&&open_with_mom){
    if(ITradedOnThisBar != Bars)
   if (Buy20_1 > Buy20_2 &&Buy5_1 > Buy5_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 <= Buy2_2 && tLastLongEntry < Time[0]) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell5_1 < Sell5_2 &&Sell3_1 < Sell3_2 &&Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 >= Sell2_2 && tLastShortEntry < Time[0]) Order = SIGNAL_SELL;
   else
     {

     }
   }
   
   
   /////////////////////////////////////////////////////////////////////////////////////////
   
   
   
   
   if (use_ma&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_t3==False&&open_with_dmi==False&&open_with_mom==False){
   if (Buy20_1 > Buy20_2 &&Buy1_1 > Buy1_2 ) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell1_1 < Sell1_2 ) Order = SIGNAL_SELL;
   else
     {
   }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_t3&&open_with_dmi==False&&open_with_mom==False){
   if (Buy20_1 > Buy20_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_dmi&&open_with_t3==False&&open_with_mom==False){
   if (Buy20_1 > Buy20_2 &&Buy4_1 > Buy4_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_mom&&open_with_t3==False&&open_with_dmi==False){
   if (Buy20_1 > Buy20_2 &&Buy5_1 > Buy5_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell5_1 < Sell5_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_t3&&open_with_dmi&&open_with_mom==False){
   if (Buy20_1 > Buy20_2 &&Buy4_1 > Buy4_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell4_1 < Sell4_2 &&Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
    if (use_ma&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_t3&&open_with_mom&&open_with_dmi==False){
   if (Buy20_1 > Buy20_2 &&Buy5_1 > Buy5_2 &&Buy3_1 > Buy3_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell5_1 < Sell5_2 &&Sell3_1 < Sell3_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_dmi&&open_with_mom&&open_with_t3==False){
   if (Buy20_1 > Buy20_2 &&Buy5_1 > Buy5_2 &&Buy4_1 > Buy4_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell5_1 < Sell5_2 &&Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_t3&&open_with_qqea==False&&open_with_dmi==False&&open_with_mom==False){
   if (Buy20_1 > Buy20_2 &&Buy6_1 > Buy6_2 && Buy7_1 > Buy7_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell6_1 < Sell6_2 && Sell7_1 < Sell7_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_t3&&open_with_dmi&&open_with_qqea==False&&open_with_mom==False){
   if (Buy20_1 > Buy20_2 &&Buy4_1 > Buy4_2 &&Buy6_1 > Buy6_2 && Buy7_1 > Buy7_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell4_1 < Sell4_2 &&Sell6_1 < Sell6_2 && Sell7_1 < Sell7_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_t3&&open_with_mom&&open_with_dmi==False&&open_with_qqea==False){
   if (Buy20_1 > Buy20_2 &&Buy5_1 > Buy5_2 &&Buy6_1 > Buy6_2 && Buy7_1 > Buy7_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell5_1 < Sell5_2 &&Sell6_1 < Sell6_2 && Sell7_1 < Sell7_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_t3&&open_with_mom&&open_with_dmi&&open_with_qqea==False){
   if (Buy20_1 > Buy20_2 &&Buy4_1 > Buy4_2 &&Buy5_1 > Buy5_2 &&Buy6_1 > Buy6_2 && Buy7_1 > Buy7_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell4_1 < Sell4_2 &&Sell5_1 < Sell5_2 &&Sell6_1 < Sell6_2 && Sell7_1 < Sell7_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_dmi&&open_with_t3==False&&open_with_mom==False&&open_with_qqea==False){
   if (Buy20_1 > Buy20_2 &&Buy8_1 > Buy8_2 && Buy9_1 > Buy9_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell8_1 < Sell8_2 && Sell9_1 < Sell9_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   if (use_ma&&only_one_entry_per_signal==False&&open_with_qqea&&open_with_dmi&&open_with_t3&&open_with_mom){
   if (Buy20_1 > Buy20_2 &&Buy5_1 > Buy5_2 &&Buy3_1 > Buy3_2 &&Buy4_1 > Buy4_2 &&Buy1_1 > Buy1_2 && Buy2_1 > Buy2_2) Order = SIGNAL_BUY;
   if (Sell20_1 < Sell20_2 &&Sell5_1 < Sell5_2 &&Sell3_1 < Sell3_2 &&Sell4_1 < Sell4_2 &&Sell1_1 < Sell1_2 && Sell2_1 < Sell2_2) Order = SIGNAL_SELL;
   else
     {

     }
   }
   
   if (Order == SIGNAL_BUY && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         if (AccountFreeMargin() < (0 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (true) StopLossLevel = Ask - StopLoss * Point; else StopLossLevel = 0.0;
         if (true) TakeProfitLevel = Ask + TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_BUY, LotsOptimized(), Ask, Slippage, StopLossLevel, TakeProfitLevel, "buy trendchaser supernovav3.1(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
				Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
                               if (Use_Sound_only) PlaySound(NameFileSound);
               if (UseAlert) Alert(Message);
			} else {
				Print("Error opening BUY order : ", GetLastError());
			}
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }
   if (Order == SIGNAL_SELL && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
      if(!IsTrade) {
         if (AccountFreeMargin() < (1000 * Lots)) {
            Print("We have no money. Free Margin = ", AccountFreeMargin());
            return(0);
         }

         if (true) StopLossLevel = Bid + StopLoss * Point; else StopLossLevel = 0.0;
         if (true) TakeProfitLevel = Bid - TakeProfit * Point; else TakeProfitLevel = 0.0;

         Ticket = OrderSend(Symbol(), OP_SELL, LotsOptimized(), Bid, Slippage, StopLossLevel, TakeProfitLevel, "sell trendchaser supernovav3.1(#" + MagicNumber + ")", MagicNumber, 0, DeepPink);
         if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
				Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
                               if (Use_Sound_only) PlaySound(NameFileSound);
               if (UseAlert) Alert(Message);
			} else {
				Print("Error opening SELL order : ", GetLastError());
			}
         }
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
         return(0);
      }
   }

   if (!EachTickMode) BarCount = Bars;

   return(0);
}