Navigation:Home > Content >

ROBOT.mq4

Time: 2012-08-27 | Download file:ROBOT.mq4

//+------------------------------------------------------------------+
//|                                                          aaa.mq4 |
//|                      Copyright © 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//|                                                                  |
//| Modifiй par un6oitil (installation perceptron + SL + TP)         |                  
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 20012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
extern double StopLoss                 =0;
extern double TakeProfit               =0;
extern double step                     =25;
extern int    StepMode                 =0;
// Если StepMode = 0, то шаг между ордерами фиксированный и равен step
// Если StepMode = 1, то шаг постепенно увеличивается
extern double proffactor               =10;
extern double mult                     =1.5;
extern double lotsbuy                  =0.01;
extern double lotssell                 =0.01;
extern double per_K                    =200;
extern double per_D                    =20;
extern double slow                     =20;
extern double zoneBUY                  =50;
extern double zoneSELL                 =50;
extern double Magicbuy                 =555;
extern double Magicsell                =556;
extern string   Parameters              = "StochasticPerceptron";
extern string   Parameters_Stochastic   = "Stochastic";
extern int       Kperiod               = 5;
extern int       Dperiod               = 3;
extern int       slowing               = 3;
extern string   Parameters_Perceptron="Perceptron";
extern int       shag                  = 0;
extern int       x1                    = 0;
extern int       x2                    = 0;
extern int       x3                    = 0;
extern int       x4                    = 0;

// Internal settings
double  sl = 0;
double  tp = 0;
double openpricebuy,openpricesell,lotsbuy2,lotssell2,lastlotbuy,lastlotsell,tpb,tps,cnt,smbuy,smsell,lotstep,
ticketbuy,ticketsell,maxLot,free,balance,lotsell,lotbuy,dig,sig_buy,sig_sell,ask,bid;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OrdersTotalMagicbuy(int Magicbuy)
  {
   int j=0;
   int r;
   for(r=0;r=0; cnt--)
     {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==symbol && OrderMagicNumber()==Magicbuy)
        {
         ticketbuy=OrderTicket();OrderSelect(ticketbuy,SELECT_BY_TICKET,MODE_TRADES);lotsbuy2=OrderLots();
         double bid=MarketInfo(symbol,MODE_BID);
         RefreshRates();
         OrderClose(ticketbuy,lotsbuy2,bid,3,Magenta);
        }
     }
   lotsbuy2=lotsbuy;return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int orderclosesell(int ticketsell)
  {
   string symbol=Symbol();
   int cnt;
   for(cnt=OrdersTotal(); cnt>=0; cnt--)
     {
      OrderSelect(cnt,SELECT_BY_POS,MODE_TRADES);
      if(OrderSymbol()==symbol && OrderMagicNumber()==Magicsell)
        {
         ticketsell=OrderTicket();OrderSelect(ticketsell,SELECT_BY_TICKET,MODE_TRADES);lotssell2=OrderLots();
         double ask= MarketInfo(symbol,MODE_ASK);
         RefreshRates();
         OrderClose(ticketsell,lotssell2,ask,3,Lime);
        }
     }
   lotssell2=lotssell;return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
//----
   double profitbuy=0;double profitsell=0;
   string symbol = OrderSymbol();
   double spread = MarketInfo(symbol,MODE_SPREAD);
   double minLot = MarketInfo(symbol,MODE_MINLOT);
   if(minLot==0.01){dig=2;maxLot=MarketInfo(symbol,MODE_MAXLOT);}
   if(minLot==0.1){dig=1;maxLot=((AccountBalance()/2)/1000);}
   if(OrdersTotalMagicbuy(Magicbuy)>0)
     {
      double smbuy;
      for(cnt=0;cnt0)
     {
      double smsell;
      for(cnt=0;cnt=openpricesell+step*Point)
                 {
                  lotssell2=lastlotsell*mult;
                  if(StopLoss==0) sl=0; else sl=Bid+(StopLoss*Point);
                  if(TakeProfit==0) tp=0; else tp=Bid -(TakeProfit*Point);
                  RefreshRates();ticketsell=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lotssell2,dig),Bid,3,sl,tp,"Robot",Magicsell,0,Red);
                 }
              }
            if(StepMode==1)
              {
               if(Bid>=openpricesell+(step+OrdersTotalMagicsell(Magicsell)+OrdersTotalMagicsell(Magicsell)-2)*Point)
                 {
                  lotssell2=lastlotsell*mult;
                  if(StopLoss==0) sl=0; else sl=Bid+(StopLoss*Point);
                  if(TakeProfit==0) tp=0; else tp=Bid -(TakeProfit*Point);
                  RefreshRates();ticketsell=OrderSend(Symbol(),OP_SELL,NormalizeDouble(lotssell2,dig),Bid,3,sl,tp,"Robot",Magicsell,0,Red);
                 }
              }
           }
        }
     }
   if(OrdersTotalMagicbuy(Magicbuy)<1)
     {
      if(StopLoss==0) sl=0; else sl=Ask -(StopLoss*Point);
      if(TakeProfit==0) tp=0; else tp=Ask+(TakeProfit*Point);
      if(iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,0,1)>iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,1,1)
         && iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,1,1)>zoneBUY && perceptron()>0)
         ticketbuy=OrderSend(Symbol(),OP_BUY,lotsbuy,Ask,3,sl,tp,"Robot",Magicbuy,0,Blue);
     }
   if(OrdersTotalMagicsell(Magicsell)<1)
     {
      if(StopLoss==0) sl=0; else sl=Bid+(StopLoss*Point);
      if(TakeProfit==0) tp=0; else tp=Bid -(TakeProfit*Point);
      if(iStochastic(NULL,0,per_K,per_D,slow,MODE_LWMA,1,0,1)0)
     {
      if(Bid>=tpb) orderclosebuy(ticketbuy);
     }
   for(cnt=0;cnt0)
     {
      if(Ask<=tps)orderclosesell(ticketsell);
     }
   free=AccountFreeMargin();balance=AccountBalance();
   for(cnt=0;cnt        

Recommend