0
сделал вариант закрытия по цене оупен текущей свечи. но здесь одно но, если открылась следующая свеча автоматом поза закрывается т.к. соблюдается условие :) 


//+------------------------------------------------------------------+
//|                                                         Open.mq5 |
//|                                              Copyright 2019, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, AM2"
#property link      "http://www.forexsystems.biz"
#property version   "1.00"

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

CTrade trade;
CPositionInfo pos;

//--- глобальные переменные
input int TP=111;//язь
input double LT=1;//лот

double op[1];
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
   PutButton("B",100,80,"BUY");
   PutButton("S",100,40,"SELL");

   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
   ObjectDelete(0,"B");
   ObjectDelete(0,"S");
   Comment("");
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutButton(string name,int x,int y,string text)
  {
   ObjectCreate(0,name,OBJ_BUTTON,0,0,0);
//--- установим координаты кнопки
   ObjectSetInteger(0,name,OBJPROP_XDISTANCE,x);
   ObjectSetInteger(0,name,OBJPROP_YDISTANCE,y);
//--- установим размер кнопки
   ObjectSetInteger(0,name,OBJPROP_XSIZE,80);
   ObjectSetInteger(0,name,OBJPROP_YSIZE,30);
//--- установим угол графика, относительно которого будут определяться координаты точки
   ObjectSetInteger(0,name,OBJPROP_CORNER,2);
//--- установим текст
   ObjectSetString(0,name,OBJPROP_TEXT,text);
//--- установим шрифт текста
   ObjectSetString(0,name,OBJPROP_FONT,"Arial");
//--- установим размер шрифта
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,12);
//--- установим цвет текста
   ObjectSetInteger(0,name,OBJPROP_COLOR,Red);
//--- установим цвет фона
   ObjectSetInteger(0,name,OBJPROP_BGCOLOR,White);
//--- установим цвет границы
   ObjectSetInteger(0,name,OBJPROP_BORDER_COLOR,Blue);
//--- скроем (true) или отобразим (false) имя графического объекта в списке объектов
   ObjectSetInteger(0,name,OBJPROP_HIDDEN,false);
//--- установим приоритет на получение события нажатия мыши на графике
   ObjectSetInteger(0,name,OBJPROP_ZORDER,0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void CloseAll()
  {
   for(int i=PositionsTotal()-1;i>=0;i--)
     {
      if(pos.SelectByIndex(i)) trade.PositionClose(_Symbol);
     }
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   CopyOpen(NULL,0,0,1,op);

   double Ask=SymbolInfoDouble(_Symbol,SYMBOL_ASK);
   double Bid=SymbolInfoDouble(_Symbol,SYMBOL_BID);

   if(ObjectGetInteger(0,"B",OBJPROP_STATE)==1)
     {
      trade.Buy(LT,NULL,Ask,0,Bid+TP*_Point);
      ObjectSetInteger(0,"B",OBJPROP_STATE,false);
     }

   if(ObjectGetInteger(0,"S",OBJPROP_STATE)==1)
     {
      trade.Sell(LT,NULL,Bid,0,Ask-TP*_Point);
      ObjectSetInteger(0,"S",OBJPROP_STATE,false);
     }

   if(Bid==op[0]) CloseAll();

   Comment("\n Open: ",op[0]);
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 8 мая 2019, 18:53
0
Он держит ситуацию под контролем, постоянно сравнивая текущее значение цены со значением цены OPEN


цену оупен какой свечи запоминаем?
avatar

AM2

  • 8 мая 2019, 18:47
0
опишите все максимально подробно с пояснениями на скринах
avatar

AM2

  • 8 мая 2019, 18:22
0
с чужим кодом не работаю
avatar

AM2

  • 8 мая 2019, 18:16
0
заменил мыло на пуш


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

input int days=5;
input int width=1;
input int style=1;
input int delta=100;
input int count=5;
input bool push=1;
input bool alert=1;
input color upcolor=Red;
input color dncolor=Blue;
input color txtcolor=Lime;

int num=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutTrendLine(string name,datetime time1,double price1,datetime time2,double price2,color clr)
  {
   ObjectDelete(0,name);
   ObjectCreate(0,name,OBJ_TREND,0,time1,price1,time2,price2);
//--- установим цвет линии 
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
//--- установим стиль отображения линии 
   ObjectSetInteger(0,name,OBJPROP_STYLE,style);
//--- установим толщину линии 
   ObjectSetInteger(0,name,OBJPROP_WIDTH,width);
//--- включим (true) или отключим (false) режим продолжения отображения линии вправо 
   ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,0);
  }
//+------------------------------------------------------------------+
//| Put Text Function                                                |
//+------------------------------------------------------------------+
void Text(string name,const string text,double price,datetime time,const color clr)
  {
   ObjectDelete(0,name);
//--- create a "Text" object 
   ObjectCreate(0,name,OBJ_TEXT,0,time,price);
//--- set the text
   ObjectSetString(0,name,OBJPROP_TEXT,text);
//--- set the font of the text
   ObjectSetString(0,name,OBJPROP_FONT,"Arial");
//--- set the font size
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,9);
//--- set the method binding
   ObjectSetInteger(0,name,OBJPROP_ANCHOR,4);
//--- set the color
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   double hi1=iHigh(NULL,PERIOD_D1,1);
   double lo1=iLow (NULL,PERIOD_D1,1);

   for(int i=1;i<days;i++)
     {
      double hi=iHigh(NULL,PERIOD_D1,i);
      double lo=iLow (NULL,PERIOD_D1,i);
      datetime tm1=iTime(NULL,PERIOD_D1,i-1);
      datetime tm2=iTime(NULL,PERIOD_D1,i);
      datetime tm=(tm1+tm2)/2;
      int range=(int)((hi-lo)/_Point/10);

      PutTrendLine("Hi"+(string)i,tm1,hi,tm2,hi,upcolor);
      PutTrendLine("Lo"+(string)i,tm1,lo,tm2,lo,dncolor);
      Text("Text"+(string)i,(string)range,hi,tm,txtcolor);
     }

   if(num<count)
     {
      if(alert)
        {
         if(Bid<hi1+delta*_Point && Bid>hi1-delta*_Point) Alert(_Symbol+" Цена около уровня: ",hi1);
         if(Bid<lo1+delta*_Point && Bid>lo1-delta*_Point) Alert(_Symbol+" Цена около уровня: ",lo1);
        }
      if(push)
        {
         if(Bid<hi1+delta*_Point && Bid>hi1-delta*_Point) SendNotification(_Symbol+" Цена около уровня: "+(string)hi1);
         if(Bid<lo1+delta*_Point && Bid>lo1-delta*_Point) SendNotification(_Symbol+" Цена около уровня: "+(string)lo1);
        }
      num++;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 7 мая 2019, 22:13
0
Второе, что сложнее, буду думать, как контролировать руками.


в следующем топике могу посмотреть эту функцию
avatar

AM2

  • 7 мая 2019, 20:02
0
закрытие по общему профиту добавил: www.opentraders.ru/downloads/2305/

avatar

AM2

  • 7 мая 2019, 19:58
0
Проверяем общий плюс по всем сделкам. Если плюс достиг показателя переменной, то все ордера закрываем. Если нет, то ждем.


этот момент могу сегодня посмотреть

Смотрим на предыдущий квадратик, если он красный, ищем открытые ордера, которые в buy, в плюсе, закрываем их, остальные ордера в buy которые в минусе удерживаем. Открываем sell.
Смотрим на предыдущий квадратик, если он синий, ищем открытые ордера, которые в sell, в плюсе, закрываем их, остальные ордера в sell которые в минусе удерживаем. Открываем buy.


а здесь у меня нет готовой функции, нужно писать с нуля отлаживать и т.д. это долго
avatar

AM2

  • 7 мая 2019, 19:39
0
готово:




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

input int days=5;
input int width=1;
input int style=1;
input int delta=100;
input int count=5;
input bool mail=1;
input bool alert=1;
input color upcolor=Red;
input color dncolor=Blue;
input color txtcolor=Lime;

int num=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PutTrendLine(string name,datetime time1,double price1,datetime time2,double price2,color clr)
  {
   ObjectDelete(0,name);
   ObjectCreate(0,name,OBJ_TREND,0,time1,price1,time2,price2);
//--- установим цвет линии 
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
//--- установим стиль отображения линии 
   ObjectSetInteger(0,name,OBJPROP_STYLE,style);
//--- установим толщину линии 
   ObjectSetInteger(0,name,OBJPROP_WIDTH,width);
//--- включим (true) или отключим (false) режим продолжения отображения линии вправо 
   ObjectSetInteger(0,name,OBJPROP_RAY_RIGHT,0);
  }
//+------------------------------------------------------------------+
//| Put Text Function                                                |
//+------------------------------------------------------------------+
void Text(string name,const string text,double price,datetime time,const color clr)
  {
   ObjectDelete(0,name);
//--- create a "Text" object 
   ObjectCreate(0,name,OBJ_TEXT,0,time,price);
//--- set the text
   ObjectSetString(0,name,OBJPROP_TEXT,text);
//--- set the font of the text
   ObjectSetString(0,name,OBJPROP_FONT,"Arial");
//--- set the font size
   ObjectSetInteger(0,name,OBJPROP_FONTSIZE,9);
//--- set the method binding
   ObjectSetInteger(0,name,OBJPROP_ANCHOR,4);
//--- set the color
   ObjectSetInteger(0,name,OBJPROP_COLOR,clr);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
   double hi1=iHigh(NULL,PERIOD_D1,1);
   double lo1=iLow (NULL,PERIOD_D1,1);

   for(int i=1;i<days;i++)
     {
      double hi=iHigh(NULL,PERIOD_D1,i);
      double lo=iLow (NULL,PERIOD_D1,i);
      datetime tm1=iTime(NULL,PERIOD_D1,i-1);
      datetime tm2=iTime(NULL,PERIOD_D1,i);
      datetime tm=(tm1+tm2)/2;
      int range=(int)((hi-lo)/_Point/10);

      PutTrendLine("Hi"+(string)i,tm1,hi,tm2,hi,upcolor);
      PutTrendLine("Lo"+(string)i,tm1,lo,tm2,lo,dncolor);
      Text("Text"+(string)i,(string)range,hi,tm,txtcolor);
     }

   if(num<count)
     {
      if(alert)
        {
         if(Bid<hi1+delta*_Point && Bid>hi1-delta*_Point) Alert(_Symbol+" Цена около уровня: ",hi1);
         if(Bid<lo1+delta*_Point && Bid>lo1-delta*_Point) Alert(_Symbol+" Цена около уровня: ",lo1);
        }
      if(mail)
        {
         if(Bid<hi1+delta*_Point && Bid>hi1-delta*_Point) SendMail("Signal",_Symbol+" Цена около уровня: "+(string)hi1);
         if(Bid<lo1+delta*_Point && Bid>lo1-delta*_Point) SendMail("Signal",_Symbol+" Цена около уровня: "+(string)lo1);
        }
      num++;
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+

avatar

AM2

  • 7 мая 2019, 19:35
0
дайте ссылку на индикатор в базе, чтобы я мог его обновить
avatar

AM2

  • 7 мая 2019, 19:17
0
пока есть только открытие по индикатору:




//+------------------------------------------------------------------+
//|                                                         Reno.mq5 |
//|                                              Copyright 2019, AM2 |
//|                                      http://www.forexsystems.biz |
//+------------------------------------------------------------------+
#property copyright "Copyright 2019, AM2"
#property link      "http://www.forexsystems.biz"
#property version   "1.00"

#include <Trade\Trade.mqh> 

CTrade trade;

input int mag=123;
input int slip=33;
input double lot=0.1;
input string IndName="RenkoChart";

int rn=0;
double last=0;
double op[1],cl[1];

//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---
   rn=iCustom(NULL,0,IndName);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
   CopyBuffer(rn,0,1,1,op);
   CopyBuffer(rn,3,1,1,cl);

   double bid=SymbolInfoDouble(Symbol(),SYMBOL_BID);
   double ask=SymbolInfoDouble(Symbol(),SYMBOL_ASK);

   if(last!=op[0])
     {
      if(cl[0]>op[0]) trade.Buy(lot,_Symbol,ask);
      if(cl[0]<op[0]) trade.Sell(lot,_Symbol,bid);
      last=op[0];
     }

   Comment("\n Open: ",op[0],
           "\n Close: ",cl[0]);
  }
//+------------------------------------------------------------------+



язык непрофильный, провозился довольно долго.
avatar

AM2

  • 6 мая 2019, 22:30
0
нужны скрины с пояснениями
avatar

AM2

  • 5 мая 2019, 18:46