Error 0 from OrderSelect
- OrderSelect returns a bool (true or false) it does not return 0.
- Where did you declare ticket_x? Show all the relevant code.
- You should be able to read your code out loud and have it make sense. You would never write if( (2+2 == 4) == true) would you? if(2+2 == 4) is sufficient. So don't write if(bool == true), just use if(bool) or if(!bool). Code becomes self documenting when you use meaningful variable names, like bool isLongEnabled where as Long_Entry sounds like a trigger price or a ticket number and "if long entry" is an incomplete sentence.
input double buy_price; //pierwsza cena zakupu input double sell_price; //pierwsza cena sprzedaży //--- inicjacje zmiennych globlnych double SL = 2 * krok * _Point; double TP = krok * _Point; int ticket_01 = 0; double SL_01 = buy_price - SL; double TP_01 = buy_price + TP; double OP_01 = buy_price; int ticket_02 = 0; double SL_02 = sell_price + SL; double TP_02 = sell_price - TP; double OP_02 = sell_price; int ticket_0 = 0; //ticket number zlecenia otwartego int OT_0; //Order Type double Vol_0 = Vol; datetime OCT_0; //Order Close Time double OP_0; double SL_0; double TP_0; int ticket_1 = 0; int OT_1; double OP_1; double SL_1 = OP_1 - SL; double TP_1 = OP_1 + TP; double Vol_1 = Vol; int ticket_2 = 0; int OT_2; // Order Type double OP_2; //Open Price - cena otwarcia double SL_2 = OP_2 + SL; double TP_2 = OP_2 - TP; double Vol_2 = Vol;
These are my declarations.
Thank You very much for Your advices, I will try to follow them, and I really appreciate Your help with it.
Your logical approach that if(bool) is enough is very reasonable, but I just sow a lot of instances of using if(bool==true). But You are right, it's stupid.
- Don't double post! You already had this thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forum - Why did you post your MT4 question in the Root / MT5
EA section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. -
double SL = 2 * krok * _Point; double TP = krok * _Point; ⋮ ^v order dependent double SL_01 = buy_price - SL; double TP_01 = buy_price + TP; double OP_01 = buy_price;
Global and static variables work exactly the same way in MT4/MT5/C/C++.- They are initialized once on program load.
- They don't update unless you assign to them.
- In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants.
There is no
default in
MT5 (or MT4 with
strict which
you should always use.)
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
- Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
external static variable - Inflation - MQL4 programming forum
- Always use strict. Fixing the warnings will save you hours of debugging.
- Use the debugger or print out your variables, including _LastError and prices and find out why.
-
ticket_1 = OrderSend(symbol, cmd_1, Vol, OP_1, slippage, SL_1, TP_1, comment, magic, expiration, arrow_color); if(ticket_1>0) { Print("Wysłano pierwsze zlecenie ticket_1"); } else { Print("Nie udało się wysłać pierwszego zlecenia ticket_1. Błąd = ",GetLastError()); }
In your other post you call GetLastError after multiple OrderSends which is useless as the second call invalidates the error of the first.
- Don't double post! You already had this thread open.
General rules and best pratices of the Forum. - General - MQL5 programming forum - Why did you post your MT4 question in the Root / MT5
EA section instead of the MQL4 section, (bottom of the Root page?)
General rules and best pratices of the Forum. - General - MQL5 programming forum
Next time post in the correct place. The moderators will likely move this thread there soon. -
Global
and
static variables work exactly the same way in MT4/MT5/C/C++.
- They are initialized once on program load.
- They don't update unless you assign to them.
- In C/C++ you can only initialize them with constants, and they default to zero. In MTx you should only initialize them with constants.
There is no
default in MT5 (or MT4 with strict which
you should always use.)
MT4/MT5 actually compiles with non-constants, but the order that they are initialized is unspecified and don't try to use any price or server related functions in OnInit (or on load,) as there may be no connection/chart yet:
- Terminal starts.
- Indicators/EAs are loaded. Static and globally declared variables are initialized. (Do not depend on a specific order.)
- OnInit is called.
- For indicators OnCalculate is called with any existing history.
- Human may have to enter password, connection to server begins.
- New history is received, OnCalculate called again.
- New tick is received, OnCalculate/OnTick is called. Now TickValue, TimeCurrent, account information and prices are valid.
- Unlike indicators, EAs are not reloaded on chart change so you must reinitialize them, if necessary.
external static variable - Inflation - MQL4 programming forum
- OP_1 has no value. Always use strict. Fixing the warnings will save you hours of debugging.
- Use the debugger or print out your variables, including _LastError and prices and find out why.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use