Hi
I am in the process of learning MQL4 and would like to seek advice on how and where to define the functions properly in my EA as I am struggling to get it to work.
Below is the general sequence of events I am trying to code.
1. On every tick, count the number of open buy/sell orders
2. If the number of buy or sell orders has decreased from when counted on the previous tick, open a new order (if there is no decreased, then no action).
3. Once done, define the open buy and sell order count as LastBuyCount and LastSellCount to be used when the loop is run again on the next tick.
The issue I am facing is I want the Count loop to run on every tick but MQL4 does not allow me to declare the function for my loop in "void OnTick()" so I am also unable use that function for my following IF statement.
Thank you
Please post code that compiles.
You cannot put a function in OnTick(), a function must be outside of any other function.
int CheckOrderCount()
{
}
Always use property strict.
Densuke
Always use
#property strict
in your code.
I'm not sure exactly what your logical reasons for counting the trades are but this just concerns your function to count the trades
//+------------------------------------------------------------------+ void OnTick() { int new_buy_count=0; int new_sell_count=0; //Pass these 2 variables to the function by reference that way the function can calculate the value of multiple variables CheckOrderCount(new_buy_count,new_sell_count); //Now the 2 variables will be updated } //+------------------------------------------------------------------+ void CheckOrderCount(int &new_buy_count,int &new_sell_count) //The & means that the variables are passed by reference. //They don't have to have the same names as in the main code { for (int i=OrdersTotal()-1; i>=0; i--) { if(OrderSelect(i, SELECT_BY_POS) && OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (OrderType() == OP_BUY) new_buy_count++; else if (OrderType() == OP_SELL) new_sell_count++; } } } //+------------------------------------------------------------------+
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi
I am in the process of learning MQL4 and would like to seek advice on how and where to define the functions properly in my EA as I am struggling to get it to work.
Below is the general sequence of events I am trying to code.
1. On every tick, count the number of open buy/sell orders
2. If the number of buy or sell orders has decreased from when counted on the previous tick, open a new order (if there is no decreased, then no action).
3. Once done, define the open buy and sell order count as LastBuyCount and LastSellCount to be used when the loop is run again on the next tick.
The issue I am facing is I want the Count loop to run on every tick but MQL4 does not allow me to declare the function for my loop in "void OnTick()" so I am also unable use that function for my following IF statement.
Thank you