
   extern string Account_Settings = "---------- Account Settings";
   extern double Risk_Percent=0.10;
   extern string General_Settings = "---------- General Settings";
   extern double fastma=29;
   extern double slowma=65;
   extern int currency_momentum=64;
   extern int trend_momentum=25;
   extern int MaxpipfromEMA=32;
   extern string System_Settings = "----------System Settings-----WARNING!----DO NOT CHANGE!----";
   extern double Spike_Define=2.7;
   extern int RangePoint=9;
   extern double JumpWidth_Percen=0.25;
   extern int TrendPeriod=PERIOD_H1;

   string Trend,Buy,Sell,TradeComm;
   double Close1,Close2,Close3,Close4,Close5,Close6,Open1,Open2,Open3,Open4,Open5,Open6,
          Fast1,Fast2,Fast3,Fast4,Fast5,Fast6,Slow1,Slow2,Slow3,Slow4,Slow5,Slow6,
          Average,FastW,Currency_momentumA,Currency_momentumB,Currency_momentumC,
          Trend_momentumFastA,Trend_momentumFastB,Trend_momentumFastC,Trend_momentumFastD,
          Trend_momentumSlowA,Trend_momentumSlowB,
          Width1,Width2,Width3,Width4,Width5,Width6,
          WidthW1,WidthW2,WidthW3,WidthW4,WidthW5,WidthW6;
   int Trendd,TFTime=0;
   
    void TrendPreFetch() 
      {
      Fast1=iMA(NULL,TrendPeriod,fastma,0,MODE_EMA,PRICE_CLOSE,1);    Slow1=iMA(NULL,TrendPeriod,slowma,0,MODE_EMA,PRICE_CLOSE,1);
      Fast2=iMA(NULL,TrendPeriod,fastma,0,MODE_EMA,PRICE_CLOSE,2);    Slow2=iMA(NULL,TrendPeriod,slowma,0,MODE_EMA,PRICE_CLOSE,2);
      Fast3=iMA(NULL,TrendPeriod,fastma,0,MODE_EMA,PRICE_CLOSE,3);    Slow3=iMA(NULL,TrendPeriod,slowma,0,MODE_EMA,PRICE_CLOSE,3);
      Fast4=iMA(NULL,TrendPeriod,fastma,0,MODE_EMA,PRICE_CLOSE,4);    Slow4=iMA(NULL,TrendPeriod,slowma,0,MODE_EMA,PRICE_CLOSE,4);
      Fast5=iMA(NULL,TrendPeriod,fastma,0,MODE_EMA,PRICE_CLOSE,5);    Slow5=iMA(NULL,TrendPeriod,slowma,0,MODE_EMA,PRICE_CLOSE,5);
      Fast6=iMA(NULL,TrendPeriod,fastma,0,MODE_EMA,PRICE_CLOSE,6);    Slow6=iMA(NULL,TrendPeriod,slowma,0,MODE_EMA,PRICE_CLOSE,6);
      
      Close1=iClose(NULL,TrendPeriod,1);   Open1=iOpen(NULL,TrendPeriod,1);    Width1=MathAbs(Fast1-Slow1);    
      Close2=iClose(NULL,TrendPeriod,2);   Open2=iOpen(NULL,TrendPeriod,2);    Width2=MathAbs(Fast2-Slow2);    
      Close3=iClose(NULL,TrendPeriod,3);   Open3=iOpen(NULL,TrendPeriod,3);    Width3=MathAbs(Fast3-Slow3);    
      Close4=iClose(NULL,TrendPeriod,4);   Open4=iOpen(NULL,TrendPeriod,4);    Width4=MathAbs(Fast4-Slow4);    
      Close5=iClose(NULL,TrendPeriod,5);   Open5=iOpen(NULL,TrendPeriod,5);    Width5=MathAbs(Fast5-Slow5);    
      Close6=iClose(NULL,TrendPeriod,6);   Open6=iOpen(NULL,TrendPeriod,6);    Width6=MathAbs(Fast6-Slow6); 
         
      WidthW1=MathAbs(iMA(NULL,TrendPeriod,fastma*3.8,0,MODE_EMA,PRICE_CLOSE,1)-Slow1); 
      WidthW2=MathAbs(iMA(NULL,TrendPeriod,fastma*3.8,0,MODE_EMA,PRICE_CLOSE,2)-Slow2);  
      WidthW3=MathAbs(iMA(NULL,TrendPeriod,fastma*3.8,0,MODE_EMA,PRICE_CLOSE,3)-Slow3);  
      WidthW4=MathAbs(iMA(NULL,TrendPeriod,fastma*3.8,0,MODE_EMA,PRICE_CLOSE,4)-Slow4);  
      WidthW5=MathAbs(iMA(NULL,TrendPeriod,fastma*3.8,0,MODE_EMA,PRICE_CLOSE,5)-Slow5);  
      WidthW6=MathAbs(iMA(NULL,TrendPeriod,fastma*3.8,0,MODE_EMA,PRICE_CLOSE,6)-Slow6);   
                                                                                    
      Average=iMA(NULL,TrendPeriod,3,0,MODE_EMA,PRICE_CLOSE,1);
      FastW=iMA(NULL,TrendPeriod,fastma*3.8,0,MODE_EMA,PRICE_CLOSE,1);
      Currency_momentumA=iCustom(NULL,TrendPeriod,"OSMAMA",4,6,currency_momentum,1,currency_momentum,0,1);
      Currency_momentumB=iCustom(NULL,TrendPeriod,"OSMAMA",4,6,currency_momentum,1,currency_momentum,1,1);
      Currency_momentumC=iCustom(NULL,TrendPeriod,"OSMAMA",4,6,currency_momentum,1,currency_momentum,0,3);
      Trend_momentumFastA=iCustom(NULL,TrendPeriod,"OSMAMA",4,6,trend_momentum,1,trend_momentum,0,1);
      Trend_momentumFastB=iCustom(NULL,TrendPeriod,"OSMAMA",4,6,trend_momentum,1,trend_momentum,0,2);
      Trend_momentumFastC=iCustom(NULL,TrendPeriod,"OSMAMA",4,6,trend_momentum,1,trend_momentum,0,3);
      Trend_momentumFastD=iCustom(NULL,TrendPeriod,"OSMAMA",4,6,trend_momentum,1,trend_momentum,1,1);
      Trend_momentumSlowA=iCustom(NULL,TrendPeriod,"OSMAMA",6,8,slowma*3,currency_momentum*3,currency_momentum*3,0,1);
      Trend_momentumSlowB=iCustom(NULL,TrendPeriod,"OSMAMA",6,8,slowma*3,currency_momentum*3,currency_momentum*3,0,5);
      }
      
      
     

   int start()
      {
      double Averagepips,Opentime,Stopip;
      int i,open,Spike,SpikeW,Buyjump,Selljump,BuyjumpR,SelljumpR,Ticket,Cnt,Can,Ranging;
       
     
       if((TFTime!=iTime(Symbol(),TrendPeriod,1)))
             {
             TrendPreFetch();
             TFTime=iTime(Symbol(),PERIOD_H1,1);
             }
         
    
      int total=OrdersTotal();
      double AcctLeverage=AccountLeverage();
      double CurrencyLotSize=MarketInfo(Symbol(),MODE_LOTSIZE);
      double lot=AccountEquity()*Risk_Percent/(CurrencyLotSize/AcctLeverage);
   
      for(i=0;i<total;i++)
         {
         OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            {
            if(OrderSymbol()==Symbol())
               {
              open++;
               }
            }
         }
         
   //***************************Spike Detector***************Spike Detector**********************************
      if((MathAbs(Close1-Open1)>((Width1*Spike_Define))) || (MathAbs(Close2-Open2)>((Width2*Spike_Define))) || 
         (MathAbs(Close3-Open3)>((Width3*Spike_Define))) || (MathAbs(Close4-Open4)>((Width4*Spike_Define))) || 
         (MathAbs(Close5-Open5)>((Width5*Spike_Define))))
         {
         Spike++;
         }
      if((MathAbs(Close1-Open1)>((WidthW1*Spike_Define))) || (MathAbs(Close2-Open2)>((WidthW2*Spike_Define))) ||
         (MathAbs(Close3-Open3)>((WidthW3*Spike_Define))) || (MathAbs(Close4-Open4)>((WidthW4*Spike_Define))) ||
         (MathAbs(Close5-Open5)>((WidthW5*Spike_Define))))
         {
         SpikeW++;
         }
   //***********************************************************************************************************
   
   //***************Ends Trend after Appropiate Time***
      if((Currency_momentumA>0) && (Average>Slow1) && (Trend=="sell"))
         {
         Trend="endtrend";
         }
     if((Currency_momentumA<0) && (Average<Slow1) && (Trend=="buy"))
         {
         Trend="endtrend";
         }
  
   //*******************************************************
   
      double FastTrend=iMA(NULL,PERIOD_H1,fastma,0,MODE_EMA,PRICE_CLOSE,1);
      double SlowTrend=iMA(NULL,PERIOD_H1,slowma,0,MODE_EMA,PRICE_CLOSE,1);
      if((MathAbs(FastTrend-SlowTrend)<RangePoint*Point))
            {
            Ranging++;
            }
            
   
   //************************Jump Detector**************Jump Detector***************************   
      if(((Open2>=Fast2) && (Close1<=Slow1)) || ((Open3>=Fast3) && (Close2<=Slow2)) || 
         ((Open4>=Fast4) && (Close3<=Slow3)) || ((Open5>=Fast5) && (Close4<=Slow4)) || 
         ((Open6>=Fast6) && (Close5<=Slow5)))
            {
            Selljump++;
            }
      if(((Open2<=Fast2) && (Close1>=Slow1)) || ((Open3<=Fast3) && (Close2>=Slow2)) || 
         ((Open4<=Fast4) && (Close3>=Slow3)) || ((Open5<=Fast5) && (Close4>=Slow4)) ||  
         ((Open6<=Fast6) && (Close5>=Slow5)))
            {
            Buyjump++;
            }
      
     
      if(((Open1>=Fast1) && (Close1<=Slow1)) || ((Open2>=Fast2) && (Close2<=Slow2)) || 
         ((Open3>=Fast3) && (Close3<=Slow3)) || ((Open4>=Fast4) && (Close4<=Slow4)) || 
         ((Open5>=Fast5) && (Close5<=Slow5)))
            {
            Selljump++;
            SelljumpR++;
            }
       if(((Open1<=Fast1) && (Close1>=Slow1)) || ((Open2<=Fast2) && (Close2>=Slow2)) || 
          ((Open3<=Fast3) && (Close3>=Slow3)) || ((Open4<=Fast4) && (Close4>=Slow4)) || 
          ((Open5<=Fast5) && (Close5>=Slow5)))
            {
            Buyjump++;
            BuyjumpR++;
            }
            
       if(((Open1<=Fast1) && (Open1>=(Fast1-(Width1*JumpWidth_Percen))) && (Close1<=Slow1)) || 
          ((Open3<=Fast2) && (Open2>=(Fast2-(Width2*JumpWidth_Percen))) && (Close2<=Slow2)) || 
          ((Open3<=Fast3) && (Open3>=(Fast3-(Width3*JumpWidth_Percen))) && (Close3<=Slow3)) || 
          ((Open4<=Fast4) && (Open4>=(Fast4-(Width4*JumpWidth_Percen))) && (Close4<=Slow4)) ||  
          ((Open5<=Fast5) && (Open6>=(Fast6-(Width5*JumpWidth_Percen))) && (Close5<=Slow5)))
            {
            Selljump++;
            }
       if(((Open1>=Fast1) && (Open1<=(Fast1+(Width1*JumpWidth_Percen))) && (Close1>=Slow1)) || 
          ((Open3>=Fast2) && (Open2<=(Fast2+(Width2*JumpWidth_Percen))) && (Close2>=Slow2)) || 
          ((Open3>=Fast3) && (Open3<=(Fast3+(Width3*JumpWidth_Percen))) && (Close3>=Slow3)) || 
          ((Open4>=Fast4) && (Open4<=(Fast4+(Width4*JumpWidth_Percen))) && (Close4>=Slow4)) ||  
          ((Open5>=Fast5) && (Open6<=(Fast6+(Width5*JumpWidth_Percen))) && (Close5>=Slow5)))
            {
            Buyjump++;
            }
            
    //*************************************************************************************************************
            
       
            
      
   //****************Open Trades********************************
      if((open<1) && (fastma<slowma) && (Ranging<1))
            {
         //************************Jump Trades*******************Jump Trades***********************************
            if((((Selljump>0) && (Ranging<1)) || ((SelljumpR>0) && (Ranging>0))) && (Spike<1) && (Fast1>Slow1)) 
                  {
                  if((Currency_momentumA<0) && ((Currency_momentumC>0) || 
                                                      ((Trend_momentumSlowA<Trend_momentumSlowB) && (Trend_momentumFastA<0))))
                        if((MathAbs(Slow1-Close1)<Width1*1.62) || (MathAbs(Slow1-Close1)<MaxpipfromEMA*Point)) 
                        
                              if((Currency_momentumA<Currency_momentumB) && (Trend_momentumFastA<Trend_momentumFastD))
                                    {
                                    Ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,10,0,0,0,1,0,Green);
                                    Trend="sell";
                                    PlaySound("alert.wav");
                                    return(0);
                                    }
                  }
            if((((Buyjump>0) && (Ranging<1)) || ((BuyjumpR>0) && (Ranging>0))) && (Spike<1) && (Fast1<Slow1)) 
                  {
                  if((Currency_momentumA>0) && ((Currency_momentumC<0) || 
                                                      ((Trend_momentumSlowA>Trend_momentumSlowB) && (Trend_momentumFastA>0))))
                        if((MathAbs(Slow1-Close1)<Width1*1.62) || (MathAbs(Slow1-Close1)<MaxpipfromEMA*Point)) 
                        
                              if((Currency_momentumA>Currency_momentumB) && (Trend_momentumFastA>Trend_momentumFastD))
                                    {
                                    Ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,10,0,0,0,1,0,Green);
                                    Trend="buy";
                                    PlaySound("alert.wav");
                                    return(0);
                                    }
                  }
    //*******************************Swing Trades*******************Swing Trades*****************************************              
            if((Trend=="sell") && (Ranging<1) && (Average<Fast1) && (Fast1<Slow1)) 
                  {
                  if((Trend_momentumFastA<0) && (Trend_momentumFastC>0)) 
               
                        if(((Currency_momentumA<Currency_momentumB) && (Currency_momentumA<0) && (Trend_momentumFastA<Trend_momentumFastD)) || 
                                    (Trend_momentumSlowA<Trend_momentumSlowB))
                              if(MathAbs(Fast1-Close1)<MaxpipfromEMA*Point)
                                    {
                                    Ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,10,0,0,0,1,0,Green);
                                    PlaySound("alert.wav");
                                    return(0);
                                    }
                  }
            if((Trend=="buy") && (Ranging<1) && (Average>Fast1) && (Fast1>Slow1)) 
                  {
                  if((Trend_momentumFastA>0) && (Trend_momentumFastC<0)) 
               
                        if(((Currency_momentumA>Currency_momentumB) && (Currency_momentumA>0) && (Trend_momentumFastA>Trend_momentumFastD)) || 
                                    (Trend_momentumSlowA>Trend_momentumSlowB))
                              if(MathAbs(Fast1-Close1)<MaxpipfromEMA*Point)
                                    {
                                    Ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,10,0,0,0,1,0,Green);
                                    PlaySound("alert.wav");
                                    return(0);
                                    }
                  }
    //*****************************Waterfall Trades**************************Waterfall Trades*********************************************    
            if((Width1<=2*Point) && (MathAbs(FastW-Slow1)>=(RangePoint*Point)))
                  { 
                  if((Currency_momentumA<0) && (Trend_momentumFastA<0) && (Trend_momentumSlowA<Trend_momentumSlowB))
              
                        if(MathAbs(Close1-Fast1)<MaxpipfromEMA*Point)
               
                              if(SpikeW<1) 
                                    {
                                    Ticket=OrderSend(Symbol(),OP_SELL,lot,Bid,10,0,0,0,1,0,Green);
                                    Trend="sell";
                                    PlaySound("alert.wav");
                                    return(0);
                                    }
                  }
            if((Width1<=2*Point) && (MathAbs(FastW-Slow1)>=(RangePoint*Point)))
                  { 
                  if((Currency_momentumA>0) && (Trend_momentumFastA>0) && (Trend_momentumSlowA>Trend_momentumSlowB))
              
                        if(MathAbs(Close1-Fast1)<MaxpipfromEMA*Point)
               
                              if(SpikeW<1) 
                                    {
                                    Ticket=OrderSend(Symbol(),OP_BUY,lot,Ask,10,0,0,0,1,0,Green);
                                    Trend="buy";
                                    PlaySound("alert.wav");
                                    return(0);
                                    }
                  }  
            }
   //*****************************************************************************************************************************   
 
  //**********************Closes Trades***********************Closes Trades*********************************************   
      for(Cnt=0;Cnt<total;Cnt++)
         {
         OrderSelect(Cnt, SELECT_BY_POS, MODE_TRADES);
            {
            if(OrderType()==OP_BUY) 
               {
                if((Currency_momentumA<0) && (Currency_momentumA<Currency_momentumB) && (Close1<Fast1) && 
                  (Trend_momentumFastA<Trend_momentumFastD) && (Spike<1)) 
                     {
                     OrderClose(OrderTicket(),OrderLots(),Bid,10,Blue);
                     PlaySound("alert.wav");
                     return(0);
                     }
                 }
              if(OrderType()==OP_SELL) 
                 {
                 if((Currency_momentumA>0) && (Currency_momentumA>Currency_momentumB) && (Close1>Fast1) && 
                    (Trend_momentumFastA>Trend_momentumFastD) && (Spike<1))
                     {
                     OrderClose(OrderTicket(),OrderLots(),Ask,10,Blue);
                     PlaySound("alert.wav");
                     return(0);
                     }
                  }
               }
            }
   //**********************************************************************************************************************************
      }
      