0
да все правильно
avatar

AM2

  • 16 ноября 2014, 17:28
0
сделал с подобным индикатором. pipscasor не запускается.
предварительная версия в базе: www.opentraders.ru/downloads/505/

avatar

AM2

  • 16 ноября 2014, 17:17
0
да. сейчас сделаю
avatar

AM2

  • 16 ноября 2014, 14:54
0
добавил БУ и включение БУ и манименеджмента


//--- Inputs
extern int    StopLoss    = 200;  // стоп лосс ордера
extern int    TakeProfit  = 200;  // тейк профит ордера
extern int    BUF         = 0;    // включение вывода в БУ(0-Выкл.,1-Вкл.)
extern int    BULevel     = 10;   // Уровень безубытка
extern int    BUProfit    = 100;  // Уровень профита
extern int    MM          = 0;    // включение расчета объема позиции(0-Выкл.,постоянный лот;1-Вкл.)
extern double Lots        = 0.1;  // объем позиции
extern double Risk        = 10;   // риск в процентах от депо
extern int    MAGIC       = 2014; // магик
avatar

AM2

  • 16 ноября 2014, 14:50
0
поместите в папку с индикаторами тот индикатор который я вам делал с тем же названием InBar.ex4. тогда запустится. в журнале пишет индикатор не нашел
avatar

AM2

  • 16 ноября 2014, 14:49
0
уменьшите стоп и риск в настройках и покажите на скрине что в журнале пишет. еще добавлю отключение расчета лота, чтобы постоянный был.
avatar

AM2

  • 16 ноября 2014, 14:11
0
можно написать ему об этом и попросить прокомментировать
avatar

AM2

  • 16 ноября 2014, 14:07
0
любой каприз пожалуйста, рандомная функция из чисел 1,2,3 ;) 
avatar

AM2

  • 16 ноября 2014, 14:05
0
дополнительные условия сейчас пропишу.
avatar

AM2

  • 16 ноября 2014, 13:29
+1
готово. советник в базе: www.opentraders.ru/downloads/504/

avatar

AM2

  • 16 ноября 2014, 13:24
+1
приступил к выполнению.
avatar

AM2

  • 16 ноября 2014, 12:22
+1
Можно. Просьба приложить индикаторы к заказу и уточнить выходы(по стопу или по сигналу индикатора)
avatar

AM2

  • 16 ноября 2014, 11:26
0
Разместите пожалуйста отдельный заказ на советник в этой группе и сделаю
avatar

AM2

  • 16 ноября 2014, 11:19
0
сегодня оптил с маленькими стопами, лимитники оказались снова намного эффективнее.
avatar

AM2

  • 15 ноября 2014, 23:56
+1
готово.

подправил чтобы открывал сделки на разных парах.

логика на примере покупки: открываемся если

1. 1-й излом зигзага больше 3-го но меньше второго и четвертого,
2. пятый излом меньше 3-го
3. в настоящее время нет покупки
4. предыдущая сделка была продажа


if(zz1>zz3 && zz1<zz2 && zz1<zz4 && zz5<=zz3 && b<1 && (LastDealResult()==0 || LastDealResult()==2))


обращение к индикатору есть

zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, i);



//+------------------------------------------------------------------+
//|                                                           WW.mq4 | 
//|                                            Copyright © 2014, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, AM2"
#property link      "http://www.forexsystems.biz"

#define MAGIC  20141115

extern int    StopLoss     = 450;
extern int    TakeProfit   = 800;
extern int    ExtDepth     = 10;
extern int    ExtDeviation = 5;
extern int    ExtBackstep  = 3;
extern double Lots         = 0.1;

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   double zz1,zz2,zz3,zz4,zz5;
   int    res,b,s;
   
//---- get Extremum ZigZag Price
 
   zz1=GetExtremumZZPrice(NULL,0,4,ExtDepth,ExtDeviation,ExtBackstep);
   zz2=GetExtremumZZPrice(NULL,0,3,ExtDepth,ExtDeviation,ExtBackstep);
   zz3=GetExtremumZZPrice(NULL,0,2,ExtDepth,ExtDeviation,ExtBackstep);
   zz4=GetExtremumZZPrice(NULL,0,1,ExtDepth,ExtDeviation,ExtBackstep);
   zz5=GetExtremumZZPrice(NULL,0,0,ExtDepth,ExtDeviation,ExtBackstep);

   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
       {
        if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
         {
          if(OrderType()==OP_BUY) b++;
          if(OrderType()==OP_SELL) s++;
         }
       }  
     }             
           
   Comment("\n","ZZ1 = ",zz1,"\n",
          "ZZ2 = ",zz2,"\n",
          "ZZ3 = ",zz3,"\n",
          "ZZ4 = ",zz4,"\n",
          "ZZ5 = ",zz5,"\n");
   
//---- buy conditions
   if(zz1>zz3 && zz1<zz2 && zz1<zz4 && zz5<=zz3 && b<1 && (LastDealResult()==0 || LastDealResult()==2))  
     {
      res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,fND(Ask-StopLoss*Point),fND(Ask+TakeProfit*Point),"",MAGIC,0,Blue);
      if(res<0)
       {
        Print("Order Buy  error: ",GetLastError());
       }
      else
        Print("OK Order Buy");  
      return;
     }   
//---- sell conditions
   if(zz1<zz3 && zz1>zz2 && zz1>zz4  && zz5>=zz3 && s<1 && (LastDealResult()==0 || LastDealResult()==1))  
     {
      res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,fND(Bid+StopLoss*Point),fND(Bid-TakeProfit*Point),"",MAGIC,0,Red);
      if(res<0)
       {
        Print("Order Sell  error: ",GetLastError());
       }
      else
        Print("OK Order Sell");  
      return;
     }
//----
  }
//+------------------------------------------------------------------+
double fND(double d, int n=-1) 
  {  
   if (n<0) return(NormalizeDouble(d, Digits)); 
   return(NormalizeDouble(d, n)); 
  }  
//+------------------------------------------------------------------+
bool NewBar()
  {
   static datetime lastbar = 0;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
    {
     lastbar=curbar;
     return (true);
    }
   else
    {
     return(false);
    }
  }  
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+

double GetExtremumZZPrice(string sy="", int tf=0, int ne=0, int dp=12, int dv=5, int bs=3) {
  if (sy=="" || sy=="0") sy=Symbol();
  double zz;
  int    i, k=iBars(sy, tf), ke=0;

  for (i=1; i<k; i++) {
    zz=iCustom(sy, tf, "ZigZag", dp, dv, bs, 0, i);
    if (zz!=0) {
      ke++;
      if (ke>ne) return(zz);
    }
  }
  Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
  return(0);
}
//+----------------------------------------------------------------------------+
int LastDealResult()
  {
   int result;
   if(OrderSelect(OrdersHistoryTotal(), MODE_HISTORY)==true)
    {
     if(OrderType()==OP_BUY) result=1;
     if(OrderType()==OP_SELL) result=2;
    }
   else
    {
     result=0;
    } 
   return(result);    
  } 
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void start()
  {
//---- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false) return;
//--- go trading only for first tiks of new bar
   if(NewBar()==true)
    {
     CheckForOpen();
    }                               
//----
  }  
//+------------------------------------------------------------------+
avatar

AM2

  • 15 ноября 2014, 20:33
0
опишите, пожалуйста подробнее и со скринами что именно у вас не работает в топике:
zakaz.opentraders.ru/
avatar

AM2

  • 15 ноября 2014, 17:38
+2
готово.




//+------------------------------------------------------------------+
//|                                                        Renko.mq4 |
//|                                            Copyright © 2014, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2014, AM2"
#property link      "http://www.forexsystems.biz"
#property description "indalekseifx Directional Line expert advisor"


//--- Inputs
extern double StopLoss    = 2000; // стоп лосс ордера
extern double TakeProfit  = 2000; // тейк профит ордера
extern double Lots        = 0.1;  // объем позиции
//----
extern int Amplitude      = 2;    // период средней indalekseifx Directional Line
extern int shift          = 2;    // смещение средней
//----
extern int FastPeriod     = 12;   // период быстрого макди 
extern int SlowPeriod     = 26;   // период медленного макди
extern int SignalPeriod   = 9;    // период сигнального макди
//----
extern int MACDAC         = 0;    // включение макди(1-включен,0-отключен)
extern int MAGIC          = 2014; // магик

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   int    res,b,s;
//--- get Moving Average 
   double indalekseifxDeepSkyBlue=iCustom(Symbol(),0,"indalekseifx",Amplitude,1,1);
   double indalekseifxTomato=iCustom(Symbol(),0,"indalekseifx",Amplitude,0,1);
   double MACDGreen=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,1,1);
   double MACDRed=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,0,1);
      
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
       {
        if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
         {
          if(OrderType()==OP_BUY) b++;
          if(OrderType()==OP_SELL) s++;
         }
       }  
     }         
 
   //--- sell conditions
         if(MACDAC==1)
          {
           if(indalekseifxDeepSkyBlue>indalekseifxTomato && MACDGreen<MACDRed && s<1  && (LastDealResult()==0 || LastDealResult()==1))
            {
             res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,fND(Bid+StopLoss*Point),fND(Bid-TakeProfit*Point),"",MAGIC,0,Tomato);
             if(res<0)
              {
               Print("Order Sell  error: ",GetLastError());
              }
             else
               Print("OK Order Sell");             
               return;
            }
      //--- buy conditions
           if(indalekseifxTomato>indalekseifxDeepSkyBlue && MACDGreen>MACDRed && b<1 && (LastDealResult()==0 || LastDealResult()==2))
            {
             res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,fND(Ask-StopLoss*Point),fND(Ask+TakeProfit*Point),"",MAGIC,0,DeepSkyBlue);      
             if(res<0)
              {
               Print("Order Buy  error: ",GetLastError());
              }
             else
               Print("OK Order Buy");             
               return;
            }
           }
           else
            {
             if(indalekseifxDeepSkyBlue>indalekseifxTomato && s<1 && (LastDealResult()==0 || LastDealResult()==1))
              {
               res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Tomato);
               if(res<0)
                {
                 Print("Order Sell  error: ",GetLastError());
                }
               else
               Print("OK Order Sell");             
               return;                                     
              }
      //--- buy conditions
             if(indalekseifxTomato>indalekseifxDeepSkyBlue && b<1 && (LastDealResult()==0 || LastDealResult()==2))
              {
               res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,fND(Ask-StopLoss*Point),fND(Ask+TakeProfit*Point),"",MAGIC,0,DeepSkyBlue);         
               if(res<0)
                {
                 Print("Order Buy  error: ",GetLastError());
                }
               else
               Print("OK Order Buy");             
               return;             
              }      
            }
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
//--- get Moving Average 
   double indalekseifxDeepSkyBlue=iCustom(Symbol(),0,"indalekseifx",Amplitude,1,shift);
   double indalekseifxTomato=iCustom(Symbol(),0,"indalekseifx",Amplitude,0,shift);
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
      //--- check order type 
      if(OrderType()==OP_BUY)
        {
         if(indalekseifxDeepSkyBlue>indalekseifxTomato)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(indalekseifxTomato>indalekseifxDeepSkyBlue)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
//+------------------------------------------------------------------+
bool NewBar()
  {
   static datetime lastbar = 0;
   datetime curbar = Time[0];
   if(lastbar!=curbar)
   {
      lastbar=curbar;
      return (true);
   }
   else
   {
      return(false);
   }
  }
//+------------------------------------------------------------------+
int LastDealResult()
  {
   int result;
   if(OrderSelect(OrdersHistoryTotal(), MODE_HISTORY)==true)
    {
     if(OrderType()==OP_BUY) result=1;
     if(OrderType()==OP_SELL) result=2;
    }
   else
    {
     result=0;
    } 
   return(result);    
  } 
//+------------------------------------------------------------------+
double fND(double d, int n=-1) 
  {  
   if (n<0) return(NormalizeDouble(d, Digits)); 
   return(NormalizeDouble(d, n)); 
  } 
//+------------------------------------------------------------------+
void OnTick()
  {
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- go trading only for first tiks of new bar
   if(NewBar()==true)
    {
     Print("New Bar");
     CheckForOpen();
     CheckForClose();
    }
   Comment("\nResult of last deal: ", LastDealResult());
//---
  } 
//+------------------------------------------------------------------+  
avatar

AM2

  • 15 ноября 2014, 13:07
+1
сейчас советник можно установить на несколько пар. добавил к средней параметр shift с помощью которого читаем значение средней на несколько свечек вглубь при закрытии, чтобы не было перерисовки. написал функцию которая читает сделки в истории и открывает обратную позу.


//+------------------------------------------------------------------+
//|                                                        Renko.mq4 |
//|                                            Copyright © 2014, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2014, AM2"
#property link      "http://www.forexsystems.biz"
#property description "Slope Directional Line expert advisor"


//--- Inputs
extern double StopLoss    = 500; // стоп лосс ордера
extern double TakeProfit  = 500; // тейк профит ордера
extern double Lots        = 0.1; // объем позиции
//----
extern int period         = 90;  // период средней Slope Directional Line
extern int method         = 2;   // метод средней(SMA=0,EMA=1,SMMA=2,LWMA=3)
extern int price          = 0;   // цена по которой строится средняя
extern int shift          = 3;   // смещение средней
//----
extern int FastPeriod     = 12;  // период быстрого макди 
extern int SlowPeriod     = 26;  // период медленного макди
extern int SignalPeriod   = 9;   // период сигнального макди
//----
extern int MACDAC         = 1;   // включение макди(1-включен,0-отключен)
extern int MAGIC          = 333; // магик

//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   int    res,b,s;
   bool sp=true,bp=true;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- get Moving Average 
   double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,1);
   double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,1);
   double MACDGreen=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,1,1);
   double MACDRed=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,0,1);
      
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
       {
        if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
         {
          if(OrderType()==OP_BUY) b++;sp=false;
          if(OrderType()==OP_SELL) s++;bp=false;
         }
       }  
     }         
 
   //--- sell conditions
         if(MACDAC==1)
          {
           if(SlopeBlue>SlopeRed && MACDGreen<MACDRed && s<1 && (LastDealResult()==0 || LastDealResult()==1))
            {
             res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Red);
             return;
            }
      //--- buy conditions
           if(SlopeRed>SlopeBlue && MACDGreen>MACDRed && b<1 && (LastDealResult()==0 ||LastDealResult()==2))
            {
             res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,Blue);      
             return;
            }
           }
           else
            {
             if(SlopeBlue>SlopeRed && s<1&& (LastDealResult()==0 || LastDealResult()==1))
              {
               res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Red);       
               return;
              }
      //--- buy conditions
             if(SlopeRed>SlopeBlue && b<1 && (LastDealResult()==0 ||LastDealResult()==2))
              {
               res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,Blue);         
               return;
              }      
            }
        
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- get Moving Average 
   double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,shift);
   double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,shift);
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
      //--- check order type 
      if(OrderType()==OP_BUY)
        {
         if(SlopeBlue>SlopeRed)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(SlopeRed>SlopeBlue)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- calculate open orders by current symbol
   CheckForOpen();
   CheckForClose();
   Comment("\nResult of last deal: ", LastDealResult());
//---
  }
//+------------------------------------------------------------------+
int LastDealResult()
  {
   int result;
   if(OrderSelect(OrdersHistoryTotal(), MODE_HISTORY)==true)
    {
     if(OrderType()==OP_BUY) result=1;
     if(OrderType()==OP_SELL) result=2;
    }
   else
    {
     Print("No deals in history");
     result=0;
    } 
   return(result);    
  }

//+------------------------------------------------------------------+
avatar

AM2

  • 14 ноября 2014, 21:44
+1
измените магик в строчке с параметрами, когда на разные пары ставить будете. вынес его в настройки


//+------------------------------------------------------------------+
//|                                                        Renko.mq4 |
//|                                            Copyright © 2014, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2014, AM2"
#property link      "http://www.forexsystems.biz"
#property description "Slope Directional Line expert advisor"


//--- Inputs
extern double StopLoss    = 500; // стоп лосс ордера
extern double TakeProfit  = 500; // тейк профит ордера
extern double Lots        = 0.1; // объем позиции
//----
extern int period         = 90;  // период средней Slope Directional Line
extern int method         = 2;   // метод средней(SMA=0,EMA=1,SMMA=2,LWMA=3)
extern int price          = 0;   // цена по которой строится средняя
//----
extern int FastPeriod     = 12;  // период быстрого макди 
extern int SlowPeriod     = 26;  // период медленного макди
extern int SignalPeriod   = 9;   // период сигнального макди
//----
extern int MACDAC         = 1;   // включение макди(1-включен,0-отключен)
extern int MAGIC          = 2014;// магик

bool buy=true,sell=true;
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   int    res;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- get Moving Average 
   double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,1);
   double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,1);
   double MACDGreen=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,1,1);
   double MACDRed=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,0,1);   

//--- sell conditions
   if(MACDAC==1)
    {
     if(SlopeBlue>SlopeRed && MACDGreen<MACDRed && sell==true)
      {
       res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Red);
       sell=false;
       buy=true;
       return;
      }
//--- buy conditions
     if(SlopeRed>SlopeBlue && MACDGreen>MACDRed  && buy==true)
      {
       res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,Blue);
       buy=false;
       sell=true;       
       return;
      }
     }
     else
      {
       if(SlopeBlue>SlopeRed && sell==true)
        {
         res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGIC,0,Red);
         sell=false;
         buy=true;         
         return;
        }
//--- buy conditions
       if(SlopeRed>SlopeBlue && buy==true)
        {
         res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGIC,0,Blue);
         buy=false;
         sell=true;          
         return;
        }      
      }
//---
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- get Moving Average 
   double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,1);
   double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,1);
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGIC || OrderSymbol()!=Symbol()) continue;
      //--- check order type 
      if(OrderType()==OP_BUY)
        {
         if(SlopeBlue>SlopeRed)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(SlopeRed>SlopeBlue)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- calculate open orders by current symbol
   if(OrdersTotal()<1) CheckForOpen();
   else CheckForClose();
//---
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 14 ноября 2014, 17:10
+1
подправил, сейчас как?


//+------------------------------------------------------------------+
//|                                                        Renko.mq4 |
//|                                            Copyright © 2014, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2011, AM2"
#property link      "http://www.forexsystems.biz"
#property description "Slope Directional Line expert advisor"

#define MAGICMA  20141111
//--- Inputs
extern double StopLoss    = 500; // стоп лосс ордера
extern double TakeProfit  = 500; // тейк профит ордера
extern double Lots        = 0.1; // объем позиции
//----
extern int period         = 90;  // период средней Slope Directional Line
extern int method         = 2;   // метод средней(SMA=0,EMA=1,SMMA=2,LWMA=3)
extern int price          = 0;   // цена по которой строится средняя
//----
extern int FastPeriod     = 12;  // период быстрого макди 
extern int SlowPeriod     = 26;  // период медленного макди
extern int SignalPeriod   = 9;   // период сигнального макди
//----
extern int MACDAC         = 1;   // включение макди(1-включен,0-отключен)

bool buy=true,sell=true;
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void CheckForOpen()
  {
   int    res;
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- get Moving Average 
   double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,1);
   double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,1);
   double MACDGreen=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,1,1);
   double MACDRed=iCustom(Symbol(),0,"MACDTraditional",FastPeriod,SlowPeriod,SignalPeriod,0,1);   

//--- sell conditions
   if(MACDAC==1)
    {
     if(SlopeBlue>SlopeRed && MACDGreen<MACDRed && sell==true)
      {
       res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red);
       sell=false;
       buy=true;
       return;
      }
//--- buy conditions
     if(SlopeRed>SlopeBlue && MACDGreen>MACDRed  && buy==true)
      {
       res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);
       buy=false;
       sell=true;       
       return;
      }
     }
     else
      {
       if(SlopeBlue>SlopeRed && sell==true)
        {
         res=OrderSend(Symbol(),OP_SELL,Lots,Bid,3,Bid+StopLoss*Point,Bid-TakeProfit*Point,"",MAGICMA,0,Red);
         sell=false;
         buy=true;         
         return;
        }
//--- buy conditions
       if(SlopeRed>SlopeBlue && buy==true)
        {
         res=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,Ask-StopLoss*Point,Ask+TakeProfit*Point,"",MAGICMA,0,Blue);
         buy=false;
         sell=true;          
         return;
        }      
      }
//---
  }
//+------------------------------------------------------------------+
//| Check for close order conditions                                 |
//+------------------------------------------------------------------+
void CheckForClose()
  {
//--- go trading only for first tiks of new bar
   if(Volume[0]>1) return;
//--- get Moving Average 
   double SlopeBlue=iCustom(Symbol(),0,"Slope",period,method,price,0,1);
   double SlopeRed=iCustom(Symbol(),0,"Slope",period,method,price,1,1);
//---
   for(int i=0;i<OrdersTotal();i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
      if(OrderMagicNumber()!=MAGICMA || OrderSymbol()!=Symbol()) continue;
      //--- check order type 
      if(OrderType()==OP_BUY)
        {
         if(SlopeBlue>SlopeRed)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Bid,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
      if(OrderType()==OP_SELL)
        {
         if(SlopeRed>SlopeBlue)
           {
            if(!OrderClose(OrderTicket(),OrderLots(),Ask,3,White))
               Print("OrderClose error ",GetLastError());
           }
         break;
        }
     }
//---
  }
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
//--- check for history and trading
   if(Bars<100 || IsTradeAllowed()==false)
      return;
//--- calculate open orders by current symbol
   if(OrdersTotal()<1) CheckForOpen();
   else CheckForClose();
//---
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 14 ноября 2014, 16:48