Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 1928

 
Maxim Kuznetsov #:

most likely - ex4 was built with an old compiler. The terminal has been updated, but the EA is ancient orphan. We need to contact the author

The second option - the signatures do not match (or have not verified for technical reasons). You just need to wait until DNS updates and the connection will be set up.

Hypothetical option - the author is permanently banned. Look at his profile

To sum it up: first you have to ask the author questions.

Thank you

 
Vitaly Muzichenko #:

Difficult, I'd like to turn in something suitable already. He's fine with just visualising levels and moving stops to past levels, that's enough of that. Didn't expect such a catch. If he hadn't been gone for a long time, I would have, but not now. I don't want arbitrage, I already have it.

Oninit calculates levels and draws. For a different task, but close by. Your part is for Absolute levels.

Zy, I don't have much wrong with it of course. I need to understand how orders, positions and trawl are tracked, it's easy to draw, but when you reach a level, you either have to change the colour of the level, or remove the horizontal line.
Files:
 
Valeriy Yastremskiy #:

OnInit calculates levels and draws. For a different task, but side by side. Your part is for Absolute levels.

Zy, I certainly don't have much wrong with it. I need to understand how orders, positions and trawl are tracked, it's easy to draw then. but when you reach a level you either have to change the colour of the level, or remove the horizontal line.

What could)))) need to add trigger flags to crossfunction. don't have time.

input double   PriceOrder=0.0;         // Цена ордера, 
input int TralStep=300;                  // Шаг отслеживания SL  
input int NumberLevels=7;            // Kоличество уровней для выбранного метода ВВЕРХ

input bool FlagShowLine=true;              // Рисовать / не рисовать уровни



//---


double LevelPrice[10];                 // Количество уровней не более 10.
string HLineName[10];
bool Del=true;

string MsgAlert,Tip;

int CurLevel;


//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---Расчет ценовых уровней

CalculationOfLevels(PriceOrder,TralStep,NumberLevels,Tip);



if(FlagShowLine)
{
ShowLine(Tip);
}
//--- create timer
   EventSetTimer(60);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
  
  Comment("");
  
   int obj_total=ObjectsTotal();
      PrintFormat("Всего %d объектов",obj_total);
      for(int i=obj_total-1; i>=0; i--)
        {
         string name=ObjectName(i);
 //        PrintFormat("Объект %d: %s",i,name);
         ObjectDelete(name);
        }
//--- destroy timer
   EventKillTimer();
   
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   CrossingLevel(CurLevel,Tip);
  }
//+------------------------------------------------------------------+
//| Timer function                                                   |
//+------------------------------------------------------------------+
void OnTimer()
  {
//---
   
  }
//+------------------------------------------------------------------+
//| Tester function                                                  |
//+------------------------------------------------------------------+
double OnTester()
  {
//---
   double ret=0.0;
//---

//---
   return(ret);
  }
//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---
   
  }
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+ 
//| Создает горизонтальную линию                                     | 
//+------------------------------------------------------------------+ 
bool HLineCreate(const long            chart_ID=0,        // ID графика 
                 const string          name="HLine",      // имя линии 
                 const int             sub_window=0,      // номер подокна 
                 double                price=0,           // цена линии 
                 const color           clr=clrRed,        // цвет линии 
                 const ENUM_LINE_STYLE style=STYLE_SOLID, // стиль линии 
                 const int             width=1,           // толщина линии 
                 const bool            back=true,        // на заднем плане 
                 const bool            selection=false,    // выделить для перемещений 
                 const bool            hidden=false,       // скрыт в списке объектов 
                 const long            z_order=0)         // приоритет на нажатие мышью 
  { 
//--- если цена не задана, то установим ее на уровне текущей цены Bid 
   if(!price) 
      price=SymbolInfoDouble(Symbol(),SYMBOL_BID); 
//--- сбросим значение ошибки 
   ResetLastError(); 
//--- создадим горизонтальную линию 
   if(!ObjectCreate(chart_ID,name,OBJ_HLINE,sub_window,0,price)) 
     { 
      Print(__FUNCTION__, 
            ": не удалось создать горизонтальную линию! Код ошибки = ",GetLastError()); 
      return(false); 
     } 
//--- установим цвет линии 
   ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr); 
//--- установим стиль отображения линии 
   ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style); 
//--- установим толщину линии 
   ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,width); 
//--- отобразим на переднем (false) или заднем (true) плане 
   ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back); 
//--- включим (true) или отключим (false) режим перемещения линии мышью 
//--- при создании графического объекта функцией ObjectCreate, по умолчанию объект 
//--- нельзя выделить и перемещать. Внутри же этого метода параметр selection 
//--- по умолчанию равен true, что позволяет выделять и перемещать этот объект 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection); 
   ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection); 
//--- скроем (true) или отобразим (false) имя графического объекта в списке объектов 
   ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden); 
//--- установим приоритет на получение события нажатия мыши на графике 
   ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order); 
//--- успешное выполнение 
   return(true); 
  } 
  
  //+------------------------------------------------------------------+
  //| Поиск ближайших уровней                                          |
  //+------------------------------------------------------------------+  
void  ShowModify(string name, string tip, bool del)
  {
  if(del){
ObjectDelete(name);
  }
  if(!del){
 if(tip=="Sell"){
  ObjectSetInteger(0,name,OBJPROP_COLOR,clrGold);
 } 
  if(tip=="Buy"){
  ObjectSetInteger(0,name,OBJPROP_COLOR,clrCoral);
 } 
 }
 }
 
 //+------------------------------------------------------------------+
 //| Мониторинг пересечения уровней                                   |
 //+------------------------------------------------------------------+
 
bool CrossingLevel(int level, string tip)
{
if((tip=="Buy" && Bid > LevelPrice[level]) || (tip=="Sell" && Ask < LevelPrice[level])){
CurLevel=level++ ;
return(true);
}
return(false);
}



void CalculationOfLevels(double priceorder, int trstep, int numberl, string tip){

//---Расчет ценовых уровней

for(int i=0; i<=(numberl); i++){
if(tip=="Buy"){
LevelPrice[i] =  priceorder + trstep*Point;
if(tip=="Sell"){
LevelPrice[i] =  priceorder - trstep*Point;

}
}
CurLevel=1;
}
}
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void ShowLine(string tip)
{
color ClrLine=clrRed;
if(tip=="Buy") ClrLine=clrBlue;
if(tip=="Sell") ClrLine=clrRed;
for(int i=0;i<=(NumberLevels);i++){

//Alert("ShowLine_",ShowLine,"__",LevelPrice[i],"__",ClrLine);
HLineName[i]="LevelPrice_"+(string)i+"_"+(string)LevelPrice[i];

HLineCreate(0,HLineName[i],0,LevelPrice[i],(color)ClrLine,STYLE_SOLID,1);
}
}
Files:
ShowLevel.mq4  16 kb
 
Valeriy Yastremskiy #:

What I could))) need to add trigger flags to the crossfunction. don't have time.

It's a bit off the mark.

I have an EA written a long time ago, but it is an EA showing where the positions will be opened


Now I need to make an addition in the trawl code to draw such lines where the trawl will be triggered.

The task is complicated by the fact that the trawl EA is set on one chart and lines should be drawn on all charts where there are open positions.

Files:
 
Vitaly Muzichenko #:

That's a little bit off the mark.

I have a long written one like this, but it is an EA with a display of where the positions will be opened


Now we need to make an addition in the code of the trawl to draw such lines where the trawl will be triggered.

The task is complicated by the fact that the trawl EA is set on one chart and lines should be drawn on all charts where there are open positions.

Are all the windows already open, or are they opened by the EA as positions emerge? The challenge is to find a chart)
 
Valeriy Yastremskiy #:
Are all windows already open, or are they opened by the EA as positions arise? The challenge is to find a chart)

I assume that if there is a position, the window is open.

 
A question has arisen. How to know the number of open windows and their IDs. I found only getting id of the first, current and next window. I understand correctly that we can't get the total, but only the first, non-ext and how to understand that there is no next window.
 
Valeriy Yastremskiy #:
A question has arisen. How to know the number of open windows and their IDs. I found only getting id of the first, current and next window. I understand correctly that we can't get the total, but only the first, non-ext and how to understand that there is no next window.
    long currChart=ChartFirst();
    int i=0;
    while(i<CHARTS_MAX) {
      if(ChartSymbol(currChart)==symbol)
        break;
      currChart=ChartNext(currChart);
      if(currChart==-1) break;
      i++;
    }
    symb=ChartSymbol(currChart);
 
Vitaly Muzichenko #:

It cannot be assumed that windows are open for all open positions. Therefore the algorithm should search for a window with the required symbol, and if it is absent, open a window and draw the situation. I.e. levels, then find on which SL modification occurred, and either delete or change colour of level.

 
Valeriy Yastremskiy #:

It cannot be assumed that windows are open for all open positions. Therefore the algorithm should search for a window with the required symbol, and if it is absent, open a window and draw the situation. I.e. levels, then find on which SL modification occurred and either delete or change colour of level.

Put a flag, if there is an open window, then draw, if there is no open - skip. There is no sense to open and draw if it is not opened/closed

    long currChart=ChartFirst();
    int i=0;
    flag=false;
    while(i<CHARTS_MAX) {
      if(ChartSymbol(currChart)==symbol) {
        flag=true;
        break;
      }
      currChart=ChartNext(currChart);
      if(currChart==-1) break;
      i++;
    }
    if(flag) {
    symb=ChartSymbol(currChart);
    ...
Reason: