qq_v2.1_gbpusd_MM





// Because of my dismal stupidity not even named this EA 
#property copyright "RamilT" 
#property link "RamilT@bk.ru" 


//-----------------------------------Òèïà ïåðåìåííûå----------------------------------------------------------- 
extern int Magic = 2222;
extern int pr=12; 
extern int sl=30; 
extern int tp=100; 
extern int tz=50; 
extern int mm=1; 
extern int qq=10; 
extern int chas1=5; 
extern int chas2=17; 
extern double Lots=1;
extern double TrailingStop = 0;

double BuyStop=0, PrevBuyStop=0, SellStop=0, PrevSellStop=0;
double Slippage =3, TakeProfit=0, StopLoss =0; 
//------------------------------------------------------------------------------------------------------------- 


int start() 
{ 
   if(Hour()<=chas1||Hour()>=chas2)return(0); 
   if(Bars<100) 
   { 
   Print("bars less than 100"); 
   return(0); 
   } 
//-----------------------------------Ìîíýé ìåíäæìåíò----------------------------------------------------------- 
   
   if (ScanTrades()>0 ) HideTrailStop();
   
   if (mm==1) 
   { 
   if(Lots<(MathCeil((AccountFreeMargin()/1000)*qq)/10)){Lots=(MathCeil((AccountFreeMargin()/10000)*qq)/10);if(Lots>100){Lots=100;}} 
   } 
//------------------------------------------------------------------------------------------------------------- 


//----------------------------------Ãëàâíûé àëãîðèòì----------------------------------------------------------- 
   if(ScanTrades()<1)
   { 
      if (((iOpen(NULL,5,1)-iClose(NULL,5,pr))>(Point*tz))&&(Ask>iOpen(NULL,5,1))) 
      { 
      if( tp>0 ) TakeProfit = Ask+tp*Point; else TakeProfit = 0;
      if( sl>0 ) StopLoss =  Ask-sl*Point;  else StopLoss = 0;
      OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"qq-buy60",Magic,0,Blue); 
      BuyStop=0; PrevBuyStop=StopLoss;
      } 


      if (((iOpen(NULL,5,1)-iClose(NULL,5,pr))<(-Point*tz))&&(Bid<iOpen(NULL,5,1))) 
      { 
      if( tp>0 ) TakeProfit = Bid-tp*Point; else TakeProfit = 0;
      if( sl>0 ) StopLoss =  Bid+sl*Point;  else StopLoss = 0;
      OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,0,"qq-sell60",Magic,0,Red); 
      SellStop=0; PrevSellStop=StopLoss;
  
      } 
   } 
   
   

} 
//------------------------------------------------------------------------------------------------------------- 


 

int ScanTrades()
{   
   int total = OrdersTotal();
   int numords = 0;
      
   for(int cnt=0; cnt<total; cnt++) 
   {        
   OrderSelect(cnt, SELECT_BY_POS);            
   if(OrderSymbol() == Symbol() && OrderType()<=OP_SELLSTOP && OrderMagicNumber() == Magic) 
   numords++;
   }
   return(numords);
}  


void HideTrailStop()
{
   for (int cnt=0;cnt<OrdersTotal();cnt++)
   { 
   OrderSelect(cnt, SELECT_BY_POS);   
   int mode=OrderType();    
      if ( OrderSymbol()==Symbol() && OrderMagicNumber()==Magic) 
      {
         if (mode==OP_BUY) 
         {
			   if ( TrailingStop >0 )
			   {
			   BuyStop = Bid - TrailingStop*Point;
			   if (BuyStop < PrevBuyStop ) BuyStop = PrevBuyStop;       
               if( OrderOpenPrice() <= BuyStop ) 
               {   
			         if ( Bid <= BuyStop || (Bid >= TakeProfit && TakeProfit>0) || Bid <= StopLoss)
			         {
			         OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Yellow);
			         return(0);
			         }
               }            
            }
            else
            if ( (Bid >= TakeProfit && TakeProfit>0) || Bid <= StopLoss)
			   {
			   Print("BUY: TP = ",TakeProfit," SL=", StopLoss);
			   OrderClose(OrderTicket(),OrderLots(),Bid,Slippage,Yellow);
			   return(0);
			   }
         }   
// - SELL Orders          
         if (mode==OP_SELL)
         {
            Print("SEll: TP = ",TakeProfit," SL=", StopLoss," Ask=", Ask);
            if ( TrailingStop >0 )
			   {
            SellStop = Ask + Point * TrailingStop;   
            if (SellStop > PrevSellStop && PrevSellStop > 0) SellStop = PrevSellStop; 
         
               if( OrderOpenPrice() >= SellStop) 
               {
                  if ( Ask >= SellStop || Ask <= TakeProfit || ( Ask >= StopLoss && StopLoss > 0))
                  {
                  OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,White);
                  return(0);
                  }
   			   }	    
            }
            else
               if ( Ask <= TakeProfit || ( Ask >= StopLoss && StopLoss > 0))
               {
               Print("SEll: TP = ",TakeProfit," SL=", StopLoss);
               OrderClose(OrderTicket(),OrderLots(),Ask,Slippage,White);
               return(0);
               }
            }   
         }
      }     
   PrevBuyStop  = BuyStop;
   PrevSellStop = SellStop;
}



Sample





Analysis



Market Information Used:

Series array that contains open prices of each bar
Series array that contains close prices for each bar


Indicator Curves created:


Indicators Used:



Custom Indicators Used:

Order Management characteristics:
It automatically opens orders when conditions are reached
Checks for the total of open orders
It Closes Orders by itself

Other Features: