Navigation:Home > Content >

A_X4.mq4

Time: 2014-09-22 | Download file:A_X4.mq4

#include 
#include 
extern bool  STR1 = true;
extern bool  STR2 = true;
extern double  TP       =  0;
extern double  SL       =  30;  //начальный стоплосс 
extern double  TrSt         =  15; //Трал
extern double  VirtSL       =  0; //Трал
extern double  TrStep       =1;
extern double MinProfit     =10;//мин. профит модификации стоплоса
extern int Volumes          =50;
extern int Volumes2          =180;
extern int FractalPoint     =150;
extern int Expiration       = 33;
extern int Expiration2       = 5;
extern int Dist = 15;//дистанция выставления ордера
extern int DistModif =0;
extern int NormalizeLot =2;//нормализация порядка знаков после зпт. в значении лота 1 - 0.1 ....2 - 0.01
extern bool  modif = true;
extern bool  Bar0 = true;
extern bool  Bar1 = false;
extern bool  ReversFractal = false;
extern bool  ProfitFaktor = false;//разрешение след ордера при пробое спреда в профит предыдущим
extern bool  ProfitFaktor2 = false;//разрешение след ордера при пробое спреда в профит предыдущим
extern bool  FaktorBU = false;//разрешение след ордера при безубытке предыдущего
extern bool  FaktorBU2 = false;//разрешение след ордера при безубытке предыдущего
extern double Lot = 0.01;
extern bool  LotOptimized = false;//включение лототрона в доле от свободных средств
extern double Risk = 0.2;//размер доли свободных средств
extern double MaxLot = 30;
extern int    max_spread =15;//макс. значение разрешённого спреда в пип
extern bool  Sound = true; 


extern int Magic = 77;
extern string com = "V1";//2символа
extern string com2 = "V1";//2символа
//int            cnt,i;
double         lots=0,p;
double ask=0,bid=0;
int ptrend=0;

double ts1 =0;
double tb1 =0;
double ts2 =0;
double tb2 =0;

double TK=0;
double TK2=0;
double TK3=0;

int init()
{
   

   return(0);
}

int deinit()
{
ObjectDelete("U");
ObjectDelete("U1");
   return(0);
}



int start()
{   
int bo=0,so=0,cb=0,cs=0,no=0,zb=0,zs=0,zb2=0,zs2=0,sell=0,buy=0,db=0,ds=0,tiket=0;
double sl=0,tp =0;
double tik = (Ask+Bid)/2;
if(DayOfWeek()==0|| DayOfWeek()==6)return(0);

if(ObjectFind("s2")!=-1&&ObjectGet("s2",1)Ask+Dist*Point)ObjectSet("b2",1,Ask+Dist*Point); 

if(ObjectFind("s1")!=-1&&ObjectGet("s1",1)Ask+Dist*Point)ObjectSet("b1",1,Ask+Dist*Point); 
  
   int kp=0,kl=0,dob=0,dos=0;
   double pr,l;
   if(!IsTesting() )
   {  
   for(int e=OrdersHistoryTotal();e>=0;e--)
   {
   if(OrderSelect(e,SELECT_BY_POS,MODE_HISTORY))
   {
   if(OrderSymbol()==Symbol()&&OrderMagicNumber()==Magic)
   {
   if(OrderCloseTime()>0)
   {
   
   if(OrderProfit()>0){pr+=OrderProfit()+OrderCommission();kp++;}
   if(OrderProfit()<0){l+=OrderProfit()+OrderCommission();kl++;}
   }}}}   
   }
   for (int q = OrdersTotal(); q >=0; q--)   
   {
      OrderSelect(q, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol()&&OrderMagicNumber()==Magic)
      {
       
       if(OrderType()==OP_BUYSTOP&&StringSubstr(OrderComment(),0,2)==com)zb=1;
       if(OrderType()==OP_SELLSTOP&&StringSubstr(OrderComment(),0,2)==com)zs=1;  
       if(OrderType()==OP_BUY&&StringSubstr(OrderComment(),0,2)==com&&(OrderStopLoss()0||ProfitFaktor==false))zb=1;
       if(OrderType()==OP_SELL&&StringSubstr(OrderComment(),0,2)==com&&(OrderStopLoss()>OrderOpenPrice()||FaktorBU==false)&&(OrderProfit()>0||ProfitFaktor==false))zs=1;  
       
       if(OrderType()==OP_BUYSTOP&&StringSubstr(OrderComment(),0,2)==com2)zb2=1;
       if(OrderType()==OP_SELLSTOP&&StringSubstr(OrderComment(),0,2)==com2)zs2=1;  
       if(OrderType()==OP_BUY&&StringSubstr(OrderComment(),0,2)==com2&&(OrderStopLoss()0||ProfitFaktor2==false))zb2=1;
       if(OrderType()==OP_SELL&&StringSubstr(OrderComment(),0,2)==com2&&(OrderStopLoss()>OrderOpenPrice()||FaktorBU2==false)&&(OrderProfit()>0||ProfitFaktor2==false))zs2=1; 
       
       if(OrderType()==OP_BUY&&OrderStopLoss()>OrderOpenPrice())cs=1;
       if(OrderType()==OP_SELL&&OrderStopLoss()Dist*Point+DistModif*Point&&StringSubstr(OrderComment(),0,2)!="dop")OrderModify(OrderTicket(),Ask+Dist*Point,0,0,0,CLR_NONE);
       if(modif ==true&&OrderType()==OP_SELLSTOP&&Bid-OrderOpenPrice()>Dist*Point+DistModif*Point&&StringSubstr(OrderComment(),0,2)!="dop")OrderModify(OrderTicket(),Bid-Dist*Point,0,0,0,CLR_NONE);
       if(OrderType()==OP_SELLSTOP||OrderType()==OP_BUYSTOP&&TimeCurrent()-OrderOpenTime()>Expiration&&StringSubstr(OrderComment(),0,2)==com)OrderDelete(OrderTicket());             
       if(OrderType()==OP_SELLSTOP||OrderType()==OP_BUYSTOP&&TimeCurrent()-OrderOpenTime()>Expiration2&&StringSubstr(OrderComment(),0,2)==com2)OrderDelete(OrderTicket());
       if(OrderType()==OP_SELLLIMIT||OrderType()==OP_BUYLIMIT&&TimeCurrent()-OrderOpenTime()>Expiration&&StringSubstr(OrderComment(),0,2)==com)OrderDelete(OrderTicket());             
       if(OrderType()==OP_SELLLIMIT||OrderType()==OP_BUYLIMIT&&TimeCurrent()-OrderOpenTime()>Expiration2&&StringSubstr(OrderComment(),0,2)==com2)OrderDelete(OrderTicket());  
       if(OrderType()==OP_BUY||OrderType()==OP_BUYSTOP)bo++;
       if(OrderType()==OP_SELL||OrderType()==OP_SELLSTOP)so++;

       
      }
   }
//----
if(tb2>0&&TimeCurrent()-tb2>Expiration2)ObjectDelete("b2");
if(ts2>0&&TimeCurrent()-ts2>Expiration2)ObjectDelete("s2");
if(tb1>0&&TimeCurrent()-tb1>Expiration)ObjectDelete("b1");
if(ts1>0&&TimeCurrent()-ts1>Expiration)ObjectDelete("s1");
//if(cs==1){ObjectDelete("s2");ObjectDelete("s1");}
//if(cb==1){ObjectDelete("b2");ObjectDelete("b1");}
lots=NormalizeDouble(GetLotSize(),NormalizeLot);
if(lots>MaxLot)lots=MaxLot;
if(lots0&&ObjectFind("b2")!=-1&&ask=ObjectGet("b2",1))
 {
 tiket=OrderSend(Symbol(),OP_BUY,lots,Ask,0,0,0,com2, Magic, 0, Green);
 ObjectDelete("b2");
 tb2=0;
 if (Sound&&tiket>0)PlaySound("stops.wav" ); 
 }     
 if(zs2==0&&bid>0&&ObjectFind("s2")!=-1&&bid>ObjectGet("s2",1)&&Bid<=ObjectGet("s2",1))
 {
 tiket=OrderSend(Symbol(),OP_SELL,lots,Bid,0,0,0,com2, Magic, 0, Red);
 ObjectDelete("s2");
 ts2=0;
 if (Sound&&tiket>0)PlaySound("stops.wav" ); 
 }     
 
 if(zb==0&&ask>0&&ObjectFind("b1")!=-1&&ask=ObjectGet("b1",1))
 {
 tiket=OrderSend(Symbol(),OP_BUY,lots,Ask,0,0,0,com, Magic, 0, Green);
 ObjectDelete("b1");
 tb1=0;
 if (Sound&&tiket>0)PlaySound("stops.wav" ); 
 }     
 if(zs==0&&bid>0&&ObjectFind("s1")!=-1&&bid>ObjectGet("s1",1)&&Bid<=ObjectGet("s1",1))
 {
 tiket=OrderSend(Symbol(),OP_SELL,lots,Bid,0,0,0,com, Magic, 0, Red);
 ObjectDelete("s1");
 ts1=0;
 if (Sound&&tiket>0)PlaySound("stops.wav" ); 
 }
        

        
        if(STR1&&Volume[1]>Volumes)
        {  
            if(ObjectFind("s1")==-1&&((Close[1]>Open[1]&&Bar1==true)||(Close[0]>Open[0]&&Bar0==true))&&((Close[0]>u()+FractalPoint*Point&&Close[0]>d()&&ReversFractal==false)||(Close[0]>u()&&Close[0]>d()+FractalPoint*Point&&ReversFractal==true)))
            {ObjectCreate("s1",1,0,0,Bid-Dist*Point);ObjectSet("s1",6,Yellow);ts1=TimeCurrent();}//tiket=OrderSend(Symbol(),OP_SELLSTOP,lots,Bid-Dist*Point,0,0,0 ,com,Magic,0,Orange);
            if(ObjectFind("b1")==-1&&((Close[1]Open[1]+20*Point)&&Volume[1]>Volumes2)//
        {        
            if(Close[0]Open[0]&&ObjectFind("s2")==-1){ObjectCreate("s2",1,0,0,Bid-Dist*Point);ObjectSet("s2",6,Yellow);ts2=TimeCurrent();}//tiket=OrderSend(Symbol(),OP_SELLSTOP,lots,Bid-Dist*Point,0,0,0 ,com2,Magic,0,Orange);
            if(Close[0]>iOpen(Symbol(),5,0)&&Close[0]=0; n--)   
   {
      OrderSelect(n, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol()&&OrderMagicNumber()==Magic)
      {
       if(OrderType()==OP_BUYSTOP&&cb==1)OrderDelete(OrderTicket());
       if(OrderType()==OP_SELLSTOP&&cs==1)OrderDelete(OrderTicket());

      }
    } 
     
      if(SL==0)SL=20000;
      for (int m = OrdersTotal(); m >=0; m--)   
      {
      OrderSelect(m, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol()&&OrderMagicNumber()==Magic)
      {    

      
      if (OrderType() == OP_BUY)
      {
         if(VirtSL>0&&Ask<=OrderOpenPrice()-VirtSL*Point)OrderClose(OrderTicket(),OrderLots(),Bid,0,CLR_NONE);
         if(SL>0&&OrderStopLoss()==0)
         {
           OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Bid - SL*Point,Digits),OrderTakeProfit(), 0, CLR_NONE);
         }
         if(TP>0&&OrderTakeProfit()==0)
         {
            OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Ask+TP*Point, 0, CLR_NONE);
         }
         if (TrSt>0)
         {
            if (OrderStopLoss()=OrderOpenPrice()+MinProfit*Point&&Bid - TrSt*Point>=OrderStopLoss()+TrStep*Point)
            {
              OrderModify(OrderTicket(),OrderOpenPrice(),Bid - TrSt*Point,OrderTakeProfit(), 0, CLR_NONE);
            }
         }        
      }
      if (OrderType() == OP_SELL)
      {   
         if(VirtSL>0&&Bid>=OrderOpenPrice()+VirtSL*Point)OrderClose(OrderTicket(),OrderLots(),Ask,0,CLR_NONE);
         if(SL>0&&OrderStopLoss()==0)
         {
           OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(Ask + SL*Point,Digits),OrderTakeProfit(), 0, CLR_NONE);
         }  
         if(TP>0&&OrderTakeProfit()==0)
         {
            OrderModify(OrderTicket(),OrderOpenPrice(),OrderStopLoss(),Bid-TP*Point, 0, CLR_NONE);
         }   
         if (TrSt>0)
         {
           if (OrderStopLoss() > Ask +(TrSt)*Point&&Ask + TrSt*Point<=OrderOpenPrice()-MinProfit*Point&&Ask + TrSt*Point<=OrderStopLoss()-TrStep*Point) 
           {
              OrderModify(OrderTicket(),OrderOpenPrice(),Ask + TrSt*Point,OrderTakeProfit(), 0, CLR_NONE);
           }
         }            
      }
   }
   }
     
    ObjectCreate("U1", OBJ_LABEL, 0, 0, 0, 0, 0);
    ObjectSet("U1", OBJPROP_CORNER, 2);
    ObjectSet("U1", OBJPROP_YDISTANCE, 45);
    ObjectSet("U1", OBJPROP_XDISTANCE, 10);
    color col = Yellow;
    if(pr+l>0)col=Lime;
    if(pr+l<0)col=Red; 
    ObjectSetText("U1", "Profit " + DoubleToStr(kp,0)+"/"+DoubleToStr(pr,2)+"  Loss " + DoubleToStr(kl,0)+"/"+DoubleToStr(l,2)+"  All " + DoubleToStr(kp+kl,0)+"/" +DoubleToStr(pr+l,2),12, "Tahoma",col ); 
    
    ObjectCreate("U", OBJ_LABEL, 0, 0, 0, 0, 0);
    ObjectSet("U", OBJPROP_CORNER, 2);
    ObjectSet("U", OBJPROP_YDISTANCE, 65);
    ObjectSet("U", OBJPROP_XDISTANCE, 10);
    color col2 = Yellow;
    if((Ask-Bid)/Pointmax_spread)col2=Red;
    ObjectSetText("U", "Spread " + DoubleToStr((Ask-Bid)/Point,0)+"  Magic "+ DoubleToStr(Magic,0)+"  V "+ DoubleToStr(Volume[1],0),12, "Tahoma",col2 ); 
   //ptrend=trend;
   ask = Ask;
   bid = Bid;
   TK=(Ask+Bid)/2;  
   return(0);
}
double GetLotSize()
{
if(LotOptimized == TRUE){
double Loty;
//........................................................................
        int m;
        double MG;
        if(Lot>0)
        {
        if(AccountFreeMargin()>AccountMargin())MG=AccountFreeMargin();       
        double Min_Lot = MarketInfo(Symbol(), MODE_LOTSTEP);             
        if(Risk>0)
        {
          m=MG/MarketInfo (Symbol(), MODE_MARGINREQUIRED)*Risk/Min_Lot;
          Loty = m*Min_Lot;
        if(Loty < MarketInfo(Symbol(), MODE_MINLOT))
        Loty =MarketInfo(Symbol(), MODE_MINLOT);            
        if(Loty > MarketInfo (Symbol(), MODE_MAXLOT))
        Loty = MarketInfo (Symbol(), MODE_MAXLOT);                  
        }
        }
        if(Risk==0)Loty= Lot;

//......................................................................................, 
}
else
{
Loty=Lot;
}
   return (Loty);
}


//----------------Fractals-----------------
double u()
 {
  
  double f;
  int    i, k=iBars(Symbol(), 1), ke=0;

  for (i=-1; i0) return(f);
    }
  }
  return(0);
}

double d()
 {
  
  double f;
  int    i, k=iBars(Symbol(), 1), ke=0;

  for (i=-1; i0) return(f);
    }
  }
  return(0);
}

Recommend