+2
Cейчас есть открытие закрытие по двум индюкам, мыло и остальное :) 



//+------------------------------------------------------------------+
//|                                                        Poker.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>             // Use CTrade Class

input double   Lot        = 1;         // Лот
input int      TakeProfit = 333;       // Тейкпрофит
input int      StopLoss   = 333;       // Стоплосс
input int      Points     = 50;        // Размер свечи
input int      Slip       = 50;        // Проскальзывание
input bool     Mail       = true;      // Шлем на почту
input bool     CloseSig   = true;      // Закрытие по сигналу

                                       //BB_MACD indicator parameters
input string   IndName    = "BB_MACD";
input int      FastLen    = 12;
input int      SlowLen    = 26;
input int      Length     = 10;
input int      barsCount  = 400;
input double   StDv       = 2.5;

int BBHandle=0,AOHandle=0,MAHandle=0;
double bb1[1],bb2[1],ma[1],ao1[1],ao2[1],op[1],cl[1];
CTrade trade;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

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

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double Ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);

   AOHandle=iAO(NULL,0);
   MAHandle=iMA(NULL,0,8,0,1,0);
//BBHandle=iCustom(NULL,0,IndName);
   CopyBuffer(AOHandle,0,1,1,ao1);
   CopyBuffer(AOHandle,0,2,1,ao2);
   CopyBuffer(MAHandle,0,1,1,ma);
//CopyBuffer(BBHandle,0,0,1,bb1);
//CopyBuffer(BBHandle,0,1,1,bb2);
   CopyOpen(NULL,0,1,1,op);
   CopyClose(NULL,0,1,1,cl);

   if(PositionsTotal()<1)
     {
      if(MathAbs((op[0]-cl[0])/_Point>Points))
        {
         if(Ask>ma[0] && ao1[0]>ao2[0]) 
           {
            trade.PositionOpen(_Symbol,0,Lot,Ask,Ask-StopLoss*_Point,Ask+TakeProfit*_Point);
            if(Mail) SendMail("Position Open","Open Buy");
           }
           
         if(Bid<ma[0] && ao1[0]<ao2[0]) 
           {
            trade.PositionOpen(_Symbol,1,Lot,Bid,Bid+StopLoss*_Point,Bid-TakeProfit*_Point);
            if(Mail) SendMail("Position Open","Open Sell");
           }
        }
     }

   if(PositionsTotal()>0)
     {
      if(MathAbs((op[0]-cl[0])/_Point>Points) && CloseSig)
        {
         if(Ask>ma[0] && ao1[0]>ao2[0] && PositionGetInteger(POSITION_TYPE)==1) trade.PositionClose(_Symbol);
         if(Bid<ma[0] && ao1[0]<ao2[0] && PositionGetInteger(POSITION_TYPE)==0) trade.PositionClose(_Symbol);
        }
     }

   Comment(MathAbs((op[0]-cl[0])/_Point));
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 6 ноября 2016, 00:31
+2
С пользовательским индикатором у меня виснет и глючит. Менять надо на стандартный. Без пользовательского все нормально работает. Можете убедиться:


//+------------------------------------------------------------------+
//|                                                        Poker.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>                 // Use CTrade Class

input double   Lot        = 1;
input int      TakeProfit = 333;       // Тейкпрофит
input int      StopLoss   = 333;       // Стоплосс
input int      Slip       = 50;        // Проскальзывание
input long     Magic      = 123;       // Магик

                                       //BB_MACD indicator parameters
input string   IndName    = "BB_MACD";
input int      FastLen    = 12;
input int      SlowLen    = 26;
input int      Length     = 10;
input int      barsCount  = 400;
input double   StDv       = 2.5;

int BBHandle=0,AOHandle=0,MAHandle=0;
double bb1[1],bb2[1],ma[1],ao1[1],ao2[1];
CTrade trade;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

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

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double Ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);

   AOHandle=iAO(NULL,0);
   MAHandle=iMA(NULL,0,8,0,1,0);
   BBHandle=iCustom(NULL,0,IndName);
   CopyBuffer(AOHandle,0,0,1,ao1);
   CopyBuffer(AOHandle,0,1,1,ao2);
   CopyBuffer(MAHandle,0,0,1,ma);
   CopyBuffer(BBHandle,0,0,1,bb1);
   CopyBuffer(BBHandle,0,1,1,bb2);

   if(PositionsTotal()<1)
     {
      if(Ask>ma[0] && ao1[0]>ao2[0] && bb1[0]>bb2[0]) trade.PositionOpen(_Symbol,0,Lot,Ask,Ask-StopLoss*_Point,Ask+TakeProfit*_Point);
      if(Ask<ma[0] && ao1[0]<ao2[0] && bb1[0]<bb2[0]) trade.PositionOpen(_Symbol,1,Lot,Bid,Bid+StopLoss*_Point,Bid-TakeProfit*_Point);
     }

   Comment(ao1[0]);
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 5 ноября 2016, 23:13
+1
Просьба скидывать изображения в топик чтобы всегда были перед глазами

avatar

AM2

  • 5 ноября 2016, 22:11
+1
Начну сегодня, посмотрим что получится.
avatar

AM2

  • 5 ноября 2016, 21:49
0
Сделал с вашим: www.opentraders.ru/downloads/1381/
Если мультитаймфреймовость не используется лучше будет работать со стандартным.



//+------------------------------------------------------------------+
//|                                                         PSAR.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 int StopLoss      = 222;      // лось
extern int TakeProfit    = 222;      // язь
extern int TrailingStop  = 0;        // трал
extern int TrailingStep  = 20;       // шаг трала
extern int StartHour     = 0;        // час начала торговли
extern int StartMin      = 30;       // минута начала торговли
extern int EndHour       = 23;       // час окончания торговли
extern int EndMin        = 30;       // минута окончания торговли
extern int Slip          = 30;       // реквот
extern int Shift         = 1;        // на каком баре сигнал индикатора
extern int CloseOn       = 1;        // 1-закрытие в конце работы
extern int Magic         = 123;      // магик

extern string IndName    = "MTF_PSar";
extern int    TimeFrame  = 0;
extern double Step       = 0.02;
extern double Maximum    = 0.2;

datetime t=0;
bool b=true,s=true;
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Comment("");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. aka KimIV,  http://www.kimiv.ru                   |
//+----------------------------------------------------------------------------+
//|  Версия   : 30.04.2009                                                     |
//|  Описание : Возвращает флаг разрешения торговли по времени.                |
//+----------------------------------------------------------------------------+
//|  Параметры:                                                                |
//|    hb - часы времени начала торговли                                       |
//|    mb - минуты времени начала торговли                                     |
//|    he - часы времени окончания торговли                                    |
//|    me - минуты времени окончания торговли                                  |
//+----------------------------------------------------------------------------+
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 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 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 OpenPos()
  {
   double sar=iCustom(NULL,0,IndName,TimeFrame,Step,Maximum,0,Shift);

   if(t!=Time[0])
     {
      if(Ask>sar && b)
        {
         PutOrder(0,Ask);
         b=false;
         s=true;
        }

      if(Bid<sar && s)
        {
         PutOrder(1,Bid);
         s=false;
         b=true;
        }
      t=Time[0];
     }
  }
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу                                          |
//+------------------------------------------------------------------+
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 ClosePos()
  {
   double sar=iCustom(NULL,0,IndName,TimeFrame,Step,Maximum,0,Shift);

   if(Bid>sar && CountOrders(1)>0)
     {
      CloseAll(1);// sell close
     }

   if(Ask<sar && CountOrders(0)>0)
     {
      CloseAll(0);//buy close
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 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);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(CountTrades()<1 && isTradeTimeInt(StartHour,StartMin,EndHour,EndMin))
     {
      OpenPos();
     }
   else ClosePos();

   if(!isTradeTimeInt(StartHour,StartMin,EndHour,EndMin) && CloseOn>0) CloseAll();

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

AM2

  • 3 ноября 2016, 20:29
0
А чем ваш индикатор отличается от стандартного параболика? Бросил оба на график все один в один.
avatar

AM2

  • 3 ноября 2016, 19:52
0
Как мне разместить заказ?

Трейдерам от 3-го уровня бесплатное выполнение.
avatar

AM2

  • 2 ноября 2016, 23:51
0
Есть все: www.opentraders.ru/downloads/1378/






//+------------------------------------------------------------------+
//|                                                       2MASig.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       = 1;        // умножение лота
extern double MaxLot     = 5;        // максимальный лот
extern int StopLoss      = 333;      // лось
extern int TakeProfit    = 333;      // язь
extern int MA1Period     = 25;       // период МА1
extern int MA2Period     = 50;       // период МА2
extern int MAShift       = 0;        // сдвиг МА
extern int MAMethod      = 1;        // метод МА
extern int MAPrice       = 0;        // цены МА
extern int Slip          = 30;       // реквот
extern int Shift         = 1;        // на каком баре сигнал индикатора
extern int CloseSig      = 1;        // 1-закрытие по сигналу
extern int Magic         = 123;      // магик
//+------------------------------------------------------------------+
//| 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,err=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 Losses()
  {
   int losses=0;
   for(int i=OrdersHistoryTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==0)
              {
               if(OrderOpenPrice()-OrderClosePrice()>0) losses++;
               if(OrderOpenPrice()-OrderClosePrice()<0) break;
              }
            if(OrderType()==1)
              {
               if(OrderOpenPrice()-OrderClosePrice()<0) losses++;
               if(OrderOpenPrice()-OrderClosePrice()>0) break;
              }
           }
        }
     }
   return(losses);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lot()
  {
   double lot=0;
   lot=Lots*MathPow(KLot,Losses());
   if(lot>MaxLot)lot=Lots;
   return(lot);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 OpenPos()
  {
   double MA1=iMA(NULL,0,MA1Period,MAShift,MAMethod,MAPrice,Shift);
   double MA2=iMA(NULL,0,MA2Period,MAShift,MAMethod,MAPrice,Shift);

   if(OneDayDeal())
     {
      if(MA1<MA2)
        {
         PutOrder(1,Bid);
        }

      if(MA1>MA2)
        {
         PutOrder(0,Ask);
        }
     }
  }
//+------------------------------------------------------------------+
//| Закрытие позиции по типу ордера                                  |
//+------------------------------------------------------------------+
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);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу                                          |
//+------------------------------------------------------------------+
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 ClosePos()
  {
   double MA1=iMA(NULL,0,MA1Period,MAShift,MAMethod,MAPrice,Shift);
   double MA2=iMA(NULL,0,MA2Period,MAShift,MAMethod,MAPrice,Shift);

   if(MA1>MA2 && CountOrders(1)>0)
     {
      CloseAll(1);// sell close
     }

   if(MA1<MA2 && CountOrders(0)>0)
     {
      CloseAll(0);//buy close
     }
  }
//+------------------------------------------------------------------+
//| Одна сделка в день                                               |
//+------------------------------------------------------------------+
bool OneDayDeal()
  {
   bool result=true;
   if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
     {
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
        {
         if(OrderType()<2 && TimeDay(OrderCloseTime())==Day())
           {
            result=false;//tp  
           }
        }
     }
   return(result);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(CountTrades()<1) OpenPos();
   if(CloseSig>0) ClosePos();

   double dp=TakeProfit*Lot();
   double pp=dp*100/AccountBalance();

   double ds=StopLoss*Lot();
   double ps=ds*100/AccountBalance();

   Comment("\n Dollars Loss: ",ds,
           "\n Procent Loss: ",NormalizeDouble(ps,2),
           "\n Dollars Profit: ",dp,
           "\n Procent Profit: ",NormalizeDouble(pp,2));
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 2 ноября 2016, 19:34
0
Посмотрю сегодня.
avatar

AM2

  • 2 ноября 2016, 17:53
0
индюк WPR при цифре 5 уровни все равно остаются по у молчанию?

У разработчиков терминала спросите.
avatar

AM2

  • 2 ноября 2016, 08:48
0
можно в сову в вести уровни идюка какие я бы прописывал такие бы и были?

Это нужно только когда уровни разные, например верх -10 низ -70.
avatar

AM2

  • 2 ноября 2016, 01:57
0
как проставить уровни -95 и -5


WPRLevel = 5.
avatar

AM2

  • 2 ноября 2016, 01:54
0
какое бы я числовое значение extern int WPRLevel не ставил ве равно остаеться -20 и -80

Торгует по тем у ровням что прописали, а в тестере уровни ставятся по умолчанию.
avatar

AM2

  • 2 ноября 2016, 01:53
0
Для впр уровень считает так:
верхний = — WPRLevel,
нижний = -100 + WPRLevel.
extern int WPRLevel = 5;  // уровень WPR


Настройки МА добавил:


extern int MAShift       = 0;        // сдвиг МА
extern int MAMethod      = 0;        // метод МА
extern int MAPrice       = 0;        // цены МА



//+------------------------------------------------------------------+
//|                                                   MissMarple.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 string StartTime  = "00:00";  // время начала торговли
extern string EndTime    = "23:00";  // время окончания торговли
extern double Lots       = 0.1;      // лот
extern double KLot       = 1;        // умножение лота
extern double MaxLot     = 5;        // максимальный лот
extern int StopLoss      = 2000;     // лось
extern int TakeProfit    = 3000;     // язь
extern int Slip          = 30;       // реквот
extern int MAPeriod      = 12;       // период МА
extern int MAShift       = 0;        // сдвиг МА
extern int MAMethod      = 0;        // метод МА
extern int MAPrice       = 0;        // цены МА
extern int WPRPeriod     = 21;       // период WPR
extern int WPRLevel      = 5;        // уровень WPR
extern int Shift         = 1;        // на каком баре сигнал индикатора
extern int OnePos        = 1;        // 1-одна поза 0-несколько
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 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;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 OpenPos()
  {
   double ma=iMA(NULL,0,MAPeriod,MAShift,MAMethod,MAPrice,Shift);
   double wpr1=iWPR(NULL,0,WPRPeriod,Shift);
   double wpr2=iWPR(NULL,0,WPRPeriod,Shift+1);

   if(Ask>ma && wpr1>-100+WPRLevel && wpr2<-100+WPRLevel)
     {
      PutOrder(0,Ask);
     }

   if(Bid<ma && wpr2>-WPRLevel && wpr1<-WPRLevel)
     {
      PutOrder(1,Bid);
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   datetime End=StringToTime(EndTime);
   datetime Start=StringToTime(StartTime);

   if(TimeCurrent()>Start && TimeCurrent()<End)
     {
      if(t!=Time[0] && OnePos<1)
        {
         OpenPos();
         t=Time[0];
        }

      if(CountTrades()<1 && OnePos>0) OpenPos();
     }
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 1 ноября 2016, 23:19
0
Поправил:




//+------------------------------------------------------------------+
//|                                                          OAO.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       = 2;        // умножение лота
extern double MaxLot     = 5;        // максимальный лот
extern int StopLoss      = 50;       // лось
extern int TakeProfit    = 70;       // язь
extern int Expiration    = 10;       // истечение ордера
extern int CloseOn       = 0;        // 1-закрытие,удаление ордеров на сигналах AO
extern bool BSDel        = true;     // удалим байстоп после пересечения
extern bool SSDel        = true;     // удалим селстоп после пересечения
extern int Slip          = 30;       // реквот
extern int Magic         = 123;      // магик

bool b=true,s=true;
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   Comment("");
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   Comment("");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutOrder(int type,double price)
  {
   int r=0;
   color clr;
   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);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 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())
           {
            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 DelOrderType(int type)
  {
   bool del;
   for(int i=OrdersTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
        {
         if(OrderSymbol()==Symbol())
           {
            if(OrderType()==type) del=OrderDelete(OrderTicket());
           }
        }
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int CrossBars()
  {
   int bar=0;

   for(int i=0;i<100;i++)
     {
      double ao1=iAO(NULL,0,i);
      double ao2=iAO(NULL,0,i+1);
      if((ao1>0 && ao2<0) || (ao1<0 && ao2>0))
        {
         bar=i;
         break;
        }
     }

   return(bar);
  }
//+------------------------------------------------------------------+
//| Считает количество убыточных сделок в истории                    |
//+------------------------------------------------------------------+
int Losses()
  {
   int losses=0;
   for(int i=OrdersHistoryTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderType()==0)
              {
               if(OrderOpenPrice()-OrderClosePrice()>0) losses++;
               if(OrderOpenPrice()-OrderClosePrice()<0) break;
              }
            if(OrderType()==1)
              {
               if(OrderOpenPrice()-OrderClosePrice()<0) losses++;
               if(OrderOpenPrice()-OrderClosePrice()>0) break;
              }
           }
        }
     }
   return(losses);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double Lot()
  {
   double lot=0;
   lot=Lots*MathPow(KLot,Losses());
   if(lot>MaxLot)lot=Lots;
   return(lot);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   double ao1=iAO(NULL,0,1);
   double ao2=iAO(NULL,0,2);
   double ao3=iAO(NULL,0,3);
   double low=Low[iLowest(NULL,0,MODE_LOW,CrossBars(),1)];
   double high=High[iHighest(NULL,0,MODE_HIGH,CrossBars(),1)];

   if(CountTrades()<1)
     {
      if(ao1>0 && ao2>ao1 && ao2>ao3 && CountOrders(4)<1 && Bid<high && b)
        {
         PutOrder(4,high);
         b=false;s=true;
        }

      if(ao1<0 && ao2<ao1 && ao2<ao3 && CountOrders(5)<1 && Bid>low && s)
        {
         PutOrder(5,low);
         s=false;b=true;
        }
     }

   if((ao1>0 && ao2<0 && SSDel) || (ao1<0 && ao2>0 && BSDel)) DelOrder();

   if(CloseOn>0)
     {
      if(ao2>0 && ao1<0)
        {
         CloseAll(0);
         DelOrderType(2);
         DelOrderType(4);
        }

      if(ao2<0 && ao1>0)
        {
         CloseAll(1);
         DelOrderType(3);
         DelOrderType(5);
        }
     }

   Comment(CrossBars());
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 1 ноября 2016, 21:18
0
Сделал все по ТЗ: www.opentraders.ru/downloads/1375/




//+------------------------------------------------------------------+
//|                                                   MissMarple.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 string StartTime  = "00:00";  // время начала торговли
extern string EndTime    = "23:00";  // время окончания торговли
extern double Lots       = 0.1;      // лот
extern double KLot       = 1;        // умножение лота
extern double MaxLot     = 5;        // максимальный лот
extern int StopLoss      = 2000;     // лось
extern int TakeProfit    = 3000;     // язь
extern int Slip          = 30;       // реквот
extern int MAPeriod      = 12;       // период МА
extern int WPRPeriod     = 21;       // период WPR
extern int WPRLevel      = 5;        // уровень WPR
extern int Shift         = 1;        // на каком баре сигнал индикатора
extern int OnePos        = 1;        // 1-одна поза 0-несколько
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 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;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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 OpenPos()
  {
   double ma=iMA(NULL,0,MAPeriod,0,0,0,Shift);
   double wpr1=iWPR(NULL,0,WPRPeriod,Shift);
   double wpr2=iWPR(NULL,0,WPRPeriod,Shift+1);

   if(Ask>ma && wpr1>-100+WPRLevel && wpr2<-100+WPRLevel)
     {
      PutOrder(0,Ask);
     }

   if(Bid<ma && wpr2>-WPRLevel && wpr1<-WPRLevel)
     {
      PutOrder(1,Bid);
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   datetime End=StringToTime(EndTime);
   datetime Start=StringToTime(StartTime);

   if(TimeCurrent()>Start && TimeCurrent()<End)
     {
      if(t!=Time[0] && OnePos<1)
        {
         OpenPos();
         t=Time[0];
        }

      if(CountTrades()<1 && OnePos>0) OpenPos();
     }
  }
//+------------------------------------------------------------------+
avatar

AM2

  • 1 ноября 2016, 10:12
0
Помню делал с МА и WPR, посмотрите в базе, если не найдете тогда с нуля напишу.
avatar

AM2

  • 1 ноября 2016, 05:06
0
Готово: www.opentraders.ru/downloads/1376/



//+------------------------------------------------------------------+
//|                                                      Nedelka.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 string StartTime  = "00:00";  // время начала торговли
extern string EndTime    = "08:00";  // время окончания торговли
extern int StopLoss      = 2000;     // лось
extern int TakeProfit    = 3000;     // язь
extern int Spread        = 20;       // спред
extern int Delta         = 300;      // дельта
extern int BuySell       = 0;        // 0-buy 1-sell
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 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,0,clr);
   return;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
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);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   datetime End=StringToTime(EndTime);
   datetime Start=StringToTime(StartTime);
   datetime Weak=iTime(NULL,PERIOD_W1,0);
   double OpenPrice=iOpen(NULL,PERIOD_W1,1);
   double spread=MarketInfo(NULL,MODE_SPREAD);

   if(t!=Weak)
     {
      if(TimeCurrent()>Start && TimeCurrent()<End)
        {
         if(CountTrades()<1 && spread<Spread)
           {
            if(BuySell==0 && Ask<OpenPrice+Delta*Point)
              {
               PutOrder(0,Ask);
              }

            if(BuySell==1 && Bid>OpenPrice-Delta*Point)
              {
               PutOrder(1,Bid);
              }
            t=Weak;
           }
        }
     }

   Comment("\n Spread: ",spread,"\n OpenPrice: ",OpenPrice);
  }
//+------------------------------------------------------------------+
avatar

AM2

  • 31 октября 2016, 09:33