You are selecting orders BY_POS using a variable not based on OrdersTotal(), this is totally wrong, you will miss a lot of trades in your cycle.
If you don't want to use OrdersTotal()<1 for checking if your EA can do trades, make your own OrdersCount() function, that only counts order of Symbol() and with your magic number: in this way any instance of the EA can handle its own orders.
int OrdersCount() { int counter = 0; for( int i=OrdersTotal()-1; i>=0; i-- ) { if( !OrderSelect(i,SELECT_BY_POS) || OrderSymbol()!=Symbol() || OrderMagicNumber()!=MagicNumber ) continue; counter++; } return(counter); }
void OnTick() { CountOrder(); OpenOrders(); CloseProfit(); }
here on Every tick it will Count Orders,
I dont know why but
int CountOrder() { int b=1; for(int Loop3=0;Loop3<b;Loop3++) { if(OrderSymbol()==Symbol()==OrderMagicNumber()==MagicNumber) Count++; } return(Count); }
This will give wrong number cause you must first select an order before you use Ordersymbol
delete the CountOrder
and use default function
OrdersTotal()
after that it will open a buy and a sell Nothing will stop it.
if(OrdersTotal()<maxNumber) OpenOrders()
still thats poor way of limiting orders cause you will have 2 Orders a buy and a sell if maxNumber >1
if(OrderSelect(a,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()==OrderMagicNumber()==MagicNumber) bool CloseOrder=false; int Type=OrderType(); {
this will not compile
Here was showing you places to polish up, and analyse and giving ideas
NB I
wasnt solving you problem
Has helped you on the OrdersCount.
Here is Fabio's code in another way
int OrdersCount() { int counter = 0; for( int i=OrdersTotal()-1; i>=0; i-- ) { if( OrderSelect(i,SELECT_BY_POS) && OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber ) counter++; } return(counter); }
Sorry, but I will not be helping you with this.
Did you learn nothing from your other topic?
- 2019.12.18
- www.mql5.com
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 programming forum
MagicNumber: "Magic" Identifier of the Order - MQL4 Articles
Sorry, but I will not be helping you with this.
Did you learn nothing from your other topic?
Mr. J. Buda wrote that post as well,
Mr buda it has been 3 weeks what are you using to study your mql
You are selecting orders BY_POS using a variable not based on OrdersTotal(), this is totally wrong, you will miss a lot of trades in your cycle.
If you don't want to use OrdersTotal()<1 for checking if your EA can do trades, make your own OrdersCount() function, that only counts order of Symbol() and with your magic number: in this way any instance of the EA can handle its own orders.
Mr. J. Buda wrote that post as well,
Mr buda it has been 3 weeks what are you using to study your mql
I'm using Jimdany1958, MQL4Tutorial & Bilal Header on YouTube.
For a book its Andrew R. Young-Expert Advisor Programming_ Creating Automated Trading Systems in MQL for MetaTrader 4.
I use MQL4 for error's that i have encountered or something new i want to learn
I'm using Jimdany1958, MQL4Tutorial & Bilal Header on YouTube.
For a book its Andrew R. Young-Expert Advisor Programming_ Creating Automated Trading Systems in MQL for MetaTrader 4.
I use MQL4 for error's that i have encountered or something new i want to learn
imagine you are eating, and you order a lot of food from different places of earth, you have italian dishes, chinese, mexian, Russian, Indian,
canaadian, SouthAfrican, Brazilian and many more all these are at ur table.
Now cause your stomach is small you cant eat all of
it,
if you taste u wont get filled
you have to select 1 and eat it, when done then later on u can try another meal.
Just
like when studing MQL. take 1 course do it to the end, then do another.
I watched Jimdandy videos from lesson 1 to lesson 26 and
jumped to other lessons cause I understood, however Jim dandy doesnt do basics and the simplest thing will confuse you, then I read MQL
documentation Oh my that was horrid went to Andrew young he talks about the basics before he goes into simple EA. also in his MT5 book he follows
same pattern and topics so that will be pretty good.
How ever Jim explains some principles in a very nice clear way.
watch
with your MetaEditor open following,
read with your MetaEditor open following.
imagine you are eating, and you order a lot of food from different places of earth, you have italian dishes, chinese, mexian, Russian, Indian,
canaadian, SouthAfrican, Brazilian and many more all these are at ur table.
Now cause your stomach is small you cant eat all
of it,
if you taste u wont get filled
you have to select 1 and eat it, when done then later on u can try another
meal.
Just like when studing MQL. take 1 course do it to the end, then do another.
I watched
Jimdandy videos from lesson 1 to lesson 26 and jumped to other lessons cause I understood, however Jim dandy doesnt do basics and the
simplest thing will confuse you, then I read MQL documentation Oh my that was horrid went to Andrew young he talks about the basics before
he goes into simple EA. also in his MT5 book he follows same pattern and topics so that will be pretty good.
How ever Jim
explains some principles in a very nice clear way.
watch with your MetaEditor open following,
read with
your MetaEditor open following.
Thanks for advice /tip i appreciate it a lot.
As i said in my previous post, that i started last January to program. Some functions were easy & simple, some were complex & difficult to understand. I know as i made this post i was at fault & i learn from it.
Thank You
- 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 there all
If you can please help, i would like to open 1 buy & 1 sell. For some reason my EA opens many trades, I know there's a way to open 1 buy & 1 sell. By using "if (OrdersTotal()<1)" i don't want to use that because i want to use the same code on a different pair. If there's way please assist & I know I'm doing something wrong tried change it no luck. :(
Thank You