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

 
Maxim Kuznetsov:

something like this :

string level="Level"+IntegerToString(iTime(_Symbol,iBarShift(OrderCloseTime())); // ид.уровня - по времени бара (!! не по тикету)

if (ObjectFind(level)‌==-1) {

  // гор.вектора нет - видимо первый ордер из закрытых на баре

  // сделать горизонтальную линию‌

  ObjectCreate(0,level,OBJ_TREND,0,OrderCloseTime(),OrderClosePrice(),OrderCloseTime()+PeriodSeconds(_Period)*3,OrderClosePrice);

 // указывающую только вправо‌

  ObjectSetInteger(level,‌OBJPROP_RAY,1);

  ObjectSetInteger(level,OBJPROP_RAYLEFT,0);

‌ // украсить её как-то :-)

 ObjectSetInteger(level,OBJPROP_‌COLOR,....)

 ....‌

} else {

  // гор.уровень есть - значит были ордера закрытые на этом баре

  // по фантазии - обновить метки/корректировать уровень/etc‌

}‌

int TotalPos=-1;

void start()
 
{
 // остальной код

//--
  if(OrdersTotal()!=TotalPos) { // не мучаем каждый тик
   for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
     if(OrderSymbol()==Symbol() && OrderType()<=1) {
      History();

  
     }
  }}} TotalPos=OrdersTotal(); // запомним количество
//--
}
 
 
 
 void History() {
  string Ticket=(string)OrderTicket();
  color col=Red;
  if(OrderType()==0)col=Blue;
  datetime a=OrderOpenTime();
  double b=OrderOpenPrice();
  datetime c=OrderCloseTime();
  double d=OrderClosePrice();
  double prSep=OrderProfit()+OrderCommission()+OrderSwap();
  double prAll=0;
  int    cn=0;
  string hTicket;
   for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
     if(OrderSymbol()==Symbol() && OrderType()<=1) {
      datetime ct=OrderCloseTime();
      // 60 секунд разницы между закрытием первой и последней в сетке
      if(c<=ct+60 && c>=ct-60) {
        prAll+=OrderProfit()+OrderCommission()+OrderSwap();
        hTicket=(string)OrderTicket();
        cn++;
      }
   }}}
   ObjectCreate(Ticket+"Open",OBJ_ARROW,0,a,b);
   ObjectSet(Ticket+"Open",OBJPROP_COLOR,col);
   ObjectSet(Ticket+"Open",OBJPROP_ARROWCODE,1);
     
   ObjectCreate(Ticket+"Line",OBJ_TREND,0,a,b,c,d);
   ObjectSet(Ticket+"Line",OBJPROP_COLOR,col);
   ObjectSet(Ticket+"Line",OBJPROP_WIDTH,1);
   ObjectSet(Ticket+"Line",OBJPROP_STYLE,STYLE_DOT);
   ObjectSet(Ticket+"Line",OBJPROP_RAY,0);
     
   ObjectCreate(Ticket+"Close",OBJ_ARROW,0,c,d);
   ObjectSet(Ticket+"Close",OBJPROP_COLOR,Green);
   ObjectSet(Ticket+"Close",OBJPROP_ARROWCODE,3);
 
   Ticket=cn>1?hTicket:Ticket;
   ObjectCreate(Ticket+"Profit",OBJ_TEXT,0,c,d);
   ObjectSet(Ticket+"Profit",OBJPROP_ANCHOR,0);
   ObjectSetText(Ticket+"Profit",DoubleToString(prAll,2),10,"Arial",White);
   ObjectSet(Ticket+"Profit",OBJPROP_PRICE1,d);
   ObjectSet(Ticket+"Profit",OBJPROP_TIME1,c+Period()*60*2);
}

Using a vector as a level finder is wrong.... not good ....((

What if we make a horse move)

In the level search use the principle of profit summation at the price level the record of which already exists...

For example: here we've made a try and added up the profits with a 60 second delay

 for(int i=OrdersHistoryTotal()-1; i>=0; i--) {
    if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) {
     if(OrderSymbol()==Symbol() && OrderType()<=1) {
      datetime ct=OrderCloseTime();
      // 60 секунд разницы между закрытием первой и последней в сетке
      if(c<=ct+60 && c>=ct-60) {
        prAll+=OrderProfit()+OrderCommission()+OrderSwap();
        hTicket=(string)OrderTicket();
        cn++;

Next, we need to come up with a record :

If the number of accumulated profits at the level > 1, then this is our order - our level, from this level we draw a ray

 

Greetings.

I am planning an EA with functions that on every tick will loop through the available orders created by it and act depending on the situation.

Can you advise how to make separate variables for each new order and for further loops to work with them? (I assume this is something like Peremennaja+ticket=12345;)

 
Andrey Sokolov:

Greetings.

I am planning an EA with functions that on every tick will loop through the available orders created by it and act depending on the situation.

Can you advise how to make separate variables for each new order and for further loops to work with them? (I assume this is something like Peremennaja+ticket=12345;)

Preferably an array or even an array of structures.
 
Alexey Viktorov:
Better an array or even an array of structures.

I'm sorry, can you elaborate?
 
Andrey Sokolov:

Excuse me, could you go into more detail?


Here and here.

A structure and an array of structure type is created. Outside of all the code.

struct trade_settings
  {
   double take;         // значения цены фиксации прибыли
   double stop;         // значение цены защитного стопа
   uchar  slippage;     // значение допустимого проскальзывания
  };
//--- создали массив типа trade_settings
trade_settings my_set[];
// присвоить значение нулевому индексу массива в основном коде
my_set[0].take = что_то;
Структуры и, классы и интерфейсы - Типы данных - Основы языка - Справочник MQL4
Структуры и, классы и интерфейсы - Типы данных - Основы языка - Справочник MQL4
  • docs.mql4.com
Структуры и, классы и интерфейсы - Типы данных - Основы языка - Справочник MQL4
 

Hello.

Please help me find the intersection of the horizontal line "ResisL" andthe trend line by the angle "TrndL"

TRA
 
Nikolay Fedyay:

Hello.

Please help me find the intersection of the horizontal line "ResisL" andthe trend line by the angle "TrndL"

//+------------------------------------------------------------------+
//| Уравнение прямой                                                 |
//+------------------------------------------------------------------+
double EquationDirect(double left_bar, double left_price, double right_bar, double right_price, double bar_to_search) {
  return((right_bar==left_bar)?left_price:(right_price-left_price)/(right_bar-left_bar)*(bar_to_search-left_bar)+left_price);
}
//+------------------------------------------------------------------+
If you know two coordinate points of the slope line and paste them as paramaters of this function, the output will give you the price of the point on the bar_to_search. It only remains to call this function in the bar loop and compare the value it returns with the price of the horizontal line. If on the last bar of the cycle the value returned by the function was lower or equal to the price of the horizontal line, and on the current bar of the cycle the value returned by the function is greater than the line price, then the X coordinates of the crossing point will be the time corresponding to the cycle index and the Y coordinates will be the price returned by the function.
 
Artyom Trishkin:

Thank you.

How about if you want to know the crossover point when there are no bars yet, i.e. a date in the future.

 
Nikolay Fedyay:

Thank you.

How about if you want to know the crossover point when there are no bars yet, i.e. a date in the future.

Haven't tried this function - need to experiment.

 
Artyom Trishkin:

Haven't tried this function - need to experiment.

Please, if you find time to experiment, share the result.

Because I have no idea what to experiment with
.