-
When you post code please use the CODE button (Alt-S)!
(For large amounts of code, attach it.) Please edit your post.
General rules and best pratices of the Forum. - General - MQL5 programming forum
Messages Editor - Driss Tamda: I want to open Order in every candle,not every TickSo where is your new bar code?For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart,) volume is unreliable (miss ticks,) Price is unreliable (duplicate prices and The == operand. - MQL4 and MetaTrader 4 - MQL4 programming forum.) Always use time.
I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
New candle - MQL4 and MetaTrader 4 - MQL4 programming forum -
int ticket = OrderSend(Symbol(),OP_BUY,lot,Ask,slippage,Ask-StopLoss*Point,Bid+TakeProfit*Point," open ",1234,0,Green);
Check your return codes for errors, report them and you would know why. Don't just silence the compiler, it is trying to help you.
What are Function return values ? How do I use them ? - MQL4 and MetaTrader 4 - MQL4 programming forum
Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
Only those functions that return a value (e.g. iClose, MarketInfo, etc.) must you call ResetLastError before in order to check after. -
You buy at the Ask and sell at the Bid.
- Your buy order's TP/SL are triggered when the Bid reaches it. Not the Ask.
-
Your sell order's TP/SL will be triggered when the Ask reaches it. To trigger at
a specific Bid price, add the average spread.
MODE_SPREAD (Paul) - MQL4 and MetaTrader 4 - MQL4 programming forum - Page 3 - 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.)
datetime oldTime, newTime;//global variables //-------------- int OnInit(){ oldTime = Time[0];//time of pg launch return(INIT_SUCCEEDED); } //------------ void OnTick(){ newTime = Time[0]; if (newTime != oldTime){ oldTime = newTime; //...your pg } }
Only if there is a new candle your pg is launched
MQL4/5
datetime oldTime = 0, newTime[];//global variables //------------ void OnTick(){ if( CopyTime(_Symbol, PERIOD_CURRENT, 0, 1, newTime) < 1 ) return; if (newTime[0] != oldTime){ oldTime = newTime[0]; //...your pg } }
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I want to open Order in every candle,not every Tick
----------------------------------------------------------------------------------------------------------------------------------------------------------------------