Navigation:Home > Content >

RenkoChannel2.mq4

Time: 2010-01-01 | Download file:RenkoChannel2.mq4

//+------------------------------------------------------------------+
//|                                                 RenkoChannel.mq4 |
//|                                              Copyright 2016, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link      "http://www.forexsystems.biz"
#property version   "1.00"
#property strict

//--- Inputs
extern double Lots       = 0.1;      // лот
extern int StopLoss      = 500;      // лось
extern int TakeProfit    = 500;      // язь
extern int Slip          = 30;       // реквот
extern int Magic         = 123;      // магик

extern string IndName="vhpchannel_03";

extern int Fast          = 21;
extern int Slow          = 100;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
  {
   int r=0;
   color clr=Green;
   double sl=0,tp=0;

   if(type==1 || type==3 || type==5)
     {
      clr=Red;
      if(StopLoss>0) sl=NormalizeDouble(price+StopLoss*Point,Digits);
      if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
     }

   if(type==0 || type==2 || type==4)
     {
      clr=Blue;
      if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);
      if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
     }

   r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
   return;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountTrades()
  {
   int count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderType()<2) count++;
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CloseAll(int ot=-1)
  {
   bool cl;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==0 && (ot==0 || ot==-1))
              {
               RefreshRates();
               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
              }
            if(OrderType()==1 && (ot==1 || ot==-1))
              {
               RefreshRates();
               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Тип последней сделки                                             |
//+------------------------------------------------------------------+
int LastDealType()
  {
   int type=0;
   if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
     {
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
        {
         if(OrderType()==0)
           {
            type=1;//buy  
           }
         if(OrderType()==1)
           {
            type=2;//sell  
           }
        }
     }
   return(type);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OpenPos()
  {
   double up=iCustom(NULL,0,IndName,Fast,Slow,2,1);
   double dn=iCustom(NULL,0,IndName,Fast,Slow,3,1);

// покупка

   if((Close[1]>Open[1] && Close[2]Open[1] && Close[2]dn) || // цена выше нижней границы канала плюс разворотный паттерн и касание
      LastDealType()==2)                                               // последняя была продажа
     {
      if(CountTrades()<1) PutOrder(0,Ask);
     }
// продажа

   if((Close[1]Open[2] && Bid>up) ||               // цена выше верхней границы канала плюс разворотный паттерн
      (High[2]>up && Close[1]Open[2] && Bid=0;i--)
        {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
           {
            if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
              {
               if(OrderType()==OP_BUY)
                 {
                  if(High[2]>up && Close[1]Open[2] && BidOpen[1] && Close[2]dn) // цена выше нижней границы канала плюс разворотный паттерн и касание
                    {
                     CloseAll(1);
                    }
                 }
              }
           }
        }
     }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
   void OnTick()
     {
      double up=iCustom(NULL,0,IndName,Fast,Slow,2,1);
      double dn=iCustom(NULL,0,IndName,Fast,Slow,3,1);

      if(CountTrades()<1) OpenPos();
      else ClosePos();

      Comment("\n up: ",up,"\n dn: ",dn);
     }
//+------------------------------------------------------------------+

Recommend