Reply

CustomFunctions.mq4 ???

4 replies

Mike H.

Subscriber, bbp_participant, community, 76 replies.

Visit profile

10 years ago #111633

In the EA Wizard – Trading Rules – Condition Dialog – Functions (17) – Custom Function – Description (below), it explains: Call your own function. You can specify any MQL command here, or call a custom MQL function defined in /code/CustomFunctions.mq4 file. You are responsible for comparing the function with correct types. I have what I think is a function:
double profit() {
   OrderSelect (NULL,0);
   double profit = OrderProfit() + OrderSwap() + OrderCommission()
   return (profit);
}

I am a novice, which is why I purchased the EA Wizard. I know a little about writing code. I know how to write simple custom indicators. I do not even know if the format above is a function which can be used with EA Wizard.

How do I plug the above function into /code/CustomFunctions.mq4?
Do I simply replace the code in /code/CustomFunctions.mq4 with the code above, then rename the .mq4 file, keep it in the /code folder, and the EA Wizard will find it there? I think in the Properties section of the Add Condition Dialog, after Function, I type in the name of the function file. After Function, do I simply name the file and the EA Wizard will find it in the /code folder? Do I simply type in OrderProfit()+OrderSwap()? How do we use Custom Function?

 

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

10 years ago #122750

Hello,

 

you can open the file {EA Wizard}/code/CustomFunctions.mq4 and add your function to the end of this file.

After this, your function will be inserted into code of every EA generated by the program, so you can use it.

 

 

But the function as you described is probably incorrect, I’m not sure you can call OrderSelect like that.

And there’s a missing ; at the end of profit computation.

 

The correct function would be something like:

 

double profit() {
  double profit = 0;
 
  for (int cc = OrdersTotal() – 1; cc >= 0; cc–) {
    if (!OrderSelect(cc, SELECT_BY_POS) ) continue;
 
    profit = OrderProfit() + OrderSwap() + OrderCommission();
    break;
  }
 
  return(profit);
}

 

 

 

 

Then you can use this function in Custom Function calls. You just call the function by its name, you don’t use file name.

 

You can call it in conditions using Custom Function, where Function would be: profit()

or in the actions to store the profit to some variable, like Custom Action Command: ProfitVariable = profit();

 

But EA Wizard already contains functions that return open or closed profit of a trade, they return net profit value (without swaps or commissions).

These functions are in Strategy Control list box.

 

Mark

Mark
StrategyQuant architect

0

Mike H.

Subscriber, bbp_participant, community, 76 replies.

Visit profile

10 years ago #122761

Thank You Mark,

       I’ll use it next week. I want to see if my Custom Indicator where I put the function will work on Friday. Later…

0

Mike H.

Subscriber, bbp_participant, community, 76 replies.

Visit profile

10 years ago #122771

My Custom Indicator where the OpenProfit function was used within has worked very well. It even calculated the Swap as well.

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

10 years ago #122795

I’m glad it worked 🙂

Mark
StrategyQuant architect

0

Viewing 4 replies - 1 through 4 (of 4 total)