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

 
psyman:

Neverness, why are you writing this here?

Start a separate thread in the flume and hand out elephants there, hats off to you.

I told the Moderator that right away.

Let's, Mr. Moderator, discuss trading theory in a separate thread.

The moderator is against it so far.

Perhaps the Moderator does not have his own "trading theory".

 
inter78:

Hello! I too ask about switching between charts. There are 28 or 30 charts open. I switch them thoughtfully with shortcuts and if they fit the condition I open positions. I have 10 or 20. Or 5. It does not matter. The important thing is that the rest get in the way and there is no information on open positions. I tried to send IDs into global variables. But it returns completely different numbers. It was explained to me that ID is big and distorted. I tried it through a file. It returns in TXT and is not converted to long. I put ID manually in the code - it seems to work. When I shift the field, it opens the needed chart. What should I do correctly?

The double and long have the same length - 8 bytes.

To save a long to a double (and vice versa), you can use "union".


For example:

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   long id=ChartID();
   
   double X=LongToDouble(id);
   long   Y=DoubleToLong(X);
   
   Print("id=",id," X=",X," Y=",Y);
  }


//+------------------------------------------------------------------+
union eightbytes
   {
   double   dbl;
   long     lng;
   } VALUE;

double LongToDouble(long value)
   {
   VALUE.lng=value;
   return(VALUE.dbl);
   }

long DoubleToLong (double value)
   {
   VALUE.dbl=value;
   return(VALUE.lng);
   }
 
neverness:

Well, I told the Moderator about it straight away.

Let's, Mr. Moderator, discuss trading theory in a separate thread.

The Moderator is against it so far.

Perhaps the moderator does not have his own "trading theory".

You have to go to the branch of theoretical clowns where they are fond of drawing something you do not understand and do not know why.

There are a lot of similar threads on the forum - at least discuss them!

От теории к практике
От теории к практике
  • 2017.12.01
  • www.mql5.com
Добрый вечер, уважаемые трейдеры! Решил было на какое-то время покинуть форум, и сразу как-то скучно стало:)))) А просто читать, увы - неинтересно...
 
Taras Slobodyanik:

Double and long have the same length - 8 bytes.

To save a long to a double (and vice versa) you can use "union".


For example:

Excuse me, Taras , could you have a piece of code on how to send the ID to a global variable and extract it without distortion?
 
inter78:
Sorry Taras , can't you have a bit of code on how to send the ID to a global variable and extract it without distortion?

so everything is ready, just need to add write/read

string GVname="gvName";

//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//---
   //создаем временную глобальную переменную
   if (!GlobalVariableCheck(GVname))
      GlobalVariableTemp(GVname);
   
   long  id=ChartID();
   
   //сохраняем long как double
   GV_Save(LongToDouble(id));
   
   //читаем double и переводим в long
   long  Y=DoubleToLong(GV_Read());
   
   Print("id=",id," Y=",Y);
  }

//+------------------------------------------------------------------+
union eightbytes
   {
   double   dbl;
   long     lng;
   } VALUE;

double LongToDouble(long value)
   {
   VALUE.lng=value;
   return(VALUE.dbl);
   }

long DoubleToLong (double value)
   {
   VALUE.dbl=value;
   return(VALUE.lng);
   }


//+------------------------------------------------------------------+
double GV_Read()
{
if (!GlobalVariableCheck(GVname))
   GlobalVariableTemp(GVname);
   
return(GlobalVariableGet(GVname));
}
//+------------------------------------------------------------------+
void GV_Save(double value)
{
GlobalVariableSet(GVname, value);
}
 
Taras Slobodyanik:

so it's all set up, just need to add writing/reading

Thank you very much! I wonder if anyone has tried to make such an indicator before? I haven't been able to find one as long as I have. I think it would be of interest to a lot of people.
 
Vitaly Muzichenko:

Do OnInit() initialization

No, it doesn't signal on the current bar. Maybe the _time variable can be reset after the indicator has counted everything for the first time after joining the chart.

How do I know that the indicator has counted everything once?
 
Ghabo:

I throw the indicator on the chart and... ALERT but the signal is 5 bars away. During further work it beeps as it should be.

How to make it stop beeping on start?

if(М_А>0.0)  
{
if(time!=Time[0])
   {
    time=Time[0]; 
    AL(Symbol()+" "+Period()+" УХ ТЫ",2);//
   }
 }

In function AL(), all possible alerts.

What is M_A ? What does it contain and where does it get its data from?

You need to check the validity of the signal on the current bar together with the time check. And you just check the M_A value. Where do you get it from?

 
Artyom Trishkin:

What is M_A ? What does it contain and where does it get its data from?

You need to check the validity of the signal on the current bar together with the time. And you simply check the M_A value. Where do you get it from?

Calling an indicator.

М_А =NormalizeDouble(iCustom(NULL,0,"Morning_All_Best",0,i),Digits);

How do I check validity?

 
Ghabo:

Calling the indicator.

How do I check for validity?

1. Why do you do normalisation? It is too expensive operation to work in indicator cycle and it is not needed here.

2. What does "more than zero" mean? What signals does this custom indicator give out? What is displayed in the buffer values of this indicator in the data window (Ctrl+D) ?