0
Не раньше среды доберусь, заказов много.
avatar

AM2

  • 7 января 2017, 21:48
0
Сделал раз в день:




//+------------------------------------------------------------------+
//|                                                         Tree.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 Lot        = 0.1;      // лот рыночного
extern double Lots       = 0.1;      // лот отложенного
extern int Loss          = 333;      // лось рыночного
extern int Profit        = 333;      // язь  рыночного
extern int StopLoss      = 333;      // лось отложенного
extern int TakeProfit    = 333;      // язь  отложенного
extern int Slip          = 30;       // реквот
extern int Shift         = 1;        // на каком баре сигнал индикатора
extern int Delta         = 300;      // расстояние от цены
extern int Magic         = 123;      // магик
extern string IndName    = "Trix";

int counts=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,double lot,int stop,int take)
  {
   int r=0;
   color clr=Green;
   double sl=0,tp=0;

   if(type==1 || type==3 || type==5)
     {
      clr=Red;
      sl=NormalizeDouble(price+stop*Point,Digits);
      tp=NormalizeDouble(price-take*Point,Digits);
     }

   if(type==0 || type==2 || type==4)
     {
      clr=Blue;
      sl=NormalizeDouble(price-stop*Point,Digits);
      tp=NormalizeDouble(price+take*Point,Digits);
     }

   r=OrderSend(NULL,type,lot,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 lime = iCustom(NULL,0,IndName,2,Shift);
   double red  = iCustom(NULL,0,IndName,3,Shift);
   double lime1 = iCustom(NULL,0,IndName,2,Shift+1);
   double red1  = iCustom(NULL,0,IndName,3,Shift+1);

   if(lime<1000)
     {
      PutOrder(0,Ask,Lot,Loss,Profit);
      if(CountOrders(2)<1 && CountOrders(3)<1) PutOrder(2,Ask-Delta*Point,Lots,StopLoss,TakeProfit);
     }

   if(red<1000)
     {
      PutOrder(1,Bid,Lot,Loss,Profit);
      if(CountOrders(3)<1 && CountOrders(3)<1) PutOrder(3,Bid+Delta*Point,Lots,StopLoss,TakeProfit);
     }
  }
//+------------------------------------------------------------------+
//| Подсчет ордеров по типу                                          |
//+------------------------------------------------------------------+
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()
  {
   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()==OP_BUY)
              {
               RefreshRates();
               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Bid,Digits),Slip,White);
              }
            if(OrderType()==OP_SELL)
              {
               RefreshRates();
               cl=OrderClose(OrderTicket(),OrderLots(),NormalizeDouble(Ask,Digits),Slip,White);
              }
           }
        }
     }
  }
//+------------------------------------------------------------------+
//| Одна сделка в день                                               |
//+------------------------------------------------------------------+
bool OneDayDeal()
  {
   bool result=true;
   if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
     {
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
        {
         if(OrderType()<2 && TimeDay(OrderOpenTime())==Day())
           {
            result=false;//tp  
           }
        }
     }
   return(result);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   double lime= iCustom(NULL,0,IndName,2,Shift);
   double red = iCustom(NULL,0,IndName,3,Shift);

   if(CountTrades()==0) counts = 0;
   if(CountTrades()==2) counts = 2;

   if(CountTrades()<1 && OneDayDeal())
     {
      DelOrder();
      OpenPos();
     }

   if(CountTrades()==1 && counts==2)
     {
      CloseAll();
     }

   Comment("\n lime: ",lime,
           "\n red: ",red);
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 7 января 2017, 21:46
0
Завтра посмотрю, тут вроде немного.
avatar

AM2

  • 7 января 2017, 20:39
0
Здесь действительно штуки 4 только моих варианта и у Оксаны еще сколько!
avatar

AM2

  • 6 января 2017, 20:39
0
Здесь в базе есть подобные по скорости изменения цены.
avatar

AM2

  • 6 января 2017, 20:29
0
Не раньше вторника будет, очередь :) 
avatar

AM2

  • 6 января 2017, 20:18
0
Недавно помню делал такой.
avatar

AM2

  • 6 января 2017, 19:49
0
ссылка битая, я хоть посмотрю в чем ошибка была?
avatar

AM2

  • 6 января 2017, 19:27
0
Готово:




//+------------------------------------------------------------------+
//|                                                       Modnik.mq4 |
//|                                              Copyright 2016, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2016, AM2"
#property link      "http://www.forexsystems.biz"
#property description "BBands expert advisor"

//--- Inputs
extern double Lots         = 0.1;   // лот
extern double KLot         = 2;     // умножение лота
extern double MaxLot       = 5;     // максимальный лот
extern double MACDLevel    = 0.001; // максимальный лот
extern int    StopLoss     = 5000;  // лось
extern int    TakeProfit   = 5000;  // язь
extern int    StartHour    = 0;     // час начала торговли
extern int    StartMin     = 30;    // минута начала торговли
extern int    EndHour      = 23;    // час окончания торговли
extern int    EndMin       = 30;    // минута окончания торговли
extern int    Shift        = 1;     // сдвиг
extern int    Slip         = 30;    // слипаж
extern bool   MACD         = true;  // MACD включен
extern int    Magic        = 123;   // магик
//----
extern string IndName1     = "BBands_Stop_v1";
extern int    Length       = 20;   // период BB 
extern int    Deviation    = 2;    // отклонение ВВ
extern double MoneyRisk    = 1;    // Offset Factor

extern string IndName2     = "MACD_MOD";
input int     InpFastEMA   = 12;   // Fast EMA Period
input int     InpSlowEMA   = 26;   // Slow EMA Period
input int     InpSignalSMA = 9;    // Signal SMA Period
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

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

  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutOrder(int type,double price,double lot)
  {
   int r=0;
   color clr;
   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 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 LastLossDealType()
  {
   int type=8;
   for(int i=OrdersHistoryTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderProfit()<0) type=OrderType();
            break;
           }
        }
     }
   return(type);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double LastLossDealLot(int type)
  {
   double lot=Lots;
   for(int i=OrdersHistoryTotal()-1;i>=0;i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY))
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
           {
            if(OrderProfit()<0 && type==OrderType()) lot=OrderLots();
            break;
           }
        }
     }
   return(lot);
  }
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. 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);
  }
//+------------------------------------------------------------------+
//| Check for open order conditions                                  |
//+------------------------------------------------------------------+
void OpenPos()
  {
   double lot=Lots;
   double BBBlue  = iCustom(NULL,0,IndName1,Length,Deviation,0,Shift);
   double BBRed   = iCustom(NULL,0,IndName1,Length,Deviation,1,Shift);
   double BBBlue2 = iCustom(NULL,0,IndName1,Length,Deviation,0,Shift+1);
   double BBRed2  = iCustom(NULL,0,IndName1,Length,Deviation,1,Shift+1);

   double blue = iCustom(NULL,0,IndName2,InpFastEMA,InpSlowEMA,InpSignalSMA,1,Shift);
   double red  = iCustom(NULL,0,IndName2,InpFastEMA,InpSlowEMA,InpSignalSMA,0,Shift);

   bool buy,sell;

   if(MACD)
     {
      buy  = BBBlue>0 && BBRed2>0  && red<1000  && red>MACDLevel;
      sell = BBRed>0  && BBBlue2>0 && blue<1000 && blue<-MACDLevel;
     }

   if(!MACD)
     {
      buy  = BBBlue>0 && BBRed2>0;
      sell = BBRed>0  && BBBlue2>0;
     }

/*
увеличиваем лот если предыдущая сделка в минусе 
и противоположная сигналу.
*/
   if(sell)
     {
      if(LastLossDealType()==0) lot=LastLossDealLot(LastLossDealType())*KLot;
      PutOrder(1,Bid,lot);
     }

   if(buy)
     {
      if(LastLossDealType()==1) lot=LastLossDealLot(LastLossDealType())*KLot;
      PutOrder(0,Ask,lot);
     }
  }
//+------------------------------------------------------------------+
//| OnTick function                                                  |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(CountTrades()<1 && isTradeTimeInt(StartHour,StartMin,EndHour,EndMin)) OpenPos();
   Comment(LastLossDealType());
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 6 января 2017, 18:53
0
там делать 5 секунд

Можно взглянуть на готовое решение? :) 
avatar

AM2

  • 6 января 2017, 18:46
0
Заказы трейдеров от 3-го уровня смотрю.
avatar

AM2

  • 6 января 2017, 18:28
0
Если будет целая портянка не пойдет :)  Делаю только то что можно быстро сделать.
avatar

AM2

  • 5 января 2017, 22:37
0
Немного только начал. Пишите.
avatar

AM2

  • 5 января 2017, 20:59
0
Вот так примерно:




//+------------------------------------------------------------------+
//|                                                        Happy.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
//--- Inputs
extern double Lots       = 0.1;      // лот
extern int StopLoss      = 2000;     // лось
extern int TakeProfit    = 3000;     // язь
extern int Delta         = 100;      // плюс к стопу
extern int Slip          = 30;       // реквот
extern int StLevel       = 20;       // уровень индикатора
extern int Shift         = 1;        // на каком баре сигнал индикатора
extern int Many          = 0;        // 1-много ордеров
extern int Magic         = 123;      // магик

extern int InpDepth      = 12;
extern int InpDeviation  = 5;
extern int InpBackstep   = 3;

input int InpKPeriod     = 5; // K Period
input int InpDPeriod     = 3; // D Period
input int InpSlowing     = 3; // Slowing

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); else sl=GetZZPrice(0)+Delta*Point;
      if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
     }

   if(type==0 || type==2 || type==4)
     {
      clr=Blue;
      if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);else sl=GetZZPrice(0)-Delta*Point;
      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 st1=iStochastic(NULL,0,InpKPeriod,InpDPeriod,InpSlowing,0,0,0,Shift);
   double st2=iStochastic(NULL,0,InpKPeriod,InpDPeriod,InpSlowing,0,0,0,Shift+1);

   if(st1>StLevel && st2<StLevel)
     {
      PutOrder(0,Ask);
     }

   if(st1<100-StLevel && st2>100-StLevel)
     {
      PutOrder(1,Bid);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetZZPrice(int ne=0)
  {
   double zz;
   int    i,k=iBars(NULL,0),ke=0;

   for(i=1; i<k; i++)
     {
      zz=iCustom(NULL,0,"ZigZag",InpDepth,InpDeviation,InpBackstep,0,i);
      if(zz!=0)
        {
         ke++;
         if(ke>ne) return(zz);
        }
     }
   Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(CountTrades()<1 && Many==0)
     {
      OpenPos();
     }

   if(t!=Time[0] && Many==1)
     {
      OpenPos();
      t=Time[0]; 
     }
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 5 января 2017, 16:20
0
Если советник стоит на паре, нормально работает. Переоткрывал терминал, тоже нормально. Чуть чуть исправил.



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

//--- Inputs
extern double Lots       = 0.1;      // лот
extern double KLot       = 4;        // умножение лота
extern double MaxLot     = 50;       // максимальный лот
extern double Risk       = 10;       // риск
extern int StopLoss      = 300;      // лось
extern int TakeProfit    = 100;      // язь
extern int StartHour     = 0;        // час начала торговли
extern int StartMin      = 30;       // минута начала торговли
extern int EndHour       = 23;       // час окончания торговли
extern int EndMin        = 30;       // минута окончания торговли
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("");
  }
//+----------------------------------------------------------------------------+
//|  Автор    : Ким Игорь В. 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,Lot(),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()
  {
//---- buy 
   if(Ask<iOpen(NULL,PERIOD_D1,0))
     {
      PutOrder(0,Ask);
     }
//---- sell   
   if(Bid>iOpen(NULL,PERIOD_D1,0))
     {
      PutOrder(1,Bid);
     }
  }
//+------------------------------------------------------------------+
//| Calculate optimal lot size                                       |
//+------------------------------------------------------------------+
double Lot()
  {
   double lot=Lots;

   if(Lots==0)
     {
      lot=NormalizeDouble(AccountBalance()*Risk/100000,2); // 10000*10/100000=1
     }

   if(OrderSelect(OrdersHistoryTotal()-1,SELECT_BY_POS,MODE_HISTORY))
     {
      if(OrderSymbol()==Symbol() && OrderMagicNumber()==Magic)
        {
         if(OrderProfit()<=0)
           {
            lot=OrderLots()*KLot;
           }
        }
     }
   if(lot>MaxLot)lot=MaxLot;
   return(lot);
  }
//+------------------------------------------------------------------+
//| Одна сделка в день                                               |
//+------------------------------------------------------------------+
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);
  }
//+------------------------------------------------------------------+
//| Start function                                                   |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(t!=Time[0])
     {
      if(CountTrades()<1 && OneDayDeal() && isTradeTimeInt(StartHour,StartMin,EndHour,EndMin)) OpenPos();
      t=Time[0];
     }
  }
//+------------------------------------------------------------------+
avatar

AM2

  • 5 января 2017, 15:44
0
Я начал делать, покажите на скрине куда ставить стопы, на какой излом?




//+------------------------------------------------------------------+
//|                                                        Happy.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
//--- Inputs
extern double Lots       = 0.1;      // лот
extern int StopLoss      = 2000;     // лось
extern int TakeProfit    = 3000;     // язь
extern int Slip          = 30;       // реквот
extern int StLevel       = 20;       // уровень индикатора
extern int Shift         = 1;        // на каком баре сигнал индикатора
extern int Magic         = 123;      // магик

extern int InpDepth      = 12;
extern int InpDeviation  = 5;
extern int InpBackstep   = 3;

input int InpKPeriod     = 5; // K Period
input int InpDPeriod     = 3; // D Period
input int InpSlowing     = 3; // Slowing
//+------------------------------------------------------------------+
//| 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); else sl=GetZZPrice(0);
      if(TakeProfit>0) tp=NormalizeDouble(price-TakeProfit*Point,Digits);
     }

   if(type==0 || type==2 || type==4)
     {
      clr=Blue;
      if(StopLoss>0) sl=NormalizeDouble(price-StopLoss*Point,Digits);else sl=GetZZPrice(0);
      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 st1=iStochastic(NULL,0,InpKPeriod,InpDPeriod,InpSlowing,0,0,0,Shift);
   double st2=iStochastic(NULL,0,InpKPeriod,InpDPeriod,InpSlowing,0,0,0,Shift+1);

   if(st1>StLevel && st2<StLevel)
     {
      PutOrder(0,Ask);
     }

   if(st1<100-StLevel && st2>100-StLevel)
     {
      PutOrder(1,Bid);
     }
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double GetZZPrice(int ne=0)
  {
   double zz;
   int    i,k=iBars(NULL,0),ke=0;

   for(i=1; i<k; i++)
     {
      zz=iCustom(NULL,0,"ZigZag",InpDepth,InpDeviation,InpBackstep,0,i);
      if(zz!=0)
        {
         ke++;
         if(ke>ne) return(zz);
        }
     }
   Print("GetExtremumZZPrice(): Экстремум ЗигЗага номер ",ne," не найден");
   return(0);
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   if(CountTrades()<1)
     {
      OpenPos();
     }
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 4 января 2017, 21:46
0
Не раньше чем через 2 дня буду смотреть.
avatar

AM2

  • 4 января 2017, 20:32