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

 
Igor Makanu :

this will work:

Most likely you have described the structure at global level, and there at global level you wanted to assign values to the fields of the structure, this will not work

Thanks for the reply.

Can you tell me, when I write #define FXT_HEADER.intSize 70, why it gives an error?

 
//+------------------------------------------------------------------+
//|  Функция A/D                       |
//+------------------------------------------------------------------+
double A_D(ENUM_TIMEFRAMES tf, int shift)
  {
   double res=0;
   res=iAD(NULL,tf, shift);
   return res;
  }

//+------------------------------------------------------------------+
//|  Функция A/D  средняя                     |
//+------------------------------------------------------------------+
double A_D_moving(ENUM_TIMEFRAMES tf, int period, int shift)
  {
   double res=0;
   double a[1];
  
   
   for(int i=period-1; i>=0; i--)
     {
   ArrayResize(a,period,0);
      a[i]= A_D(tf, i);    
     }
   for(int j=shift; j>=1; j--)
     {
      res=iMAOnArray(a,0, period,0,MODE_SMA,j);
     }
   return res;
  }

Hello!

Trying to make a moving Average function from iAD(). It didn't work out to the end. The function in the above version outputs the value of moving Average from iAD() on the current bar. It does not depend on the value of the shift variable.

But I need the shift variable to be the index of the bar where the function returns the corresponding value of the moving Average from iAD(). The described error was detected by the following code inserted into OnTick():

   Comment("\n  #0= ", DoubleToString(A_D_moving(0, 20, 0)),
           "\n  ++++++++++++++",
           "\n  #1= ", DoubleToString(A_D_moving(0, 20, 1)),
           "\n  ----------------------",
           "\n  #2= ", DoubleToString(A_D_moving(0, 20, 2)));
   

If anyone can, please advise how to fix the error.

 

Can you help me with a primitive task?
- the indicator has a check for the account number... if the account number is not the one specified - the indicator gives a message (the indicator is just for friends, etc.)
- after the indicator is installed on a chart - everything is working fine ... check goes through... the indicator works

But after restarting the terminal - indicator fails the test ... I understand that the downloading of indicator's code occurs before the connection to the broker? I have to reinstall it on the chart... This is not an option...
Can you tell me in what place to insert this code correctly? I want to be able to put it on the chart once, save it as a template and all ...

 {

   if (AccountInfoInteger(ACCOUNT_LOGIN)  != 123456) {

      Alert("Если не работает: блаблабла");

      return(INIT_FAILED);

   }
 
Roman Agafonkin:

Do you know where to insert this code? So that you can put it once on the chart, save it as a template and that's it...

try putting while() before it, waiting for login within certain limits. don't know what functionAccountInfoInteger(ACCOUNT_LOGIN) gives out if not logged in yet - unprint it and paste it instead of question marks.

while (AccountInfoInteger(ACCOUNT_LOGIN)==????) Sleep (100);
 
Igor Zakharov:

Try while() before that, waiting for login within certain limits. I don't know what functionAccountInfoInteger(ACCOUNT_LOGIN) gives out if not yet logged - print and paste instead of question marks.

You can not execute something long in OnInit - the terminal can unload the code

in the indicator must not slip to work

i don't understand why the source code does not work - either your broker has no good servers or the internet is too slow - usually this code is shared by your "friends" on all forums )))


i think you have to add a static check variable in the indicator body , when a tick comes it will connect to the broker and authorization, the only thing i would give the first tick when loading the chart - but it may be handled , by the way prev_calculated ==0 is a very good reason to check the "license".

 
I started to teach my daughter how to trade. She had this question: "I understand if, say, I buy a pound, but I do not understand how I can sell a pound if I did not buy it and do not have it. To be honest, I could not explain it to her clearly, I said something vague, that it was a non-cash, virtual transaction and it was not necessary to have these pounds in stock to sell. In general, I did not like my own answer. And what would have been the right answer to such a question?
 
khorosh:
I started teaching my daughter to trade. She had this question: I understand if, say, to buy a pound, but it is unclear how you can sell a pound, if I did not buy it and I do not have it. To be honest, I could not explain it to her clearly, I said something vague, that it is considered non-cash, virtual transactions and have these pounds in stock to sell, not necessarily. In general, I did not like my own answer. And what would have been the right answer to such a question?

You don't need to understand things to make a profit. The less you know, theeasier you play. I think so.

It's cool that she is able to start doing it so early) In the process she will find the answers to the questions (which she will ask herself), if there are any...
 
onedollarusd:

You don't need to understand things to make a profit. The less you know, the easier you play. Imho.

If I tell her that when the price has gone down a decent distance and turned around, hit the buy button, and vice versa. Do you think it will be enough? )

 
Igor Makanu:

you cannot execute something long in OnInit - the terminal may unload the code

in the indicator must not work

i don't know why the source code does not work - either your broker has no good servers or the internet is too slow - usually this code is shared by your "friends" on all forums )))


i think i need to add a static check variable in the indicator body , when a tick comes, it will connect to the broker and authorization; the only thing i see is that the first tick is loaded to the chart by itself - but it may be handled , by the way prev_calculated ==0 is a good occasion to check the "license".

I solved the same problem and inserted the following code at the beginning of OnCalculate function:

 if(account_number>0)
 {
   int akk;
   akk=AccountInfoInteger(ACCOUNT_LOGIN);
   if(akk==0)return(0);
   if(akk!=account_number)
   {
     Alert("Неверный номер счёта.");
     int window=ChartWindowFind();
     ChartIndicatorDelete(0,window,MeName);
     return(0);
   }
 }              

account_number is defined with #define (a global visibility variable is also possible), MeName is the same, but in general it is the short name of the indicator.

 
Yurij Kozhevnikov:

I solved the same problem by inserting this code at the beginning of the OnCalculate function:

account_number is defined with #define (you can use global visibility variable), MeName - similarly, but in general it is a short indicator name.

Yes, you have a good example, that's what I'm writing about

but you need to process the first start of the indicator - the first start may or may not be a connection, and if the license has not passed, you should unload the indicator at once, as a counter and 2-3 times no license, then unload the indicator