Navigation:Home > Content >

AdaptTS.mq4

Time: 2011-01-19 | Download file:AdaptTS.mq4

//+------------------------------------------------------------------+
//|                                                      AdaptTS.mq4 |
//|                                 Copyright © 2006, Andrew Suvorov |
//|                                                    [email protected] |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2006, Andrew Suvorov"
#property link      "[email protected]"

extern int     Lots=1;
extern int     Timer=600; //inteval between the modifications
extern int     PerTS=10;  //period ATR for calculation TS/SL
extern double	Kts=7.5;   //ATR for calculating the level TS/SL	
extern int     risk=13;   //% risk from available capital
extern int     MiniForex=1;
extern int     Slippage=5;

int PrBuy=0;

datetime LastTradeTime=0;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  int i,DolPunkt;
  double HD,LD,lotsi,StopLos;
//----

if(OrdersTotal()>0) OrderSelect(0,SELECT_BY_POS,MODE_TRADES);
if(OrdersTotal()>0 && OrderType()==OP_BUY)  PrBuy=1;
if(OrdersTotal()>0 && OrderType()==OP_SELL) PrBuy=0;

HD=0;	LD=0; 
 for(i=1;i<=PerTS;i++) //StopLoss & TralingStop
 {
   HD+=High[i-1];
	LD+=Low[i-1];
 }
 
StopLos=Kts*MathSqrt((HD-LD)/PerTS/Point)*Point;

if(Symbol()=="EURUSD") DolPunkt = 10;
else if(Symbol()=="GBPUSD") DolPunkt = 7;
     else return(0);

if(CurTime()>LastTradeTime+10)
{
  if(OrdersTotal()<1)
  {   
 
	if(risk!=0) lotsi=NormalizeDouble(AccountBalance()*risk/100/DolPunkt/StopLos*Point,1);
 	else lotsi=Lots;
           
 	if(lotsi > 10) lotsi=MathFloor(lotsi);
 	if(lotsi < 0.1 && MiniForex!=0) lotsi=0.1;
 	if(lotsi < 1 && MiniForex==0) lotsi=1;
 	Comment("lotsi - ",lotsi,"\n","\n","lotsi - ",lotsi,"\n","\n","Buy - ",PrBuy);
   
  	if(PrBuy==0)
	 { //SetOrder(OP_BUY,lotsi,bid,Slippage,bid-StopLos,0,Lime);
      OrderSend(Symbol(),OP_BUY,lotsi,Bid,Slippage,Bid-StopLos,0,"Покупаем",16384,0,Lime);
      LastTradeTime=CurTime();
		 					
 	 }
 	 if(PrBuy==1)
	 { //SetOrder(OP_SELL,lotsi,ask,Slippage,ask+StopLos,0,Blue);
      OrderSend(Symbol(),OP_SELL,lotsi,Ask,Slippage,Ask+StopLos,0,"Продаем",16384,0,Blue);      
      LastTradeTime=CurTime();
      return(0);		
 	 }
  }	 
}

 	
if(OrdersTotal()<1 || (CurTime()-LastTradeTime)Ask+StopLos+10*Point || OrderStopLoss()==0)
        {
           // ModifyOrder(Ord(1,VAL_TICKET),Ord(1,VAL_OPENPRICE),Ask+STOPLOS,0,Yellow);
           OrderModify(OrderTicket(),OrderOpenPrice(),Ask+StopLos,0,Yellow);
           return(0);             
        }
  	}


   
//----
   return(0);
  }
//+------------------------------------------------------------------+

Recommend