-
int OnInit() { Ask = SymbolInfoDouble(_Symbol, SYMBOL_ASK); meutrade.Buy(0.01, _Symbol, Ask, Ask - (200 * _Point), 0);
Do you really want to open an order every time you change symbol or timeframe, compile, restart the terminal, etc.?
-
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
-
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25 -
The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
My GBPJPY shows average spread = 26 points, average maximum spread = 134.
My EURCHF shows average spread = 18 points, average maximum spread = 106.
(your broker will be similar).
Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)
-
- Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), 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.
- A 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 - MQL4 programming forum #2 (2013) -
if(PositionGetDouble(POSITION_PRICE_CURRENT) > PositionGetDouble(POSITION_PRICE_OPEN) + (InputDistancia * _Point)) // Calcula se excedeu a distância para mover o SL { meutrade.PositionModify(PositionGetTicket(i), PositionGetDouble(POSITION_PRICE_OPEN, 0);
You are repeatedly modifying the position every tick. ERR_NO_RESULT
You Server Change the SL to X It is at X! Change the SL to X It is at X! Change the SL to X You are insane Insanity: doing the same thing over and over again and expecting different results.
UnknownCompute the new value, then check that you are moving the existing value at least a tick (in the currect direction).
What is a TICK? - MQL4 programming forum (2014) - alefyinacio: }' - unexpected end of program and '{' - unbalanced parentheses
void OnTick() { for(int i = PositionsTotal(); i>= 0; i--) // Cataloga todas as operações da conta { if(PositionGetSymbol(i) == _Symbol) // Filtra pelo ativo atual { //==== COMPRA ==== if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY) // Filtra somente operações de compra {…} //==== VENDA ==== if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL) // Filtra somente operações de VENDA {…} // Filtra somente operações de VENDA } // Filtra pelo ativo atual } // Cataloga todas as operações da conta //+------------------------------------------------------------------+ <<<<<<< Where is the end of OnTick?
-
Do you really want to open an order every time you change symbol or timeframe, compile, restart the terminal, etc.?
-
You buy at the Ask and sell at the Bid. Pending Buy Stop orders become market orders when hit by the Ask.
-
Your buy order's TP/SL (or Sell Stop's/Sell Limit's entry) are triggered when the Bid / OrderClosePrice reaches it. Using Ask±n, makes your SL shorter and your TP longer, by the spread. Don't you want the specified amount used in either direction?
-
Your sell order's TP/SL (or Buy Stop's/Buy Limit's entry) will be triggered when the Ask / OrderClosePrice reaches it. To trigger close at a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 programming forum - Page 3 #25 -
The charts show Bid prices only. Turn on the Ask line to see how big the spread is (Tools → Options (control+O) → charts → Show ask line.)
Most brokers with variable spreads widen considerably at end of day (5 PM ET) ± 30 minutes.
My GBPJPY shows average spread = 26 points, average maximum spread = 134.
My EURCHF shows average spread = 18 points, average maximum spread = 106.
(your broker will be similar).
Is it reasonable to have such a huge spreads (20 PIP spreads) in EURCHF? - General - MQL5 programming forum (2022)
-
- Don't try to use any price (or indicator) or server related functions in OnInit (or on load or in OnTimer before you've received a tick), 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.
- A 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 - MQL4 programming forum #2 (2013) -
You are repeatedly modifying the position every tick. ERR_NO_RESULT
You Server Change the SL to X It is at X! Change the SL to X It is at X! Change the SL to X You are insane Compute the new value, then check that you are moving the existing value at least a tick (in the currect direction).
What is a TICK? - MQL4 programming forum (2014)
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
}' - unexpected end of program and '{' - unbalanced parentheses
Auto-translation applied by moderator.