0
//+------------------------------------------------------------------+
//|                                                           17.mq4 |
//|                                                               gi |
//|                                                                  |
//+------------------------------------------------------------------+
//|анализ всех ордеров на наличие подходяих                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+


#property copyright "gi"
#property link      ""
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
input   int Dist_TP=11;                              // Заданный TP (pt)
input   double Lot=0.01;                          // Лоты
input   string CM = "Expert Name";
input   int MN = 123;
//+------------------------------------------------------------------+
double Old_Price;                   // Ценa (Bid,округленная)
double Price;                     // Цены открываемых ордеров
double TP;                        // Цены ТР
int dig;                     // к-во знаков при округлении 3 или 1
int i,k,l,p,r;
double Poin;                     // Вес пункта (для TP)
string Symb;                        // Финанс. инструмент
string Order_Tip[4];
int Order_Type;
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//   Alert ("Начинаем-----------------------------");
   Symb=Symbol();
   dig=Digits-1;
   Poin=Point;
   if(dig==2 || dig==4)
     {
      dig--;
      Poin*=10;
     }
//   Order_Type[] = {2,4,3,5};         // Типы устанавлтваемых ордеров:
//   2-байлимит, 4-байстоп, 3-селл лимит,5- селл стоп
//   Order_Tip[4] = {"BUYLIMIT","BUYSTOP","SELLLIMIT","SELLSTOP"};

//---
   return(0);
  }
//--------------------------------------------------------------- 1 --
void OnTick() // Спец.функция OnTick
  {
//+------------------------------------------------------------------+
// Alert("tik!");
//+------------------------------------------------------------------+
   Old_Price=NormalizeDouble(Bid,dig); // Округление цены 
   double Price_Minus=Old_Price-10*Poin;
   double Price_Plus=Old_Price+10*Poin;
   int Flag[4]={0,0,0,0};                // Выставляем флаги необходимости открытия ордеров
   l=0;//к-во проанализированных ордеров
   p=0;//результат анализа цены открытия ордера 1 при-10, 2 при +10,0- иначе
   r=0;
   int Ord_Tot=OrdersTotal();                 // Всего ордеров
//--------------------------------------------------------------- 2 --
   for(k=1; k<=Ord_Tot; k++) // Цикл перебора ордер
     {
      if((Flag[0]+Flag[1]+Flag[2]+Flag[3])==4) break;                     // Найдены все 4 ордера 
      if(OrderSelect(k-1,SELECT_BY_POS)==true) // Если есть следующий
        {                                       // Анализ ордеров:                         
         l++;
         string Ord_Sy=OrderSymbol();
         if(Ord_Sy!=Symb) continue;    // Не наш фин.инструм.
         int Tip=OrderType();                   // Тип ордера
         double Open_Price=NormalizeDouble(OrderOpenPrice(),dig); // Цена открытия анализируемого ордера
         p=GI_01(Open_Price,Price_Minus,Price_Plus);
         if(p==0)continue;
         r++;     // Есть подходящая цена
         if(p==1 && (Tip==0 || Tip==2)) // Ордер BuyLimit не нужен
           {
            Flag[0]=1;
            //               Alert("Ордер BuyLimit не нужен");
            continue;
           }
         if(p==1 && (Tip==1 || Tip==5)) // Ордер SellStop не нужен
           {
            Flag[3]=1;
            //             Alert("Ордер SellStop не нужен"); 
            continue;
           }
         if(p==2 && (Tip==0 || Tip==4))
           {
            Flag[1]=1;
            //             Alert("Ордер BuyStop не нужен");      // Ордер BuyStop не нужен
            continue;
           }
         if(p==2 && (Tip==1 || Tip==3)) // Ордер SellLimit не нужен
           {
            Flag[2]=1;
            //               Alert("Ордер SellLimit не нужен"); 
           }
        }

     }                                          //Конец перебора орд.
//---------------------------------------------------------  --
// При необходимости отдаем приказы на открытие
// и фиксируем исполнение
//---------------------------------------------------------  --
   for(i=0;i<=3;i++)
     {
      if(Flag[i]==0)
        {
         // Вычисляем цены открытия и профиты ордеров
         switch(i)
           {
            case 0: Price=Old_Price-10*Poin;
            TP=Old_Price+(Dist_TP-10)*Poin;
            Order_Type=2;
            break;
            case 1: Price=Old_Price+10*Poin;
            TP=Old_Price+(Dist_TP+10)*Poin;
            Order_Type=4;
            break;
            case 2: Price=Old_Price+Dist_TP*Poin;
            TP=Old_Price;
            Order_Type=3;
            break;
            case 3: Price=Old_Price+(Dist_TP-20)*Poin;
            TP=Old_Price-20*Poin;
            Order_Type=5;
           }
         //            Alert("Торговый приказ отправлен на сервер ",Order_Tip[i],"  ",Price,"  ",TP);
         int ticket=OrderSend(Symb,Order_Type,Lot,Price,0,0,TP,CM,MN);
         //--------------------------------------------------------- 7 --
         //            if (ticket>0)                             // Получилось <img src='http://opentraders.ru/templates/skin/g6h/images/smilies/002.gif' alt=' :) '> 
         //              {
         //               Alert ("Установлен ордер  ",ticket," Цена ",Price," Профит ",TP);
         //             }                                 
        }
     }
//-------------------------------------------------------------- 10 --
//   Alert (" закончил работу -----------------------------");
   return;                                      // Выход из OnTick
  }
//--------------------------------------------------------------- 1 --
int GI_01(double a,double b,double c)
//+------------------------------------------------------------------+
//|сравнение a b c   с точностью до 0.00004                                                 |
//|возвращает 1, если a=b                                            |
//|           2       a=c                                            |
//|           0 - иначе                                              |
//+------------------------------------------------------------------+
  {
   int d=0;
   if(MathAbs(a-b)<0.0001) d=1;
   else if(MathAbs(a-c)<0.0001) d=2;
   return(d);
  }
//+------------------------------------------------------------------+
avatar

AM2

  • 14 сентября 2017, 22:09
0
В четверг на следующей неделе смотреть буду. Заказов много.
avatar

AM2

  • 13 сентября 2017, 22:40
0
Нужно чтобы получился тест с почти ровный и немножко в профите.

Так и получается после оптимизации:



Еще мартин не работает как нужно местами не увеличивает лот

Увеличение лота ограничено переменной макслот. Добавил БУ еще.


//+------------------------------------------------------------------+
//|                                                       MASafe.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 double Lots      = 0.1;
extern double KLot      = 2;
extern double MaxLot    = 5;
extern int StopLoss     = 1200;
extern int TakeProfit   = 1400;
extern int TrailingStop = 300;
extern int BULevel      = 0;      
extern int BUPoint      = 30;       
extern int Slip         = 50;
extern int MA1Period    = 9;
extern int MA2Period    = 22;
extern int Magic        = 123;

datetime t=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 Trailing()
  {
   bool mod;
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(TrailingStop>0)
                 {
                  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(TrailingStop>0)
                 {
                  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);
      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;
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void OpenPos()
  {
   double ma11=iMA(NULL,0,MA1Period,0,0,0,1);
   double ma21=iMA(NULL,0,MA2Period,0,0,0,1);
   double ma12=iMA(NULL,0,MA1Period,0,0,0,2);
   double ma22=iMA(NULL,0,MA2Period,0,0,0,2);

//---- buy 
   if(ma11>ma21 && ma12<ma22)
     {
      PutOrder(0,Ask);
     }
//---- sell   
   if(ma11<ma21 && ma12>ma22)
     {
      PutOrder(1,Bid);
     }
  }
//+------------------------------------------------------------------+
//| Лот для усреднителя                                              |
//+------------------------------------------------------------------+
double Lot()
  {
   double lot=Lots;
   double MinimumLot = MarketInfo(NULL,MODE_MINLOT);
   double MaximumLot = MarketInfo(NULL,MODE_MAXLOT);

   lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades()),2);
   if(lot<MinimumLot) lot=MinimumLot;
   if(lot>MaximumLot) lot=MaximumLot;
   if(lot>MaxLot)lot=Lots;

   return(lot);
  }
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(t!=Time[0])
     {
      OpenPos();
      t=Time[0];
     }

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

avatar

AM2

  • 13 сентября 2017, 21:30
0
через пару недель где то будет.
поручителя также можете найти: project.opentraders.ru/20424.html
avatar

AM2

  • 13 сентября 2017, 20:04
0
В сигму добавил: www.opentraders.ru/downloads/1117/

avatar

AM2

  • 13 сентября 2017, 19:55
0
А где индикаторы от брикволкера?

2017.09.13 20:27:18.377 2017.01.16 19:00:00 cannot open file 'D:\Program Files\Alpari Limited MT4\MQL4\indicators\4D — Range Switch.ex4' [2]
2017.09.13 20:27:18.373 2017.01.16 18:45:00 cannot open file 'D:\Program Files\Alpari Limited MT4\MQL4\indicators\Waddah_Attar_Explosion.ex4' [2]

avatar

AM2

  • 13 сентября 2017, 19:28
0
Пока на неделю вперед все расписано. Поэтому не раньше следующей среды смотреть буду.
avatar

AM2

  • 13 сентября 2017, 19:23
0
Просьба пояснить все на скринах.
avatar

AM2

  • 13 сентября 2017, 17:40
0
Основу набросал теперь поясняйте подробнее со скринами:


//+------------------------------------------------------------------+
//|                                                       MASafe.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 double Lots      = 0.1;
extern double KLot      = 2;
extern double MaxLot    = 5;
extern int StopLoss     = 1200;
extern int TakeProfit   = 1400;
extern int TrailingStop = 300;
extern int Slip         = 50;
extern int MA1Period    = 9;
extern int MA2Period    = 22;
extern int Magic        = 123;

datetime t=0;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 Trailing()
  {
   bool mod;
   for(int i=0; i<OrdersTotal(); i++)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==OP_BUY)
              {
               if(TrailingStop>0)
                 {
                  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(TrailingStop>0)
                 {
                  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,0,clr);
   return;
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void OpenPos()
  {
   double ma11=iMA(NULL,0,MA1Period,0,0,0,1);
   double ma21=iMA(NULL,0,MA2Period,0,0,0,1);
   double ma12=iMA(NULL,0,MA1Period,0,0,0,2);
   double ma22=iMA(NULL,0,MA2Period,0,0,0,2);

//---- buy 
   if(ma11>ma21 && ma12<ma22)
     {
      PutOrder(0,Ask);
     }
//---- sell   
   if(ma11<ma21 && ma12>ma22)
     {
      PutOrder(1,Bid);
     }
  }
//+------------------------------------------------------------------+
//| Лот для усреднителя                                              |
//+------------------------------------------------------------------+
double Lot()
  {
   double lot=Lots;
   double MinimumLot = MarketInfo(NULL,MODE_MINLOT);
   double MaximumLot = MarketInfo(NULL,MODE_MAXLOT);

   lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades()),2);
   if(lot<MinimumLot) lot=MinimumLot;
   if(lot>MaximumLot) lot=MaximumLot;
   if(lot>MaxLot)lot=Lots;

   return(lot);
  }
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(t!=Time[0])
     {
      OpenPos();
      t=Time[0];
     }

   if(TrailingStop!=0) Trailing();
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 12 сентября 2017, 20:05
0
Через неделю только буду смотреть.
avatar

AM2

  • 12 сентября 2017, 18:01
0
Нужно подробнее и со скринами.
avatar

AM2

  • 11 сентября 2017, 21:53
0
Очень непростая доработка. Смотреть буду не раньше следующей недели. Очередь.
avatar

AM2

  • 11 сентября 2017, 18:49
0
В пятницу только доберусь и еще надо смотреть будет есть ли от него сигнал.
avatar

AM2

  • 11 сентября 2017, 17:32
0
В четверг буду смотреть.
avatar

AM2

  • 11 сентября 2017, 17:29
Начать торговлю с Альпари