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

 
Roman:

Because minute timeframes below H1 return the correct values.
As described in the help, they return timeframe value, not an out-of-the-box constant.

What nonsense?

Wipe your eyes, I showed you the internal representation of ENUM_TIMEFRAMES

bit 16 which is set determines the weekly and monthly timeframe

bit 15 set defines the hourly time TF, where TF D1 = 1000000011000 --> 11000 --> 24, i.e. the developers have compared D1 to 24 hours and the remaining hourly time TFs correspond to the decimal conversion

the minute timeframes are the same as the hour ones, but the high bits are reset


another issue is that you thought the functions returning ENUM_TIMEFRAMES return the time of the TF in minutes - this is not true, these functions return the ENUM_TIMEFRAMES enumeration - no more or less, just ENUM_TIMEFRAMES

see the example from the helpat https://www.mql5.com/ru/docs/basis/types/integer/enumeration.

enums can also be with assignment of any constant value to a member of the enum

You can create your own enumeration to suit your needs

 

Thank you so much! It waswchar_t that helped! I read about it, it stores 2 bytes per character, unlike char.


extern "C" __declspec(dllexport) wchar_t* __stdcall ToString(wchar_t* str)

{

        str = L" - 889 - dsa - просто!";

        return L"--- Привет! ---";

}


But the "str" function parameter still doesn't return the value assigned to it... I wonder why...

 

Hello, could you tell me how to solve a problem? I want to write an EA based on an indicator (tied to the iron) that builds a lot of levels (lines) on the chart, the number of lines can reach 500.

All I want to implement is to open an order or any other event (like alert or message) when price crosses lines on the chart. But the problem is that the indicator does not return any values and only draws horizontal lines (objects with names) - there is nothing else on the chart.

I tried to find a solution through the iCustom function that retrieves price levels via the "_price" variable, but the EA does not open trades when lines are touched. I do not know what I have done wrong.

void OnTick()
  {
  
ENUM_OBJECT typeObj = OBJ_HLINE;
string   ArrLines[];
  
  double 
  Price;
  Price=Bid;
  
//ВАРИАНТ 1 (не получился). Я хотел, чтобы ордер открывался при пересечении любой из линий на графике   
  
//вызовем индикатор: (пара, таймфрейм, индикатор...)
iCustom(Symbol(), 0, "ITS-Level Gun", 0, 0); 

int i, k = ObjectsTotal();

ArrayResize(ArrLines, 0);

//в цикле перебираем все объекты на графике
for (i=k-1; i>=0; i--) {
  
  //узнаем имя объекта на графике
  string _name = ObjectName(i);

{

    //узнаем координату цены линии
    double _price = NormalizeDouble(ObjectGetDouble(0, _name, OBJPROP_PRICE), Digits);
  } 
}

if(Price==_price)
{OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-15*Point,Bid+15*Point);}

    // И ВСЁ, дальше не знаю, что делать


     
    } 
 
  }

OPTION 2. An order is opened on the line I have specified in the settings, it works and opens trades at the level I have specified in the EA parameters


extern string h="@Line_week_open-0"; //ИЗМЕНЕНИЕ ННАЗВАНИЯ ЛИНИИ В СВОЙСТВАХ СОВЕТНИКА.ВАРИАНТ 2.

if(ObjectFind(h)>-1)

    {

     double prise = ObjectGet(h, OBJPROP_PRICE1);

     if (Price==prise)

      {OrderSend(Symbol(),OP_BUY,0.1,Ask,3,Bid-15*Point,Bid+15*Point);}       

    } 
Files:
we3s6_kgeqx.jpg  151 kb
 
Fib0 RU:

Hello, could you tell me how to solve a problem? I want to write an EA based on an indicator (tied to the iron) that builds a lot of levels (lines) on the chart, the number of lines can reach 500.

All I want to implement is to open an order or any other event (like alert or message) when price crosses lines on the chart. But the problem is that the indicator does not return any values and only draws horizontal lines (objects with names) - there is nothing else on the chart.

I tried to find a solution through the iCustom function that retrieves price levels via the "_price" variable, but the EA does not open trades when lines are touched. I do not know what I have done wrong.

OPTION 2, an order is opened at the line I have specified in the settings; it works and opens trades at that level, which I have specified in the EA parameters



for(int i = ObjectsTotal() - 1; i >=0; i--) {

        // все что не горизонтальные линии - игнорируем

        if(ObjectType(ObjectName(i)) != OBJ_HLINE) continue; 

        double PriceLine = NormalizeDouble(ObjectGet(ObjectName(i), OBJPROP_PRICE1), Digits());
	
	// измените условие Bid == PriceLine
        
	 if(Bid == PriceLine) {

                // ..... тут что-то происходит ... 

        }
}


BUT, what if the Bid for some reason jumped the line, and was not equal to the price of the line, then what? Provide then at least a variable that stores the previous tick, and if it was a new tick crossed your line - then do some action ... But in this case do not forget to provide "permissible" crossing, because if the market opens with a large Gap, or there is a large jump in price, you will open on many lines in one go and probably not on the place you want. If the crossing is bigger than allowed - only a message will be given...

 
Vadim Lin:



BUT, what if the Bid for some reason crossed the line, and was not equal to the line price, then what...? Provide then at least a variable, in which previous tick is stored, and if there was a new tick crossing your line - then do some action... But in this case do not forget to provide "permissible" crossing, because if the market will open with a Gap large, or just a big jump in price, you will open on many lines in one go and probably not there where you want. If the crossing is bigger than allowed - only a message will be given...

Problem code.

 
Igor Makanu:

What nonsense?

Wipe your eyes, I showed you the internal representation of ENUM_TIMEFRAMES

bit 16 which is set determines the weekly and monthly timeframe

bit 15 is set to determine the hourly time TF and TF D1 = 1000000011000 --> 11000 --> 24, i.e. the developers have compared D1 to 24 hours and the remaining hourly time TFs correspond to the decimal conversion

the minute timeframes are the same as the hour ones, but the high bits are reset


another issue is that you thought the functions returning ENUM_TIMEFRAMES return the time of the TF in minutes - this is not true, these functions return the ENUM_TIMEFRAMES enumeration - no more or less, just ENUM_TIMEFRAMES

see the example from the helpat https://www.mql5.com/ru/docs/basis/types/integer/enumeration.

enums can also be with assignment of any constant value to a member of the enum

You can create your own enumeration to suit your needs

Igor, it's been clear for a long time about constant values.
That's what I'm talking about, what is the meaning of 15 and 16 bits as a return value. This is just nonsense.
For some reason before M30 ENUM constants corresponded toTIMFRAME values!!!!.
And further it already corresponds to values of some bits
. Where the hell is the logic in guys.
This is a crude error. If it was done so intentionally, it's a diversion.)
Variable _Period already contains all these timeframe values from enumeration ENUM, they don't need additional conversion.
Therefore, these constant values, should correspond to timeframe values as stated in the help. Not BITS!

 
Roman:

It's definitely time for quarantine. Search for everything that has been said about it and read it at your leisure. Why do you think people around you have to repeat everything you've written?

 
Alexey Viktorov:

It's definitely time to quarantine it. Search everything that was said about it and read it at your leisure. Why do you think that people around you should repeat everything you have written?

And why do you put up with the wrong solutions? I have delivered a logical explanation of the values of the constants, not what the developer made up.

 
Roman:

And why do you put up with the wrong solutions? I have delivered a logical explanation of the values of the constants, not what the developer made up.

Apparently for you there are only two opinions: yours and the wrong one. You may be able to find an explanation that suits you.
 
Alexey Viktorov:
Apparently for you there are only two opinions: yours and the wrong one. You may be able to find an explanation that suits you.

Try to use the value returned by _Period variable for periods higher than H1 in your mathematical calculations.
And you will immediately understand who is wrong.

Reason: