About description in function of mql5

 

Note:I'm using the translation tool. There may be wrong expressions.

please excuse any inaccuracies or unnatural expressions.



In the case of mql4,

 double testMA(){

double ma = ima();
return ma;
} 

I write like.

In mql5, you  use "handle".
int maHandle = ima() 

I heard that I don't need to create a handle every time.

Call once in INIT.

In that case, should I put the handle as an argument to the function?

for example:

 double testMA(int handle){
  
  double buf[]; 
  copybuffer(...,buf);
  double ma = buf[0];
  return ma; 

} 


Is it good code to use a copy buffer every time?

or,

is it good code to pass the buf as an argument?

for example:
double testMA(double &buf[]){
  
  double ma = buf[0];
  return ma; 

} 


which one is better?

***


I want to call ma or other functions and do calculations in my new function.
Please tell me about good code.
 

    If you place the cursor on an MQL function and press F1, you will see the reference directly, many with examples to copy and paste - the fastest form to code.
    https://www.mql5.com/en/articles/496
    https://www.mql5.com/en/articles/100
    and for debugging: https://www.metatrader5.com/en/metaeditor/help/development/debug
    https://www.mql5.com/en/search#!keyword=cookbook
    "Bear in mind there's virtually nothing that hasn't already been programmed for MT4/MT5 and is ready for you - so searching gives better results than AI or ChatGPT!" (Carl Schreiber):
    => Search in the articles: https://www.mql5.com/en/articles
    => Search in the codebase: https://www.mql5.com/en/code
    => Search in general: https://www.mql5.com/en/search or via Google with: "site:mql5.com .." (forgives misspelling)

migrate MQL4 to MQL5: https://www.mql5.com/en/articles/81
Transferring Indicators from MQL4 to MQL5: https://www.mql5.com/en/articles/66

Quick Start: Short Guide for Beginners
Quick Start: Short Guide for Beginners
  • www.mql5.com
Hello dear reader! In this article, I will try to explain and show you how you can easily and quickly get the hang of the principles of creating Expert Advisors, working with indicators, etc. It is beginner-oriented and will not feature any difficult or abstruse examples.
 
valenciaorange:

Note:I'm using the translation tool. There may be wrong expressions.

please excuse any inaccuracies or unnatural expressions.



In the case of mql4,


I write like.

In mql5, you  use "handle".

I heard that I don't need to create a handle every time.

Call once in INIT.

In that case, should I put the handle as an argument to the function?

for example:



Is it good code to use a copy buffer every time?

or,

is it good code to pass the buf as an argument?

for example:


which one is better?

***


I want to call ma or other functions and do calculations in my new function.
Please tell me about good code.
Cannot be answered this simple.

Depends on what you are trying to achieve.

Ether is valid, and can be a good approach. You would need to lay out more of your execution path.

As long as your functions only use up to three parameters, (__cdecl) you will be using registers to pass the values, no need to worry.

Return value is anyways only max 8 bytes in one register, no need to worry either.

Memory allocation takes longer, if you can preallocate one memory space and keep it around, without changing the size, you can save that time.

It all depends very much on your execution path.
 
カール・シュライバー #:

    MQL 関数にカーソルを置いて F1 キーを押すと、参照が直接表示されます。その多くには、コピーして貼り付けるための例が含まれており、コードを作成するのが最も早い形式です。
    https://www.mql5.com/en/articles/496
    https://www.mql5.com/en/articles/100
    、デバッグ用: https://www.metatrader5.com/en/metaeditor/help/開発/デバッグ
    https://www.mql5.com/en/search#!keyword=cookbook
    「MT4/MT5 用にまだプログラムされておらず、すぐに使用できるものは実質的に何もないことに留意してください - したがって、検索するとより良い結果が得られますAIやChatGPTよりも!」 (Carl Schreiber):
    => 記事内の検索: https://www.mql5.com/en/articles
    => コー​​ドベース内の検索: https://www.mql5.com/en/code
    => 一般的な検索: https://www.mql5.com/en/search または Google 経由: 「site:mql5.com ..」 (スペルミスは許してください)

MQL4 から MQL5 への移行: https://www.mql5.com/en/articles/81
MQL4 から MQL5 へのインジケーターの移行: https://www.mql5.com/en/articles/66

Thank you!

I look at the materials and study.

 
ドミニク・クリスチャン・エガート# :
I can't answer this easily.

It depends on what you are trying to achieve.

Ether is valid and could be a good approach. You need to lay out your execution path further.

As long as your function only uses up to 3 issues (__cdecl), you'll be passing values using registers, but don't worry about it.

By all means the return value is only a maximum of 8 bytes in one register, so don't worry about it.

Allocating memory takes time, but you can save that time if you can preallocate a single memory region and keep it unchanged.

Everything depends heavily on the execution path.

thank you.

I have a better understanding.


I'm thinking of using handles as function arguments.


I came to the conclusion that there is a possibility of causing an accident if I, an amateur, worry about memory and do fancy coding.


I thought it might be better to use the whole buf, but at my current level of understanding, complex code looks like

Doing so may cause an accident.


Either way, I was relieved because I didn't have to worry about memory.


Thank you very much.