two mql4 questions

 

1. How can I tell if start is being called the first time in an EA? Is there a way you can tell which day you're on (Bars-1 or 0, eg).


2. If I have more that one buy of EUR/USD (eg) how can I calculate the average cost of my position given what I paid for each order and the lot size of that order?


thanks,

William

 

1. How can I tell if start is being called the first time in an EA?

bool FirstTime = True;


int start(){

   if(FirstTime == True){

      Print("This is the first time");

      FirstTime = false;

   }

1-a. Is there a way you can tell which day you're on (Bars-1 or 0, eg).

Typically, you are "on" the bar that you specify in your code.

2. If I have more that one buy of EUR/USD (eg) how can I calculate the average cost of my position given what I paid for each order and the lot size of that order?

You can determine the "breakeven" price, if that is what you mean by "cost".

For each order:

cost1 = lots * price

cost2 = lots * price

costn = lots * price

---

breakeven = (sum of cost1 through costn ) / total lots

--

example: 2 lots at $3, 4 lots @ $4 = (6 + 16) / 6 = $3.667