0
Пока так, дальше если будет свободное время. На бесплатном не придумывайте ничего лишнего, чем проще будет задание тем больше у вас шансов получить его в готовом виде.


//+------------------------------------------------------------------+
//|                                                   CandleSize.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
#property indicator_chart_window

input int Max = 10;
input int Min = 3;
input int Points=30;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0,0,OBJ_RECTANGLE);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutRect(string name,datetime t1,double p1,datetime t2,double p2,color clr)
  {
   ObjectDelete(0,name);
//--- создадим прямоугольник по заданным координатам
   ObjectCreate(0,name,OBJ_RECTANGLE,0,t1,p1,t2,p2);
//--- установим цвет прямоугольника
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   for(int i=1;i<5555;i++)
     {
      if(MathAbs(close[i+1]-open[i+1])/MathAbs(close[i+2]-open[i+2])>=Min     // свеча 2 больше свечи 3 в 3 раза
         && MathAbs(close[i+1]-open[i+1])/MathAbs(close[i+2]-open[i+2])<=Max  // свеча 2 больше свечи 3 в 3 раза но меньше чем 10 раз
         && MathAbs(close[i+2]-open[i+2])>Points*Point                        // свеча 3 бльше 30 пунктов
         && MathAbs(close[i]-open[i])>Points*Point                            // свеча 1 бльше 30 пунктов
         && MathAbs(close[i+2]-open[i+1])<10*Points                           // закрытие 3-й минус открытие 2-й меньше 10п.
         && MathAbs(close[i+1]-open[i])<10*Points                             // закрытие 2-й минус открытие 1-й меньше 10п.                      
         )
         //&& (((close[i+1]-open[i+1])>0 && (close[i]-open[i])>0)||((close[i+1]-open[i+1])>0 && (close[i]-open[i])>0))// сонапрвлены
         PutRect("Rect"+time[i],time[i],open[i],time[i+2],close[i+2],Red);
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 17 сентября 2016, 20:52
0
Сделаны следующие условия для 3-х свечей:


 // свеча 2 больше свечи 3 в 3 раза
 // свеча 2 больше свечи 3 в 3 раза но меньше чем 10 раз
 // свеча 3 больше 30 пунктов
 // свеча 1 больше 30 пунктов





//+------------------------------------------------------------------+
//|                                                   CandleSize.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
#property indicator_chart_window

input int Max = 10;
input int Min = 3;
input int Points=30;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0,0,OBJ_RECTANGLE);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutRect(string name,datetime t1,double p1,datetime t2,double p2,color clr)
  {
   ObjectDelete(0,name);
//--- создадим прямоугольник по заданным координатам
   ObjectCreate(0,name,OBJ_RECTANGLE,0,t1,p1,t2,p2);
//--- установим цвет прямоугольника
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   for(int i=1;i<5555;i++)
     {
      if(MathAbs(close[i+1]-open[i+1])/MathAbs(close[i+2]-open[i+2])>=Min     // свеча 2 больше свечи 3 в 3 раза
         && MathAbs(close[i+1]-open[i+1])/MathAbs(close[i+2]-open[i+2])<=Max  // свеча 2 больше свечи 3 в 3 раза но меньше чем 10 раз
         && MathAbs(close[i+2]-open[i+2])>Points*Point                        // свеча 3 бльше 30 пунктов
         && MathAbs(close[i]-open[i])>Points*Point)                           // свеча 1 бльше 30 пунктов

         PutRect("Rect"+time[i],time[i],open[i],time[i+2],close[i+2],Red);
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+



Могу еще добавить парочку условий на выбор, если все целиком нужно к платному.
avatar

AM2

  • 17 сентября 2016, 20:09
0
Пока сделано для двух свечей и есть 2 условия.

1. тело первой свечи в 3 раза больше тела второй.
2. тело второй свечи больше 30 п.




//+------------------------------------------------------------------+
//|                                                   CandleSize.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
#property indicator_chart_window

input int Max = 10;
input int Min = 3;
input int Points = 30;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectsDeleteAll(0,0,OBJ_RECTANGLE);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutRect(string name,datetime t1,double p1,datetime t2,double p2,color clr)
  {
   ObjectDelete(0,name);
//--- создадим прямоугольник по заданным координатам
   ObjectCreate(0,name,OBJ_RECTANGLE,0,t1,p1,t2,p2);
//--- установим цвет прямоугольника
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   for(int i=1;i<5555;i++)
     {
      if(MathAbs(close[i]-open[i])/MathAbs(close[i+1]-open[i+1])>Min  // 
       && MathAbs(close[i+1]-open[i+1])>Points*Point)                 //
       
       PutRect("Rect"+time[i],time[i],open[i+1],time[i+1],close[i],Red);
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 17 сентября 2016, 19:44
0
Я начал делать, только скиньте все ТЗ в одно место чтобы мне не прыгать туда сюда.
avatar

AM2

  • 17 сентября 2016, 19:36
+1
Только сейчас заметил сообщение. Топик опубликовал: mql.opentraders.ru/34960.html
Надеюсь сохранится :) 
avatar

AM2

  • 17 сентября 2016, 15:57
0
После выходных посмотрю.
avatar

AM2

  • 17 сентября 2016, 14:00
0
Посмотрите как работает и пока есть свободное время могу еще 1-2 пункта добавить из ТЗ. Только подробнее опишите а то там каша.
avatar

AM2

  • 16 сентября 2016, 17:24
0
И добавил закрытие положительных и удаление отложенных ордеров после указанного времени. Ну и все для бесплатного заказа объем работы выполнен, уже весь код сюда не лезет :D 
www.opentraders.ru/downloads/1319/

avatar

AM2

  • 16 сентября 2016, 10:27
0
Стопы ордеров на границах коробки, тейк первого на открытии второго, тп второго задаваемый:




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

//--- Inputs
extern double Lots        = 0.1;      // лот
extern double KLot        = 1;        // умножение лота
extern double MaxLot      = 5;        // максимальный лот
extern double TargetLevel = 161.8;    // уровень 
extern int StopLoss       = 300;      // лось
extern int TakeProfit     = 700;      // язь
extern int TrailingStop   = 35;       // трал
extern int Expiration     = 10;       // истечение ордера
extern int Delta          = 100;      // дельта
extern int Slip           = 30;       // реквот
extern int Magic          = 123;      // магик

extern string Start       = "00:00";  // начало коробки
extern string End         = "8:00";   // конец коробки

datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Comment("");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lot()
  {
   double lot=Lots;

   if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
     {
      if(OrderProfit()<0)
        {
         lot=OrderLots()*KLot;
        }
     }
   if(lot>MaxLot)lot=Lots;
   return(lot);
  }
//+------------------------------------------------------------------+
//| Простой трал                                                     |
//+------------------------------------------------------------------+
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,double sl,double tp)
  {
   int r=0;
   color clr=Green;

   if(type==1 || type==3 || type==5)
     {
      clr=Red;
     }

   if(type==0 || type==2 || type==4)
     {
      clr=Blue;
     }

   r=OrderSend(NULL,type,Lot(),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);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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);
  }
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров                                      |
//+------------------------------------------------------------------+
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 PutRect(string name,datetime t1,double p1,datetime t2,double p2,color clr)
  {
   ObjectDelete(0,name);
//--- создадим прямоугольник по заданным координатам
   ObjectCreate(0,name,OBJ_RECTANGLE,0,t1,p1,t2,p2);
//--- установим цвет прямоугольника
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int EndBar=iBarShift(NULL,0,StringToTime(End));
   int StartBar=iBarShift(NULL,0,StringToTime(Start));
   int DeltaBars=MathAbs(StartBar-EndBar);
   double h = High[iHighest(NULL,0,MODE_HIGH,DeltaBars+1,EndBar)]+Delta*Point;
   double l = Low[iLowest(NULL,0,MODE_LOW,DeltaBars+1,EndBar)]-Delta*Point;
   double h2=(h-l)*(TargetLevel-100)/100+h;
   double l2=l-(h-l)*(TargetLevel-100)/100;
   double st=0,tk=0;

   if(TrailingStop>0) Trailing();

   if(TimeCurrent()>StringToTime(End) && CountTrades()<1)
     {
      PutRect("Rect",Time[EndBar],l,Time[StartBar],h,Blue);
      if(CountOrders(4)<1 && Bid<h)
        {
         st=NormalizeDouble(l,Digits);
         tk=NormalizeDouble(h2,Digits);
         PutOrder(4,h,st,tk);
         tk=NormalizeDouble(h2+TakeProfit*Point,Digits);
         PutOrder(4,h2,st,tk);
        }
        
      if(CountOrders(5)<1 && Bid>l)
        {
         st=NormalizeDouble(h,Digits);
         tk=NormalizeDouble(l2,Digits);
         PutOrder(5,l,st,tk);
         tk=NormalizeDouble(l2-TakeProfit*Point,Digits);
         PutOrder(5,l2,st,tk);
        }
     }

   Comment("\n End: ",iBarShift(NULL,0,StringToTime(End)),
           "\n Start: ",iBarShift(NULL,0,StringToTime(Start)));
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 16 сентября 2016, 10:09
0
Ставит ордера на 2 уровня:




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

//--- Inputs
extern double Lots        = 0.1;      // лот
extern double KLot        = 1;        // умножение лота
extern double MaxLot      = 5;        // максимальный лот
extern double TargetLevel = 161.8;    // уровень 
extern int StopLoss       = 300;      // лось
extern int TakeProfit     = 700;      // язь
extern int TrailingStop   = 35;       // трал
extern int Expiration     = 10;       // истечение ордера
extern int Delta          = 100;      // дельта
extern int Slip           = 30;       // реквот
extern int Magic          = 123;      // магик

extern string Start       = "00:00";  // начало коробки
extern string End         = "8:00";   // конец коробки

datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Comment("");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lot()
  {
   double lot=Lots;

   if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
     {
      if(OrderProfit()<0)
        {
         lot=OrderLots()*KLot;
        }
     }
   if(lot>MaxLot)lot=Lots;
   return(lot);
  }
//+------------------------------------------------------------------+
//| Простой трал                                                     |
//+------------------------------------------------------------------+
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,Lot(),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);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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);
  }
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров                                      |
//+------------------------------------------------------------------+
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 PutRect(string name,datetime t1,double p1,datetime t2,double p2,color clr)
  {
   ObjectDelete(0,name);
//--- создадим прямоугольник по заданным координатам
   ObjectCreate(0,name,OBJ_RECTANGLE,0,t1,p1,t2,p2);
//--- установим цвет прямоугольника
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int EndBar=iBarShift(NULL,0,StringToTime(End));
   int StartBar=iBarShift(NULL,0,StringToTime(Start));
   int DeltaBars=MathAbs(StartBar-EndBar);
   double h = High[iHighest(NULL,0,MODE_HIGH,DeltaBars+1,EndBar)]+Delta*Point;
   double l = Low[iLowest(NULL,0,MODE_LOW,DeltaBars+1,EndBar)]-Delta*Point;
   double h2=(h-l)*(TargetLevel-100)/100+h;
   double l2=l-(h-l)*(TargetLevel-100)/100;

   if(TrailingStop>0) Trailing();

   if(TimeCurrent()>StringToTime(End) && CountTrades()<1)
     {
      PutRect("Rect",Time[EndBar],l,Time[StartBar],h,Blue);
      if(CountOrders(4)<1 && Bid<h)
        {
         PutOrder(4,h);
         PutOrder(4,h2);
        }
      if(CountOrders(5)<1 && Bid>l)
        {
         PutOrder(5,l);
         PutOrder(5,l2);
        }
     }

   Comment("\n End: ",iBarShift(NULL,0,StringToTime(End)),
           "\n Start: ",iBarShift(NULL,0,StringToTime(Start)));
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 16 сентября 2016, 09:46
0
Вроде бы сдвинулось с мертвой точки, пока самый простой вариант:




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

//--- Inputs
extern double Lots       = 0.1;      // лот
extern double KLot       = 1;        // умножение лота
extern double MaxLot     = 5;        // максимальный лот
extern int StopLoss      = 300;      // лось
extern int TakeProfit    = 700;      // язь
extern int TrailingStop  = 35;       // трал
extern int Expiration    = 10;       // истечение ордера
extern int Delta         = 100;      // дельта
extern int Slip          = 30;       // реквот
extern int Magic         = 123;      // магик

extern string Start      = "00:00";  // начало коробки
extern string End        = "8:00";   // конец коробки

datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Comment("");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lot()
  {
   double lot=Lots;

   if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
     {
      if(OrderProfit()<0)
        {
         lot=OrderLots()*KLot;
        }
     }
   if(lot>MaxLot)lot=Lots;
   return(lot);
  }
//+------------------------------------------------------------------+
//| Простой трал                                                     |
//+------------------------------------------------------------------+
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,Lot(),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);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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);
  }
//+------------------------------------------------------------------+
//| Удаление отложенных ордеров                                      |
//+------------------------------------------------------------------+
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 PutRect(string name,datetime t1,double p1,datetime t2,double p2,color clr)
  {
   ObjectDelete(0,name);
//--- создадим прямоугольник по заданным координатам
   ObjectCreate(0,name,OBJ_RECTANGLE,0,t1,p1,t2,p2);
//--- установим цвет прямоугольника
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   int EndBar=iBarShift(NULL,0,StringToTime(End));
   int StartBar=iBarShift(NULL,0,StringToTime(Start));
   int DeltaBars=MathAbs(StartBar-EndBar);
   double h = High[iHighest(NULL,0,MODE_HIGH,DeltaBars+1,EndBar)];
   double l = Low[iLowest(NULL,0,MODE_LOW,DeltaBars+1,EndBar)];

   if(TrailingStop>0) Trailing();

   if(TimeCurrent()>StringToTime(End) && CountTrades()<1)
     {
      PutRect("Rect",Time[EndBar],l,Time[StartBar],h,Blue);
      if(CountOrders(4)<1 && Bid<h) PutOrder(4,h+Delta*Point);
      if(CountOrders(5)<1 && Bid>l)PutOrder(5,l-Delta*Point);
     }

   Comment("\n End: ",iBarShift(NULL,0,StringToTime(End)),
           "\n Start: ",iBarShift(NULL,0,StringToTime(Start)));
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 16 сентября 2016, 09:08
0
Очень клево!!! Но что то с друн=гих сайтов ерунду выдает


Только вчера с инвестинг котировки вытаскивал. С лмакс напрямую не получилось.

А подскажите как сделать задержку опроса сайта, например столько то секунд?


Sleep(5000);
попробуйте

avatar

AM2

  • 16 сентября 2016, 08:26
0
Напрямую уровни из индикатора не получить, если получится восстановить уровни по формулам из индикатора, тогда может что то и нарисуется.
avatar

AM2

  • 16 сентября 2016, 08:14
0
Очень достойный сигнал: прибыль 4135% за 1.5 года, просадка 5%, все месяцы в плюсе, 423 подписчика, полтора ляма средств подписчиков.
www.mql5.com/ru/signals/207112
avatar

AM2

  • 14 сентября 2016, 19:50
0
Примерно так: www.opentraders.ru/downloads/1316/



//+------------------------------------------------------------------+
//|                                                     MACD_MOD.mq4 |
//|                                              Copyright 2016, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2016, AM2"
#property link      "http://www.forexsystems.biz"
#property description "Moving Averages Convergence/Divergence"
#property strict

#include <MovingAverages.mqh>

//--- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 4
#property  indicator_color1  Red
#property  indicator_color2  Blue
#property  indicator_color3  clrNONE
#property  indicator_color4  Red
#property  indicator_width1  2
#property  indicator_width2  2
#property  indicator_width3  1
#property  indicator_width4  1
//--- indicator parameters
input int InpFastEMA=12;   // Fast EMA Period
input int InpSlowEMA=26;   // Slow EMA Period
input int InpSignalSMA=9;  // Signal SMA Period
//--- indicator buffers
double    MRed[];
double    MBlue[];
double    Macd[];
double    MSig[];
//--- right input parameters flag
bool      ExtParameters=true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit(void)
  {
   IndicatorDigits(Digits+1);
//--- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM);
   SetIndexStyle(1,DRAW_HISTOGRAM);
   SetIndexStyle(2,DRAW_HISTOGRAM);
   SetIndexStyle(3,DRAW_LINE);
//--- indicator buffers mapping
   SetIndexBuffer(0,MRed);
   SetIndexBuffer(1,MBlue);
   SetIndexBuffer(2,Macd);
   SetIndexBuffer(3,MSig);
//--- name for DataWindow and indicator subwindow label
   IndicatorShortName("MACD_MOD("+IntegerToString(InpFastEMA)+","+IntegerToString(InpSlowEMA)+","+IntegerToString(InpSignalSMA)+")");
   SetIndexLabel(0,"MACD");
   SetIndexLabel(1,"MACD");
   SetIndexLabel(2,"MACD");
   SetIndexLabel(3,"Signal");
//--- check for input parameters
   if(InpFastEMA<=1 || InpSlowEMA<=1 || InpSignalSMA<=1 || InpFastEMA>=InpSlowEMA)
     {
      Print("Wrong input parameters");
      ExtParameters=false;
      return(INIT_FAILED);
     }
   else
      ExtParameters=true;
//--- initialization done
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Moving Averages Convergence/Divergence                           |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int i,limit;
//---
   if(rates_total<=InpSignalSMA || !ExtParameters)
      return(0);
//--- last counted bar will be recounted
   limit=rates_total-prev_calculated;
   if(prev_calculated>0)
      limit++;
//--- macd counted in the 1-st buffer
   for(i=0; i<limit; i++)
     {
      double macd=iMA(NULL,0,InpFastEMA,0,1,0,i)-iMA(NULL,0,InpSlowEMA,0,1,0,i);
      double macd1=iMA(NULL,0,InpFastEMA,0,1,0,i+1)-iMA(NULL,0,InpSlowEMA,0,1,0,i+1);
      
      Macd[i]=macd;

      if(macd>macd1 && macd>0) MRed[i]=macd;
      if(macd<macd1 && macd>0) MBlue[i]=macd;

      if(macd>macd1 && macd<0) MRed[i]=macd;
      if(macd<macd1 && macd<0) MBlue[i]=macd;
     }
//--- signal line counted in the 2-nd buffer
   SimpleMAOnBuffer(rates_total,prev_calculated,0,InpSignalSMA,Macd,MSig);
//--- done
   return(rates_total);
  }
//+------------------------------------------------------------------+
avatar

AM2

  • 14 сентября 2016, 12:44
0
Посмотрю вечером.
avatar

AM2

  • 14 сентября 2016, 12:17
0
И мой вариант <img src='http://opentraders.ru/templates/skin/g6h/images/smilies/002.gif' alt=' :) '>&nbsp;  www.opentraders.ru/downloads/1316/



avatar

AM2

  • 14 сентября 2016, 02:22
0
А чем не устраивает цветной макди ма? Там достаточно поменять цвет в настройках и будет как у вас на скрине.


#property  indicator_color1  Blue
#property  indicator_color2  Green
#property  indicator_color3  Red


avatar

AM2

  • 14 сентября 2016, 01:25
0
С CPositionInfo:


//+------------------------------------------------------------------+
//|                                                   HelloSmart.mq5 |
//|                                              Copyright 2016, AM2 | 
//|                                     https://www.forexsystems.biz | 
//+------------------------------------------------------------------+ 
#property copyright "Copyright 2016, AM2" 
#property link "https://www.forexsystems.biz" 
#property version "1.00" 

#include <Trade\Trade.mqh> 
#include <Trade\PositionInfo.mqh>   

CTrade trade;
CPositionInfo pos;

input int BuySell     = 2;    // 1-Only Buy 2-Only Sell
input int Step        = 1000; // Step
input double Lot      = 0.1;  // Volume
input double BigLot   = 1;    // Big Lot
input double MaxLots  = 5;    // Maximum lot
input double Profit   = 60;   // Dollars Profit 
input double Loss     = 5100; // Dollars Loss
input double Mnogitel = 3;    // Lots Mnogitel 

int bars=0;
double lot=Lot,pr=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//|  Position Profit                                                 |
//+------------------------------------------------------------------+
double SymbProfit(string Symb)
  {
   double p=0;
   for(int i=PositionsTotal()-1;i>=0;i--)
     {
      if(pos.Select(Symb))
        {
         p+=pos.Profit();
        }
     }
   return(p);
  }
//+------------------------------------------------------------------+
//|  Position Volume                                                 |
//+------------------------------------------------------------------+
double Lots(string Symb)
  {
   double lots=0;

   for(int i=PositionsTotal()-1;i>=0;i--)
     {
      if(pos.Select(Symb))
        {
         lots+=pos.Volume();
        }
     }
   return(lots);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CloseAll(string symb)
  {
   for(int i=PositionsTotal()-1;i>=0;i--)
     {
      if(pos.Select(symb))
        {
         trade.PositionClose(symb);
        }
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   string symb=Symbol();
   double Ask=SymbolInfoDouble(symb,SYMBOL_ASK);
   double Bid=SymbolInfoDouble(symb,SYMBOL_BID);

   if(bars!=Bars(symb,0))
     {
      if(BuySell==1 && (PositionsTotal()<1 || (PositionsTotal()>0 && (pr-Ask)/_Point>=Step))) {trade.PositionOpen(symb,0,lot,Ask,0,0); pr=Bid;}//buy
      if(BuySell==2 && (PositionsTotal()<1 || (PositionsTotal()>0 && (Bid-pr)/_Point>=Step))) {trade.PositionOpen(symb,1,lot,Bid,0,0); pr=Bid;}//sell

      if(Lots(symb)>=BigLot) lot=lot*Mnogitel;
      if(lot>MaxLots) lot=Lot;

      if(SymbProfit(symb)>Profit || SymbProfit(symb)<-Loss) {CloseAll(symb); lot=Lot;}
      bars=Bars(symb,0);
     }

   Comment("\n Lots: ",Lots(symb),
           "\n Profit: ",SymbProfit(symb),
           "\n Price: ",pr);
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 13 сентября 2016, 15:33