please help with this code
If it's opening multiple orders then your position of if(OrdersTotal==0) is incorrect so make sure to pack each OrderSend() also to make sure there can always only be one position.
If it's not that, then you have a problem in the closing process where newly opened orders get closed immediately..
if(OrdersTotal() == 0){ // I have no open orders on this chart
No open orders on any chart. Using OrdersTotal directly and/or no Magic number filtering on your OrderSelect loop means your code is incompatible with every EA (including itself on other charts and manual trading.)
Symbol Doesn't equal Ordersymbol when another currency is added to another seperate chart . - MQL4 and MetaTrader 4 - MQL4 programming forum
MagicNumber: "Magic" Identifier of the Order - MQL4 Articlesif(FmaLast<SmaLast && Fmanow>Smanow){
You are checking a condition, will be true each tick. Only look once per bar or Act on a change of signal.
MQL4 (in Strategy Tester) - double testing of entry conditions - Strategy Tester - Expert Advisors and Automated Trading - MQL5 programming forum
thanks for replying
about orderstotal its ok you right and i am not using manual work with experts
i dont even need magic
2- yes also you are right every tick it will check if the cross over happened or not
for that i put another condition its buyorsell
if the last order was buy u dont need to buy again but u can sell only
i also fixed the function of buy orsell but it works only one time
i need code check all existing orders and just get the last ordertype and its volume
here is the function i found but it work only once
bool BuyOrSell(){ datetime TicketDate; datetime StartTime; int TicketNumber; int TicketType; bool z = false; for(int i=0; i<OrdersTotal(); i++){ if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)){ TicketDate = OrderOpenTime(); StartTime = TicketDate; TicketNumber = OrderTicket(); TicketType = OrderType(); //OP_BUY OP_SELL if(TicketType == OP_BUY){ z = true; }else if(TicketType == OP_SELL){ z = false; } } } return (z); }
why are you trying to re-event the wheel?
Top right there is the lens (=search) enter: "EA crossing ma" and you'll find 186 pages each with 10 (=1860) entries about Ea trading if two ma crosses?
And practically all are running!
Choose one and amend it according to your ideas! It's a lot faster!

- Free trading apps
- Free Forex VPS for 24 hours
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
hello
i am trying to make a code works with cross over 2 MA,
the idea is when the fast MA cross the slow one it start a buy order with volume 0.01 and wait till the other cross
in the second cross if the previous order have profit it will close it and start new sell order with volume 0.01
if not it will start new sell order with double volume 0.02
and go on until it get profit or limit loss then close all orders
the problem it make some kind of loop in the second cross and start many orders with double volumes not only one order
please if someone can help me with this
here is full code and thank you in advance