← Назад к списку файлов

ichimoku_ea_v1.1.mq4

Поиск по коду файла

extern bool TradeTKCross = True;
extern bool TradeKCross = True;
extern bool TradeBreakout = True;
extern string BreakoutTFs = "1=Day, 2=Week, 3=Monthly";
extern int BreakoutTF = 1;
extern bool TradeSenkouSCross = True;
extern string SenkouSCrossTFs = "1=Day, 2=Week, 3=Monthly";
extern int SenkouSCrossTF = 1;
extern bool TradeChikouSCross = True;
extern string StopString1 = "BE, SL, TSL & TP Valid";
extern string StopString2 = "Only On TK & Chikou";
extern int BEPips=0;       // Pips In profit after which EA will Move SL to BE+1
extern int TrailingStop=0; // Trailing Stop
extern int TakeProfit=0;
extern int StopLoss=0;
extern bool mm=false;       //Money Management?
extern int RiskPercent=2;  
extern double Lots=0.01;
extern double MinimumLot=0.01;
extern double DollarsPerLot = 10000;
extern string TradeLog = " MI_Log";

int Total, Magic;    
double Spread, Entry, TP, SL, high, low, highopen, lowopen, highstopopen, lowstopopen, hightakeprofit, lowtakeprofit, lot;
string filename, TradeComment;
double IchTenkan, IchKijun, IchSenA, IchSenB, IchChin;
double IchSenA1, IchSenB1, IchSenA2, IchSenB2, IchSenA3, IchSenB3;
double IchSenPrice1, IchSenPrice2;

int init()
  {
      // код доступен только после оплаты
   }

int deinit()
  {

    Print("Done Testing");
    ObjectsDeleteAll();

   return(0);
  }

/*double LotsOptimized()
  {
   double lot=Lots;

   if (mm) lot=NormalizeDouble(MathFloor(AccountFreeMargin()*RiskPercent/100)/100,1);

   return(lot);
  }*/
double LotsOptimized(double InputLots)
   { 
      lot=Lots;
      if (mm) 
      {
         lot = MathRound(InputLots/MinimumLot)*MinimumLot;
         if(lot<MinimumLot) lot = MinimumLot;
      }
      return(lot);
}   

int CheckOrdersCondition()
  {
    int result=0;
    for (int i=0;i<OrdersTotal();i++) 
    {
      OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
      if ((OrderType()==OP_BUY) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic)) 
      {
        result=result+1000; 
      }
      if ((OrderType()==OP_SELL) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic)) 
      {
        result=result+100; 
      }
      if ((OrderType()==OP_BUYSTOP) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic)) 
      {
        result=result+10;
      }
      if ((OrderType()==OP_SELLSTOP) && (OrderSymbol() == Symbol()) && (OrderMagicNumber() == Magic)) 
      {
        result=result+1; 
      }

    }
    return(result); // 0 means we have no trades
  }  

void OpenBuy()
 {
    int ticket,err,tries;
        tries = 0;
          while (tries < 3)
          {
               ticket = OrderSend(Symbol(),OP_BUY,LotsOptimized(AccountBalance()/DollarsPerLot),Ask,3,SL,TP,TradeComment,Magic,0,Red);
               if(ticket>0)
                 {
                  if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());
                  tries=3;
                 }
               else 
               {
                  Print("Error opening BUY order : ",GetLastError()+" Buy @ "+Ask+" SL @ "+SL+" TP @"+TP); 
                  Print("Lots:",Lots,", TP:",TP,", SL:",SL);
                  tries++;
               }  
          }
 }

void OpenSell()
 {
    int ticket,err,tries;
        tries = 0;
          while (tries < 3)
          {
               ticket = OrderSend(Symbol(),OP_SELL,LotsOptimized(AccountBalance()/DollarsPerLot),Bid,3,SL,TP,TradeComment,Magic,0,Red);
               if(ticket>0)
                 {
                  if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
                  tries=3;
                 }
               else 
               {
                  Print("Error opening SELL order : ",GetLastError()+" Sell @ "+Bid+" SL @ "+SL+" TP @"+TP); 
                  Print("Lots:",Lots,", TP:",TP,", SL:",SL);
                  tries++;
               }  
          }
 }

void OpenBuyStop()
 {
    int ticket,err,tries;
        tries = 0;
          while (tries < 3)
          {
               ticket = OrderSend(Symbol(),OP_BUYSTOP,LotsOptimized(AccountBalance()/DollarsPerLot),Entry,3,SL,TP,TradeComment,Magic,0,Red);
               if(ticket>0)
                 {
                  if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUYSTOP order opened : ",OrderOpenPrice());
                  tries=3;
                 }
               else 
               {
                  Print("Error opening BUYSTOP order : ",GetLastError()+" BuyStop @ "+Entry+" SL @ "+SL+" TP @"+TP); 
                  Print("Lots:",Lots,", TP:",TP,", SL:",SL);
                  tries++;
               }  
          }
 }

void OpenSellStop()
 {
    int ticket,err,tries;
        tries = 0;
          while (tries < 3)
          {
               ticket = OrderSend(Symbol(),OP_SELLSTOP,LotsOptimized(AccountBalance()/DollarsPerLot),Entry,3,SL,TP,TradeComment,Magic,0,Red);
               if(ticket>0)
                 {
                  if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELLSTOP order opened : ",OrderOpenPrice());
                  tries=3;
                 }
               else 
               {
                  Print("Error opening SELLSTOP order : ",GetLastError()+" SellStop @ "+Entry+" SL @ "+SL+" TP @"+TP); 
                  Print("Lots:",Lots,", TP:",TP,", SL:",SL);
                  tries++;
               }  
          }
 }

void DoBE(int byPips)
  {
    for (int i = 0; i < OrdersTotal(); i++) {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if ( OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic))  // only look if mygrid and symbol...
        {
            if (OrderType() == OP_BUY) if (Bid - OrderOpenPrice() > byPips * Point) if (OrderStopLoss() < OrderOpenPrice()) {
              Write("Moving StopLoss of Buy Order to BE+1");
              OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() +  Point, OrderTakeProfit(), Red);
            }
            if (OrderType() == OP_SELL) if (OrderOpenPrice() - Ask > byPips * Point) if (OrderStopLoss() > OrderOpenPrice()) { 
               Write("Moving StopLoss of Buy Order to BE+1");
               OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() -  Point, OrderTakeProfit(), Red);
            }
        }
    }
  }

void DoTrail()
  {
    for (int i = 0; i < OrdersTotal(); i++) {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if ( OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic))  // only look if mygrid and symbol...
        {

          if (OrderType() == OP_BUY) {
             if(Bid-OrderOpenPrice()>Point*TrailingStop)
             {
                if(OrderStopLoss()<Bid-Point*TrailingStop)
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-Point*TrailingStop,OrderTakeProfit(),0,Green);
                     return(0);
                  }
             }
          }

          if (OrderType() == OP_SELL) 
          {
             if((OrderOpenPrice()-Ask)>(Point*TrailingStop))
             {
                if((OrderStopLoss()>(Ask+Point*TrailingStop)) || (OrderStopLoss()==0))
                {
                   OrderModify(OrderTicket(),OrderOpenPrice(),Ask+Point*TrailingStop,OrderTakeProfit(),0,Red);
                   return(0);
                }
             }
          }
       }
    }
 }

void DoTrailCloud()
  {
    for (int i = 0; i < OrdersTotal(); i++) {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if ( OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic))  // only look if mygrid and symbol...
        {

          if (OrderType() == OP_BUY) 
          {
             if(IchSenA < IchSenB && OrderStopLoss() < IchSenA-20*Point) SL = IchSenA - 20*Point;
             if(IchSenB < IchSenA && OrderStopLoss() < IchSenB-20*Point) SL = IchSenB - 20*Point;
             OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Green);
             return(0);
          }

          if (OrderType() == OP_SELL) 
          {
             if(IchSenA < IchSenB && OrderStopLoss() > IchSenB+20*Point) SL = IchSenB + 20*Point;
             if(IchSenB < IchSenA && OrderStopLoss() > IchSenA+20*Point) SL = IchSenA + 20*Point;
             OrderModify(OrderTicket(),OrderOpenPrice(),SL,OrderTakeProfit(),0,Red);
             return(0);
          }
       }
    }
 }

void DoTrailK()
  {
    for (int i = 0; i < OrdersTotal(); i++) {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if ( OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic))  // only look if mygrid and symbol...
        {

          if (OrderType() == OP_BUY) 
          {
            if (OrderStopLoss() < IchKijun-10*Point)
            {
               OrderModify(OrderTicket(),OrderOpenPrice(),IchKijun-10*Point,OrderTakeProfit(),0,Green);
               return(0);
            }
          }

          if (OrderType() == OP_SELL) 
          {
            if (OrderStopLoss() > IchKijun+10*Point)
            {
             OrderModify(OrderTicket(),OrderOpenPrice(),IchKijun+10*Point,OrderTakeProfit(),0,Red);
             return(0);
            }
          }
       }
    }
 }

void CloseBuy()
{
   for (int i = 0; i < OrdersTotal(); i++) 
   {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic) && (OrderType()==OP_BUY)) 
     {
       OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
       Write("in function CloseBuyOrder Executed");
     }

   }
}

void CloseSell()
{
   for (int i = 0; i < OrdersTotal(); i++) 
   {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic) && (OrderType()==OP_SELL)) 
     {
       OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
       Write("in function CloseSellOrder Executed");
     }

   }
}

void DeleteBuyStop()
{
   for (int i = 0; i < OrdersTotal(); i++) {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic) && (OrderType()==OP_BUYSTOP)) {
       OrderDelete(OrderTicket());
       Write("in function DeleteBuyStopOrderDelete Executed");
     }

   }
}

void DeleteSellStop()
{
   for (int i = 0; i < OrdersTotal(); i++) {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic) && (OrderType()==OP_SELLSTOP)) {
       OrderDelete(OrderTicket());
       Write("in function DeleteSellStopOrderDelete Executed");
     }

   }
}

void DoModify()
{
   for (int i = 0; i < OrdersTotal(); i++) {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic) && (OrderType()==OP_SELLSTOP)) {
       if ((OrderOpenPrice()>Ask) || (OrderOpenPrice()<Ask)) {
         Write("in function DoModify , SellStop OrderModify Executed, Sell Stop was @ "+DoubleToStr(OrderOpenPrice(),4)+" it changed to "+DoubleToStr(Ask,4));
         OrderModify(OrderTicket(),Ask,SL,TP,0,Red);
       }
     }

     if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic) && (OrderType()==OP_BUYSTOP)) {
       if ((OrderOpenPrice()>Bid) || (OrderOpenPrice()<Bid)) {
         Write("in function DoModify , BuyStop OrderModify Executed, Buy Stop was @ "+DoubleToStr(OrderOpenPrice(),4)+" it changed to "+DoubleToStr(Bid,4));
         OrderModify(OrderTicket(),Bid,SL,TP,0,Red);
       }
     }
   }
}

void ModifyStop()
{
   for (int i = 0; i < OrdersTotal(); i++) {
     OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic) && (OrderType()==OP_SELL)) {
         Print("in function ModifyStop, Sell OrderModify Executed, Sell stoploss changed to ",SL);
         OrderModify(OrderTicket(),Ask,SL,TP,0,Red);
     }

     if (OrderSymbol()==Symbol() && (OrderMagicNumber() == Magic) && (OrderType()==OP_BUY)) {
         Print("in function ModifyStop, Buy OrderModify Executed, Buy stoploss was changed to ",SL);
         OrderModify(OrderTicket(),Bid,SL,TP,0,Red);
     }
   }
}

int Write(string str)
{
   int handle;

   handle = FileOpen(filename,FILE_READ|FILE_WRITE|FILE_CSV,"/t");
   FileSeek(handle, 0, SEEK_END);      
   FileWrite(handle,str + " Time " + TimeToStr(CurTime(),TIME_DATE|TIME_SECONDS));
    FileClose(handle);
}

bool NewBar()
{
   static int lastBars;
   if (lastBars != Bars)
   {
      lastBars = Bars;
      return(true);
   }
   else
   {
      return(false);
   }
}

int start()
  {
      // код доступен только после оплаты
   }

   int i, EODTime;
   int OrdersCondition;
   double ShortEntry, LongEntry, ShortSL, LongSL, ShortTP, LongTP;

   if (!NewBar()) return(0);

/*   if (!IsTesting()){
      if (Symbol()=="EURUSD"){
         BEPips=40;
         StopLoss=15;
         TakeProfit=70;
      }   
      else if (Symbol()=="GBPUSD"){
         BEPips=56;
         StopLoss=21;
         TakeProfit=98;
         }
      else if (Symbol()=="USDJPY"){
         BEPips=40;
         StopLoss=15;
         TakeProfit=70;
         }
      else if (Symbol()=="USDCHF"){
         BEPips=40;
         StopLoss=15;
         TakeProfit=70;
      }
      else {   //default
         BEPips=40;
         StopLoss=15;
         TakeProfit=70;
      }
   }
*/      
   filename=Symbol() + TradeLog + "-" + Month() + "-" + Day() + ".txt";

      IchTenkan = iCustom(NULL,0,"Ichimoku",9,26,52,0,1); //fast
      IchKijun =  iCustom(NULL,0,"Ichimoku",9,26,52,1,1); //slow
      IchSenA =  iCustom(NULL,0,"Ichimoku",9,26,52,2,1); //Cloud Top
      IchSenB =  iCustom(NULL,0,"Ichimoku",9,26,52,3,1); //Cloud bottom
      IchChin =  iCustom(NULL,0,"Ichimoku",9,26,52,4,26); //ChinKou Span

   ShortSL = Bid+(StopLoss*Point);
   ShortTP = Bid-(TakeProfit*Point);

   LongSL = Ask-(StopLoss*Point);
   LongTP = Ask+(TakeProfit*Point);

   if(TradeTKCross)
   {
      Magic=121920071;
      TradeComment="Tenkan Kijun Cross";

      OrdersCondition=CheckOrdersCondition();

      if(OrdersCondition==0)
      {

         if (IchChin > IchTenkan && IchTenkan > IchKijun && IchKijun > IchSenA && IchKijun > IchSenB)
         {
            if(StopLoss>0) SL=LongSL;
            if(TakeProfit>0) TP=LongTP;
            OpenBuy();
         }

         if (IchChin < IchTenkan && IchTenkan < IchKijun && IchKijun < IchSenA && IchKijun < IchSenB)
         {
            if(StopLoss>0) SL=ShortSL;
            if(TakeProfit>0) TP=ShortTP;
            OpenSell();
         }
      }

      if(OrdersCondition>0)
      {

         if (IchTenkan<IchKijun) CloseBuy();
         if (IchTenkan>IchKijun) CloseSell();
         if (BEPips>0) DoBE(BEPips);
         if (TrailingStop>0) DoTrail();
       }
    }

   if(TradeKCross)
   {
      Magic=121920072;
      TradeComment="Kijun Sen Cross";

      OrdersCondition=CheckOrdersCondition();

      if(OrdersCondition==0)
      {

         if (Close[1] > IchTenkan && IchTenkan > IchSenA && IchTenkan > IchSenB) 
         {
            SL = IchKijun-10*Point;
            OpenBuy();
         }

         if (Close[1] < IchTenkan && IchTenkan < IchSenA && IchTenkan < IchSenB) 
         {
            SL = IchKijun+10*Point;
            OpenSell();
         }
      }

      if(OrdersCondition>0)
      {

         if (Close[1] < IchTenkan) CloseBuy();
         if (Close[1] > IchTenkan) CloseSell();
         Print("Kijun:",IchKijun,", Close: ",Close[1]);
         DoTrailK();
       }
    }         

   if(TradeBreakout)
   {
      Magic=121920073;
      TradeComment="Cloud Breakout";

         IchSenA1 =  iCustom(NULL,PERIOD_D1,"Ichimoku",9,26,52,2,-26);
         IchSenB1 =  iCustom(NULL,PERIOD_D1,"Ichimoku",9,26,52,3,-26);
         IchSenA2 =  iCustom(NULL,PERIOD_W

Показано первые 50% кода (символов: 19610)

Как получить полную версию?

Введите ваш email и нажмите кнопку, чтобы перейти к оплате.