Группа "Стол заказов MQL"

Рейтинг 2087



РЕКОМЕНДУЮ



Прошу доработать советник TrendWave

Хотелось бы проверить, как будет работать вариант, если поставить закрытие по тейк профит обшим в пунктах, как у илана. Если можно то сделайте пожалуйста. Ну и конечно чтобы закрывалось как в бай так и в сел отдельно.
Есть советник в столе заказов
zakaz.opentraders.ru/31618.html
  • 0
  • Просмотров: 2663
  • 18 апреля 2016, 01:31
  • cashyra
Понравилcя материал? Не забудьте поставить плюс и поделиться в социальной сети!

Вступите в группу "Стол заказов MQL", чтобы следить за обновлениями
ПРИСОЕДИНИТЬСЯ К ГРУППЕ
присоединиться
  Предыдущая запись в группе
новостной советник
17 апреля 2016
18 апреля 2016

Комментарии (9)

+
0
настырный*good* 
avatar

  13  Jora1973 Сообщений: 114

  • 18 апреля 2016, 01:33
+
0
Не для себя стараюсь, для народа.
avatar

  15  cashyra Автор Сообщений: 392 - Юра

  • 18 апреля 2016, 09:12
+
0
Здесь будет уже совсем другой советник, у вас в этом месяце есть заказ. В следующем опишите подробно ТЗ, а то что вы написали слишком расплывчато.
avatar

  34  AM2 Сообщений: 15879 - Андрей

  • 18 апреля 2016, 09:13
+
0
Просто добавить закрытие по обшему тейк профиту как у илана, вот и всё. А то он сейчас ставит на каждый ордер отдельно ТП, а нужно чтобы он модифицировался в общий ТП как это делает Илан.
avatar

  15  cashyra Автор Сообщений: 392 - Юра

  • 18 апреля 2016, 09:20
+
0
Это вам только кажется что все просто, а на самом деле нужно перекраивать всю логику советника.
avatar

  34  AM2 Сообщений: 15879 - Андрей

  • 18 апреля 2016, 09:34
+
0
Спасибо что не отказали, буду ждать следующего месяца.
avatar

  15  cashyra Автор Сообщений: 392 - Юра

  • 18 апреля 2016, 09:36
+
0
avatar

  34  AM2 Сообщений: 15879 - Андрей

  • 18 апреля 2016, 10:24
+
0
Это максимально упрощенный вариант, с илановской логикой.


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

//--- Inputs
extern double Lots       = 0.1;      // лот
extern double KLot       = 2;        // умножение лота
extern double MaxLot     = 5;        // максимальный лот
extern int StopLoss      = 2000;     // лось
extern int TakeProfit    = 3000;     // язь
extern int WavePeriod    = 10;       // TrendWave - WavePeriod
extern int AvgPeriod     = 21;       // TrendWave - AvgPeriod
extern int Slip          = 30;       // Проскальзывание цены
extern int Reverce       = 0;        // 1-реверс
extern int BuyMagic      = 111;      // buy магик 
extern int SellMagic     = 222;      // sell магик 

extern string IndName="TrendWave";

datetime t=0;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
  {
   int r=0,magic=0;
   color clr=Green;
   double sl=0,tp=0;

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

   r=OrderSend(NULL,type,Lot(type),NormalizeDouble(price,Digits),Slip,sl,tp,"",magic,0,clr);
   return;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CountTrades(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()==BuyMagic || OrderMagicNumber()==SellMagic))
           {
            if(OrderType()==type) count++;
           }
        }
     }
   return(count);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ClosePos(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()==BuyMagic || OrderMagicNumber()==SellMagic))
           {
            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 ModifyOrders()
  {
   double allb=0,alls=0;
   double countb=0,counts=0,tp=0,sl=0;

   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==0 && OrderMagicNumber()==BuyMagic)
              {
               allb+=OrderOpenPrice()*OrderLots();
               countb+=OrderLots();
              }
              
            if(OrderType()==1 && OrderMagicNumber()==SellMagic)
              {
               alls+=OrderOpenPrice()*OrderLots();
               counts+=OrderLots();
              }              
           }
        }
     }
   if(countb>0) allb=NormalizeDouble(allb/countb,Digits);
   if(counts>0) alls=NormalizeDouble(alls/counts,Digits);

   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==OP_BUY && OrderMagicNumber()==BuyMagic)
              {
               if(TakeProfit>0) tp=NormalizeDouble(allb+TakeProfit*Point,Digits);
               if(StopLoss>0)   sl=NormalizeDouble(allb-StopLoss*Point,Digits);
               if(OrderTakeProfit()!=tp || OrderStopLoss()!=sl)
                  bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
              }
            else
            if(OrderType()==OP_SELL  && OrderMagicNumber()==SellMagic)
              {
               if(TakeProfit>0) tp=NormalizeDouble(alls-TakeProfit*Point,Digits);
               if(StopLoss>0)   sl=NormalizeDouble(alls+StopLoss*Point,Digits);
               if(OrderTakeProfit()!=tp || OrderStopLoss()!=sl)
                  bool mod=OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,Yellow);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lot(int type)
  {
   double lot=Lots;
   if(CountTrades(type)>0) lot=NormalizeDouble(Lots*MathPow(KLot,CountTrades(type)),2);
   if(lot>MaxLot)lot=Lots;
   return(lot);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OpenPos()
  {
   double buy  = iCustom(NULL,0,IndName,WavePeriod,AvgPeriod,6,1);
   double sell = iCustom(NULL,0,IndName,WavePeriod,AvgPeriod,7,1);

   if(buy>-1000)
     {
      PutOrder(0,Ask);
     }
   if(sell>-1000)
     {
      PutOrder(1,Bid);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void RevercePos()
  {
   double buy  = iCustom(NULL,0,IndName,WavePeriod,AvgPeriod,6,1);
   double sell = iCustom(NULL,0,IndName,WavePeriod,AvgPeriod,7,1);

   if(buy>-1000)
     {
      PutOrder(1,Bid);
     }
   if(sell>-1000)
     {
      PutOrder(0,Ask);
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double buy  = iCustom(NULL,0,IndName,WavePeriod,AvgPeriod,6,1);
   double sell = iCustom(NULL,0,IndName,WavePeriod,AvgPeriod,7,1);

   if(t!=Time[0])
     {
      if(Reverce<1) OpenPos();
      else RevercePos();
      ModifyOrders();
      t=Time[0];
     }

   Comment("\n Buy:  ",buy,
           "\n Sell: ",sell,
           "\n Buy Positions:  ",CountTrades(0),
           "\n Sell Positions: ",CountTrades(1),
           "\n All Positions:  ",CountTrades(0)+CountTrades(1));
  }
//+------------------------------------------------------------------+

avatar

  34  AM2 Сообщений: 15879 - Андрей

  • 18 апреля 2016, 10:23
+
0
Спасибо ты супер.
avatar

  15  cashyra Автор Сообщений: 392 - Юра

  • 18 апреля 2016, 12:56

Зарегистрируйтесь или авторизуйтесь, чтобы оставить комментарий
Начать торговлю с Альпари