Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.
Hover your mouse over your post and select "edit" ...
- www.mql5.com
When you post code please use the Code button (Alt+S) !
Improperly formatted code removed by moderator. Please EDIT your post and use the CODE button (Alt-S) when inserting code.
Hover your mouse over your post and select "edit" ...
Hi I am a very beginning stage of coding i managed to do this via you tube, i need help on open only one trade at any time. after closing the next trade has to open. please help me on this. I am using mql5
You can use PositionsTotal(). As long as this is greater zero don't trade.
BTW here is a list of all function with a short eyplanation so that you can search for keywords.
Bear in mind there's virtually nothing that hasn't already been programmed for MT4/MT5 and is ready for you - so searching gives better results than AI or ChatGPT!
- www.mql5.com
OrdersTotal counts the number of orders and not positions.
if(stoch[1] > StochUpperLevel && stoch[0] > StochUpperLevel && stoch[1] < stoch[0] && PositionsTotal()==0 )
You enter new trade if number of open positions are zero.
-
int bars = iBars(_Symbol,StochTimeframe); if(totalBars !=bars)
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 programming forum.) Always use time.
MT4: New candle - MQL4 programming forum #3 (2014)
MT5: Accessing variables - MQL4 programming forum #3 (2022)I disagree with making a new bar function, because it can only be called once per tick (second call returns false). A variable can be tested multiple times.
Running EA once at the start of each bar - MQL4 programming forum (2011) -
trade.Buy(Lots,_Symbol,ask,ask-SlDist,ask+TpDist);
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)
-
You can use PositionsTotal(). As long as this is greater zero don't trade.
BTW here is a list of all function with a short eyplanation so that you can search for keywords.
Bear in mind there's virtually nothing that hasn't already been programmed for MT4/MT5 and is ready for you - so searching gives better results than AI or ChatGPT!
OrdersTotal counts the number of orders and not positions.
You enter new trade if number of open positions are zero.
- 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 I am a very beginning stage of coding i managed to do this via you tube, i need help on open only one trade at any time. after closing the next trade has to open. please help me on this. I am using mql5