0
Сделал так как понял ваше ТЗ. А что будет делать советник в такой ситуации?



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

extern int    StopLoss     = 0;        // лось
extern int    TakeProfit   = 0;        // язь
extern int    BULevel      = 0;        // уровень БУ
extern int    BUPoint      = 30;       // пункты БУ
extern int    TrailingStop = 0;        // трал
extern int    TrailingStep = 20;       // шаг трала
extern int    Profit       = 20;       // профит в валюте
extern int    Delta        = 200;      // расстояние для отложек
extern int    Slip         = 3;        // реквот
extern double Lots         = 0.1;      // лот
extern double PlusLot      = 0.1;      // прибавление лота
extern int    Magic        = 111;      // магик 
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

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

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double lot)
  {
   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,lot,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,0,clr);
   return;
  }
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу                                          |
//+------------------------------------------------------------------+
int CountOrders(int type)
  {
   int count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==type) count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountTrades()
  {
   int count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()<2) count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//| Профит всех ордеров по типу ордера                               |
//+------------------------------------------------------------------+
double AllProfit(int ot=-1)
  {
   double pr=0;
   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))
              {
               pr+=OrderProfit()+OrderCommission()+OrderSwap();
              }

            if(OrderType()==1 && (ot==1 || ot==-1))
              {
               pr+=OrderProfit()+OrderCommission()+OrderSwap();
              }
           }
        }
     }
   return(pr);
  }
//+------------------------------------------------------------------+
//| Закрытие позиции по типу ордера                                  |
//+------------------------------------------------------------------+
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);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров                                      |
//+------------------------------------------------------------------+
void DelOrder()
  {
   bool del;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()>1) del=OrderDelete(OrderTicket());
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Trailing()
  {
   bool mod;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderType()==OP_BUY)
           {
            if(Bid-OrderOpenPrice()>TrailingStop*Point)
              {
               if(OrderStopLoss()<Bid-(TrailingStop+TrailingStep-1)*Point)
                 {
                  mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }
           }

         if(OrderType()==OP_SELL)
           {
            if((OrderOpenPrice()-Ask)>TrailingStop*Point)
              {
               if(OrderStopLoss()>Ask+(TrailingStop+TrailingStep-1)*Point || OrderStopLoss()==0)
                 {
                  mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void BU()
  {
   bool m;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(OrderOpenPrice()<=(Bid-(BULevel+BUPoint)*Point) && OrderOpenPrice()>OrderStopLoss())
                 {
                  m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
                 {
                  m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(CountTrades()<1)
     {
      if(CountOrders(4)<1) PutOrder(4,Bid+Delta*Point,Lots);
      if(CountOrders(5)<1) PutOrder(5,Bid-Delta*Point,Lots+PlusLot);
     }

   if(AllProfit()>Profit && Profit>0)
     {
      CloseAll();
      DelOrder();
     }

   if(BULevel>0) BU();
   if(TrailingStop>0) Trailing();
  }
//+------------------------------------------------------------------+
avatar

AM2

  • 11 января 2017, 19:15
0
Не раньше следующей недели буду смотреть.
avatar

AM2

  • 11 января 2017, 17:27
0
Чужой код не правлю, ТЗ с нуля рассмотрю.
avatar

AM2

  • 11 января 2017, 17:25
0
Я сначала буду ваш заказ по скорости движения цены смотреть, а все остальное в следующие месяцы.
avatar

AM2

  • 11 января 2017, 17:24
+1
Если вы считаете, что закодить такое условие просто, то можете попробовать самостоятельно:


   if(Open[1]-Close[1]>0)
     {
      if((Close[2]-Open[2])/(Open[1]-Close[1])>4 && High[1]-Open[1]>Nouse*Point && Open[1]-Close[1]<Body*Point && Close[1]-Low[1]<High[1]-Open[1]) return(true);
     }
avatar

AM2

  • 10 января 2017, 00:13
+1
Вот сейчас получше распознает пин. Если и сейчас не так, то к платному.
www.opentraders.ru/downloads/1449/



avatar

AM2

  • 9 января 2017, 22:37
0
Огромная просьба прописывать сразу все условия в ТЗ, чтобы мне потом не переделывать:



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

//--- Inputs
extern double Lots       = 0.1;      // лот
extern int StopLoss      = 50;       // лось
extern int TakeProfit    = 70;       // язь
extern int BULevel       = 0;        // уровень БУ
extern int BUPoint       = 30;       // пункты БУ
extern int TrailingStop  = 35;       // трал
extern int Expiration    = 10;       // истечение ордера в часах
extern int Delta         = 100;      // дельта
extern int Body          = 30;       // тело
extern int Nouse         = 100;      // нос
extern int Slip          = 30;       // реквот
extern int Magic         = 123;      // магик

datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Comment("");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//| Простой трал                                                     |
//+------------------------------------------------------------------+
void Trailing()
  {
   bool mod;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(Bid-OrderOpenPrice()>TrailingStop*Point)
                 {
                  if(OrderStopLoss()<Bid-TrailingStop*Point)
                    {
                     mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
                     return;
                    }
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if((OrderOpenPrice()-Ask)>TrailingStop*Point)
                 {
                  if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
                    {
                     mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
                     return;
                    }
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void BU()
  {
   bool m;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(OrderOpenPrice()<=(Bid-(BULevel+BUPoint)*Point) && OrderOpenPrice()>OrderStopLoss())
                 {
                  m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
                 {
                  m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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); else sl=High[1];
      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); else sl=Low[1];
      if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
     }

   r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,clr);
   return;
  }
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу                                          |
//+------------------------------------------------------------------+
int CountOrders(int type)
  {
   int count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==type) count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров                                      |
//+------------------------------------------------------------------+
void DelOrder()
  {
   bool del;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()>1) del=OrderDelete(OrderTicket());
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool buy()
  {
   if(Open[1]-Close[1]>0)
     {
      if((Close[2]-Open[2])/(Open[1]-Close[1])>4 && High[1]-Open[1]>Nouse*Point && Open[1]-Close[1]<Body*Point) return(true);
     }
   return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool sell()
  {
   if(Open[1]-Close[1]>0)
     {
      if((Open[2]-Close[2])/(Close[1]-Open[1])>4 && Open[1]-Low[1]>Nouse*Point && Close[1]-Open[1]<Body*Point) return(true);
     }
   return(false);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(BULevel>0) BU();
   if(TrailingStop>0) Trailing();

   if(t!=Time[0] && (CountOrders(0)<1 && CountOrders(1)<1))
     {
      if(CountOrders(4)<1 && buy()) PutOrder(4,High[1]+Delta*Point);
      if(CountOrders(5)<1 && sell()) PutOrder(5,Low[1]-Delta*Point);
      t=Time[0];
     }

   if(CountOrders(0)>0 || CountOrders(1)>0) DelOrder();
  }
//+------------------------------------------------------------------+



avatar

AM2

  • 9 января 2017, 21:38
+1
Посмотрите как поведет себя такой вариант:


//+------------------------------------------------------------------+
//|                                                       Bablos.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

extern int    StopLoss     = 500;      // лось
extern int    TakeProfit   = 10;       // язь
extern int    Delta        = 10;       // расстояние для отложек
extern int    Spread       = 10;       // спред
extern int    Vol          = 40;       // волатильность
extern int    Slip         = 0;        // реквот
extern int    StartHour    = 0;        // час начала торговли
extern int    StartMin     = 30;       // минута начала торговли
extern int    EndHour      = 23;       // час окончания торговли
extern int    EndMin       = 30;       // минута окончания торговли
extern int    StopTrade    = 0;        // 1-остановка после закрытия всех ордеров
extern int    Magic1       = 111;      // магик 1
extern int    Magic2       = 222;      // магик 2
extern double Lots         = 0.1;      // лот
extern string SoundTake    = "ok.wav"; // звук тейк
extern string SoundTrade="expert.wav"; // звук остановка

int cycle=0;
datetime t=0;
bool trade=true;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

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

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool isTradeTimeInt(int hb=0,int mb=0,int he=0,int me=0)
  {
   datetime db, de;           // Время начала и окончания работы
   int      hc;               // Часы текущего времени торгового сервера

   db=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+(string)hb+":"+(string)mb);
   de=StrToTime(TimeToStr(TimeCurrent(), TIME_DATE)+" "+(string)he+":"+(string)me);
   hc=TimeHour(TimeCurrent());

   if(db>=de)
     {
      if(hc>=he) de+=24*60*60; else db-=24*60*60;
     }

   if(TimeCurrent()>=db && TimeCurrent()<=de) return(True);
   else return(False);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,int magic)
  {
   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 CountOrders(int type)
  {
   int count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==type) count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//| Подсчет позиций                                                  |
//+------------------------------------------------------------------+
int CountTrades(int ot=-1)
  {
   int count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==0 && (ot==0 || ot==-1)) count++;
            if(OrderType()==1 && (ot==1 || ot==-1)) count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ModifyOrders(int magic)
  {
   double all=0,tp=0,sl=0;
   double count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
           {
            if(OrderType()==OP_BUY || OrderType()==OP_SELL)
              {
               all+=OrderOpenPrice()*OrderLots();
               count+=OrderLots();
              }
           }
        }
     }
   if(count>0) all=NormalizeDouble(all/count,Digits);

   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==magic)
           {
            if(OrderType()==OP_BUY)
              {
               tp=NormalizeDouble(all+TakeProfit*Point,Digits);
               sl=NormalizeDouble(all-StopLoss*Point,Digits);
               if(OrderStopLoss()!=sl || OrderTakeProfit()!=tp)
                  bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
              }
            if(OrderType()==OP_SELL)
              {
               tp=NormalizeDouble(all-TakeProfit*Point,Digits);
               sl=NormalizeDouble(all+StopLoss*Point,Digits);
               if(OrderStopLoss()!=sl || OrderTakeProfit()!=tp)
                  bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void Mode()
  {
   bool m;
   double oop=0,sl=0,tp=0;

   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==2)
              {
               if((Ask-OrderOpenPrice()>Delta*Point) || (Ask-OrderOpenPrice()<Delta*Point))
                 {
                  oop=NormalizeDouble(Ask-Delta*Point,Digits);
                  if(StopLoss>0) sl=NormalizeDouble(oop-StopLoss*Point,Digits);
                  if(TakeProfit>0) tp=NormalizeDouble(oop+TakeProfit*Point,Digits);
                  if(OrderOpenPrice()!=oop) m=OrderModify(OrderTicket(),oop,sl,tp,OrderExpiration(),Lime);
                 }

              }

            if(OrderType()==3)
              {
               if((OrderOpenPrice()-Bid>Delta*Point) || (OrderOpenPrice()-Bid<Delta*Point))
                 {
                  oop=NormalizeDouble(Bid+Delta*Point,Digits);
                  if(StopLoss>0) sl=NormalizeDouble(oop+StopLoss*Point,Digits);
                  if(TakeProfit>0) tp=NormalizeDouble(oop-TakeProfit*Point,Digits);
                  if(OrderOpenPrice()!=oop) m=OrderModify(OrderTicket(),oop,sl,tp,OrderExpiration(),Lime);
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double vol=MathAbs((Open[0]-Close[0])/Point);
   double spread=MarketInfo(NULL,MODE_SPREAD);

   if(cycle>0 && CountTrades()<1 && StopTrade>0) trade=false;

   if(trade==False)
     {
      PlaySound(SoundTrade);
      Alert("SoundTrade");
     }

   if(cycle>0 && (CountTrades(0)<1 || CountTrades(0)<1))
     {
      PlaySound(SoundTake);
      Alert("SoundTake");
     }

   if(trade)
     {
      if(vol>Vol && isTradeTimeInt(StartHour,StartMin,EndHour,EndMin) && spread<=Spread)
        {
         if(t!=Time[0])
           {
            if(CountOrders(3)<1) PutOrder(3,Bid+Delta*Point,Magic1);
            if(CountOrders(2)<1) PutOrder(2,Ask-Delta*Point,Magic2);
            t=Time[0];
           }
        }

      if(CountOrders(0)>0) ModifyOrders(Magic2);
      if(CountOrders(1)>0) ModifyOrders(Magic1);

      Mode();
      if(CountTrades()>0) cycle++;
     }

   Comment("\n Trades: ",CountTrades(),
           "\n Vol: ",NormalizeDouble(vol,1),
           "\n Spread: ",spread,
           "\n Cycle: ",cycle,
           "\n Trade: ",trade);
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 9 января 2017, 21:22
0
Просьба переделать написанный вами советник

Это какой то микс :D  Лучше пишите ТЗ но будет с двумя магиками.
avatar

AM2

  • 8 января 2017, 19:39
0
Сейчас стоп на хай и лоу:




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

//--- Inputs
extern double Lots       = 0.1;      // лот
extern int StopLoss      = 50;       // лось
extern int TakeProfit    = 70;       // язь
extern int BULevel       = 0;        // уровень БУ
extern int BUPoint       = 30;       // пункты БУ
extern int TrailingStop  = 35;       // трал
extern int Expiration    = 10;       // истечение ордера в часах
extern int Delta         = 100;      // дельта
extern int Body          = 30;       // тело
extern int Nouse         = 100;      // нос
extern int Slip          = 30;       // реквот
extern int Magic         = 123;      // магик

datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Comment("");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//| Простой трал                                                     |
//+------------------------------------------------------------------+
void Trailing()
  {
   bool mod;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(Bid-OrderOpenPrice()>TrailingStop*Point)
                 {
                  if(OrderStopLoss()<Bid-TrailingStop*Point)
                    {
                     mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
                     return;
                    }
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if((OrderOpenPrice()-Ask)>TrailingStop*Point)
                 {
                  if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
                    {
                     mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
                     return;
                    }
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void BU()
  {
   bool m;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(OrderOpenPrice()<=(Bid-(BULevel+BUPoint)*Point) && OrderOpenPrice()>OrderStopLoss())
                 {
                  m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+BUPoint*Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if(OrderOpenPrice()>=(Ask+(BULevel+BUPoint)*Point) && (OrderOpenPrice()<OrderStopLoss() || OrderStopLoss()==0))
                 {
                  m=OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-BUPoint*Point,OrderTakeProfit(),0,Yellow);
                  return;
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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); else sl=High[1];
      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); else sl=Low[1];
      if(TakeProfit>0) tp=NormalizeDouble(price+TakeProfit*Point,Digits);
     }

   r=OrderSend(NULL,type,Lots,NormalizeDouble(price,Digits),Slip,sl,tp,"",Magic,TimeCurrent()+Expiration*3600,clr);
   return;
  }
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу                                          |
//+------------------------------------------------------------------+
int CountOrders(int type)
  {
   int count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==type) count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров                                      |
//+------------------------------------------------------------------+
void DelOrder()
  {
   bool del;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()>1) del=OrderDelete(OrderTicket());
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool buy()
  {
   if(Open[1]-Close[1]>0)
     {
      if((Close[2]-Open[2])/(Open[1]-Close[1])>4 && High[1]-Open[1]>Nouse*Point && Open[1]-Close[1]<Body*Point) return(true);
     }
   return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool sell()
  {
   if(Open[1]-Close[1]>0)
     {
      if((Open[2]-Close[2])/(Close[1]-Open[1])>4 && Open[1]-Low[1]>Nouse*Point && Close[1]-Open[1]<Body*Point) return(true);
     }
   return(false);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(BULevel>0) BU();
   if(TrailingStop>0) Trailing();

   if(t!=Time[0] && (CountOrders(0)<1 && CountOrders(1)<1))
     {
      if(buy() || sell())
        {
         if(CountOrders(4)<1) PutOrder(4,High[1]+Delta*Point);
         if(CountOrders(5)<1) PutOrder(5,Low[1]-Delta*Point);
         t=Time[0];
        }
     }

   if(CountOrders(0)>0 || CountOrders(1)>0) DelOrder();
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 8 января 2017, 18:47
0
Поясните то что нужно на пальцах на скринах то есть? :) 
avatar

AM2

  • 8 января 2017, 17:23
0
По моему заказчик просил о трёх рыночных ордерах по сигналу 
а в этом коде как и было ставиться один рыночный и один отложенный

Если просили об этом то значит заказчик знает что достаточно добавить:

for(int i=1;i<=3;i++)

:) 
avatar

AM2

  • 8 января 2017, 17:09
0
Андрей в советнике нет функции перевод в безубыток.

Да где ж я тебе его возьму! :D 
Если только здесь :)  www.opentraders.ru/downloads/1449/
avatar

AM2

  • 8 января 2017, 17:07
+1
Вот набросок как раз по нужным паттернам:




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

//--- Inputs
extern double Lots       = 0.1;      // лот
extern int StopLoss      = 50;       // лось
extern int TakeProfit    = 70;       // язь
extern int TrailingStop  = 35;       // трал
extern int Expiration    = 10;       // истечение ордера в часах
extern int Delta         = 100;      // дельта
extern int Body          = 30;       // тело
extern int Nouse         = 100;      // нос
extern int Slip          = 30;       // реквот
extern int Magic         = 123;      // магик

datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Comment("");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//| Простой трал                                                     |
//+------------------------------------------------------------------+
void Trailing()
  {
   bool mod;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() || OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(Bid-OrderOpenPrice()>TrailingStop*Point)
                 {
                  if(OrderStopLoss()<Bid-TrailingStop*Point)
                    {
                     mod=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*Point,OrderTakeProfit(),0,Yellow);
                     return;
                    }
                 }
              }

            if(OrderType()==OP_SELL)
              {
               if((OrderOpenPrice()-Ask)>TrailingStop*Point)
                 {
                  if((OrderStopLoss()>(Ask+TrailingStop*Point)) || (OrderStopLoss()==0))
                    {
                     mod=OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop*Point,OrderTakeProfit(),0,Yellow);
                     return;
                    }
                 }
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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,TimeCurrent()+Expiration*3600,clr);
   return;
  }
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу                                          |
//+------------------------------------------------------------------+
int CountOrders(int type)
  {
   int count=0;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==type) count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров                                      |
//+------------------------------------------------------------------+
void DelOrder()
  {
   bool del;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()>1) del=OrderDelete(OrderTicket());
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool buy()
  {
   if((Close[2]-Open[2])/(Open[1]-Close[1])>4 && High[1]-Open[1]>Nouse*Point && Open[1]-Close[1]<Body*Point) return(true);
   return(false);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
bool sell()
  {
   if((Open[2]-Close[2])/(Close[1]-Open[1])>4 && Open[1]-Low[1]>Nouse*Point && Close[1]-Open[1]<Body*Point) return(true);
   return(false);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(TrailingStop>0) Trailing();

   if(t!=Time[0] && (CountOrders(0)<1 && CountOrders(1)<1))
     {
      if(buy() || sell())
        {
         if(CountOrders(4)<1) PutOrder(4,High[1]+Delta*Point);
         if(CountOrders(5)<1) PutOrder(5,Low[1]-Delta*Point);
         t=Time[0];
        }
     }

   if(CountOrders(0)>0 || CountOrders(1)>0) DelOrder();
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 8 января 2017, 14:52
0
Покажите на скрине какой паттерн кодить? Этот?

avatar

AM2

  • 8 января 2017, 13:39
+1
Не раньше пятницы буду смотреть.
avatar

AM2

  • 8 января 2017, 06:27
0
Не раньше четверга, очередь :) 
avatar

AM2

  • 8 января 2017, 06:26
0
В середине недели где то начну делать.
avatar

AM2

  • 7 января 2017, 21:53