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

 
STARIJ:

Artem, either it's unobtrusive trolling or you don't know what you're writing about!!!

In your last post you talked about sorting. Explained to you that there is no dependence on sorting.

I've seen and PARTICIPATED in one of the discussions about order selection by time. The conclusion was that orders are now placed in the order database according to the time they were sent to the server. But THEORETALLY there is a fear that the developers may change this. That was the end of that discussion. As a database specialist I assure you that this fear is unfounded, a change is out of the question. You can refer the issue to the developers. If I write something, I know what I write. It's the 50th anniversary of programming. If you notice in my posts some mess from your point of view - write to me in person. I will explain, and your doubts will dispel. But here bicker unlikely to be appropriate. I wrote the man a script - he said thank you. Isn't it good?

That's what all those people who suddenly found themselves dependent on sorting, thought the same. People's logic collapsed. Then the dependence on sorting disappeared again. But it already has. If you want to depend not on your program, but on a hypothetical invariant sorting, you have the right, but in beginner's help thread you have no such right - to give a script and not to mention the fact that it may fail one day. Look for such discussions on mql4.com - about 6 - 7 years ago.

That's what I mentioned - the person was talking about stoploss, not loss.

Thanks he said - polite, but he doesn't know if it's right or wrong ;)

 
Artyom Trishkin:

That's what I mentioned - the man was talking about stoploss, not loss.

He said thank you - it's polite, but he doesn't know if it's right or wrong ;)

Look carefully at what the man has written.

X = OrderProfit( );        // запомнить величину тейкпрофита

if (OrderSelect (Ht-1,SELECT_BY_POS, MODE_HISTORY))     // если ПОСЛЕДНИЙ ордер                  
if ( OrderType ()==OP_SELL)  // СЕЛ

if(X < 0)                 // и если этот сел закрылся по стопу 

It follows that he was referring to losing orders. That's how he understands stoploss. He does not have the wordstoploss.

I also wanted to write that the stops are a generalized name for StopLoss and TakeProfit. To see this, type 130 in MetaEditor and press F1

Stops. Plural.

I am working here, you are distracting me.

Let's better say datetime --> TimeToStruct -->MqlDateTime How to convert back to datetime now ???

 
STARIJ:

Look carefully at what the man wrote

It follows that he was referring to losing orders. This is how he understands stop. He does not have the wordstoploss.

I also wanted to tell him that stops are a generalized name for StopLoss and TakeProfit. To see this, type 130 in MetaEditor and press F1

Stops. Plural.

I am working here, you are distracting me.

Let's better say datetime --> TimeToStruct -->MqlDateTime How to convert back to datetime ???

if(X < 0)                 // и если этот сел закрылся по стопу 

StructToTime()

 
виталик: On the hourly chart a line was drawn between high and low
//+-------------------------------------------------------+
//| на H1 суточную линию между хая и лоу         PROBA.mq4|
//+-------------------------------------------------------+
#property strict

void OnStart()
{
  // Удалим все объекты
  ObjectsDeleteAll();

  string Символ = "GBPUSD";
  datetime Первый, Последний;
  int Период=PERIOD_H1;

  // Прежде всего узнаем дату и время последнего бара
  Последний = iTime(Символ, Период, 0);
  Alert("Последний бар на часовом  ",Последний);

  // Теперь получить начало суток, обнулив часы
  // Для этого преобразуем время последнего бара в структуру
  MqlDateTime MqlПервый;
  TimeToStruct(Последний,MqlПервый);
  MqlПервый.hour=0;



  // Терерь надо обратно преобразовать во время
  Первый=StructToTime(MqlПервый);
  Alert("Первый бар на часовом  ",Первый); // Смотрим начало первого бара суток

  // По времени определим номер первого бара суток
  int НомерПервого=iBarShift(Символ, PERIOD_H1,Первый);
  Alert("Первый бар на часовом под номером ",НомерПервого);

// Можно было просто узнать время начала бара на D1


  
  // Теперь у нас есть НомерПервого бара, а номер послелнего = 0
  // Найдем на этом интервале номера баров, где макс и мин
  // iHighest и iLowest находят номер бара с макс и мин ценой
  int БарМакс = iHighest(Символ,  // symbol = инструмента
                Период,           // timeframe = Период
                MODE_HIGH,        // Наибольшая цена бара
                НомерПервого+1,   // Количество баров
                0);               // Начальный бар

  int БарМин  = iLowest(Символ,
                Период,
                MODE_LOW,         // Наименьшая цена бара
                НомерПервого+1,
                0);

  Alert("Максимальный бар = ", БарМакс, "  Минимальный бар = ", БарМин);

  // iHigh и iLow дают макс и мин цены указанного бара
  double max_price=iHigh(Символ, Период, БарМакс);
  double min_price=iLow (Символ, Период, БарМин);
  Alert("Максимум цены = ", max_price, "  Минимум цены = ", min_price);

  // Проводим линию
  ObjectCreate("Макс_Мин",OBJ_TRENDBYANGLE,0, Time[БарМакс], max_price, Time[БарМин], min_price);
  ObjectSet("Макс_Мин",OBJPROP_RAY,false);     // Выключить свойство бесконечного луча

  // Теперь хорошо бы узнать угол
  Alert("Угол = ", ObjectGetDouble(0,"Макс_Мин",OBJPROP_ANGLE));
}

// It returns 0.0 The angle should be set and then it should be obtained...
// So, knowing the price difference and the number of bars between Max and Min, the angle should be calculated.
// I guess it could be shorter...

 
STARIJ:

// Returns 0.0 The angle should be set and then obtained...
// So, knowing the price difference and the number of bars between Max and Min, the angle should be calculated
// I guess it could be shorter...


thanks a lot )
 
Artyom Trishkin:   StructToTime()
Thanks, I've found it. Turns out I've already used it. Was expecting to see it in help for one of datetime TimeToStruct MqlDateTime
 
-Aleks-:

Ugh, I can't figure out how to add variables - i.e. let's say I have 4 boolean variables and need to go through them?

I understand the point - the remainder should be less or more than zero after division - but I can't figure out how to do it :(


For boolean ones the approach is slightly different

//+------------------------------------------------------------------+
//|                                                       Decode.mq4 |
//|                                            Copyright 2017, Vinin |
//|                                             http://vinin.ucoz.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright 2017, Vinin"
#property link      "http://vinin.ucoz.ru"
#property version   "1.00"
#property strict
#property script_show_inputs
//--- input parameters
input int N=15;  //0..162
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
   for(int n=0;n<N;n++)
     {
      int tmp=n;
      bool a= (bool) MathMod(tmp,2);
      tmp=tmp/2;
      bool b= (bool) MathMod(tmp,2);
      tmp=tmp/2;
      bool c= (bool) MathMod(tmp,2);
      tmp=tmp/2;
      bool d= tmp;

      Print("N=",n,"; A=",a,"; B=",b,"; C=",c,"; D=",d);
     }

  }

Binary coding.

Maximal N in this case is less than 16.

I can not understand what you want to get

 
Victor Nikolaev:


For boolean ones the approach is slightly different

binary coding.

The maximum N in this case is less than 16

I can't understand what you're trying to get.

You're a genius! Thank you!

I got 16 options.

2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=15; A=true; B=true; C=true; D=true
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=13; A=true; B=false; C=true; D=true
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=9; A=true; B=false; C=false; D=true
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=1; A=true; B=false; C=false; D=false
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=5; A=true; B=false; C=true; D=false
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=3; A=true; B=true; C=false; D=false
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=11; A=true; B=true; C=false; D=true
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=7; A=true; B=true; C=true; D=false
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=14; A=false; B=true; C=true; D=true
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=6; A=false; B=true; C=true; D=false
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=10; A=false; B=true; C=false; D=true
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=2; A=false; B=true; C=false; D=false
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=12; A=false; B=false; C=true; D=true
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=4; A=false; B=false; C=true; D=false
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=8; A=false; B=false; C=false; D=true
2017.05.14 20:47:54.697 Brut AUDUSD,H1: N=0; A=false; B=false; C=false; D=false

What I want to use it for - I have a number of filters and position management options in my EA - I want to combine them, including making mini-sets (pre-made combinations) - as a result I will get data for analysis, while not being biased towards the sample, which hopefully will expand the horizons of perception of the settings influence on the result. The result will be a series of results which I will analyze in detail. And, there's another reason, I have a class for collecting statistics that saves a limited number of variables to a file, which prevents detailed analysis.
 
виталик:

thanks a lot )

STARIJ:

// Returns 0.0 The angle should be set and then obtained...
// So, knowing the price difference and the number of bars between Max and Min, the angle should be calculated
// I guess it could be shorter...


I think I need to look at the chart as an indicator, but I think I need to look at the chart as an indicator, so I can see how to get it to work more than one day.

#property indicator_chart_window
extern int boom = 1;
//=================================
void fishka(int ma,int mi,double map,double mip) // ф-ция
{
   ObjectCreate("Макс_Мин",OBJ_TRENDBYANGLE,0, Time[ma], map, Time[mi], mip);// Проводим линию
   ObjectSet("Макс_Мин",OBJPROP_RAY,false);     // Выключить свойство бесконечного луча
}

int deinit()
  {

 ObjectsDeleteAll();// Удалим все объекты
  return(0);
  }

void start()
{  
  string Символ = "GBPUSD";
  datetime Первый, Последний;
  int Период=PERIOD_H1;

  Последний = iTime(Символ, Период, 0);// Прежде всего узнаем дату и время последнего бара
 
if(boom){
   Alert("Последний бар на часовом  ",Последний);}
 
  
  MqlDateTime MqlПервый;              // Теперь получить начало суток, обнулив часы
  TimeToStruct(Последний,MqlПервый);  // Для этого преобразуем время последнего бара в структуру
  MqlПервый.hour=0;

  
  Первый=StructToTime(MqlПервый);            // Терерь надо обратно преобразовать во время
if(boom){
  Alert("Первый бар на часовом  ",Первый);}  // Смотрим начало первого бара суток
  
  int НомерПервого=iBarShift(Символ, PERIOD_H1,Первый);// По времени определим номер первого бара суток
if(boom){
   Alert("Первый бар на часовом под номером ",НомерПервого);}

// Можно было просто узнать время начала бара на D1

  // Теперь у нас есть НомерПервого бара, а номер послелнего = 0
  // Найдем на этом интервале номера баров, где макс и мин
  // iHighest и iLowest находят номер бара с макс и мин ценой
 int  БарМакс = iHighest(Символ,  // symbol = инструмента
                Период,           // timeframe = Период
                MODE_HIGH,        // Наибольшая цена бара
                НомерПервого+1,   // Количество баров
                0);               // Начальный бар

int  БарМин  = iLowest(Символ,Период,MODE_LOW,НомерПервого+1,0); // Наименьшая цена бара
                               
if(boom){
  Alert("Максимальный бар = ", БарМакс, "  Минимальный бар = ", БарМин);}
                                                                           

 
double max_price=iHigh(Символ, Период, БарМакс); // iHigh и iLow дают макс и мин цены указанного бара
double min_price=iLow (Символ, Период, БарМин);
   
    fishka(БарМакс,БарМин,max_price,min_price); // ф-ция
 if(boom){
   Alert("Максимум цены = ", max_price, "  Минимум цены = ", min_price);
 
   Alert("Угол = ", ObjectGetDouble(0,"Макс_Мин",OBJPROP_ANGLE));} // Теперь хорошо бы узнать угол               
}
 
STARIJ:

If at 4am - not many bars yet for today. On H4 there are only 6 bars in a day. you have to set the number of bars to search for or the number of crossings.

Long distances = trend

I tried to run it as a script, it works, but if I compile it as an EA, all lines are close to each other and I dont understand what is the problem
Reason: