Study the CopyRates help and think very hard:
- How many (number) items are you copying?
- WHY do you copy so many elements ???
Documentation on MQL5: Timeseries and Indicators Access / CopyRates
- www.mql5.com
CopyRates - Timeseries and Indicators Access - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
Hi @ Kelly O,
I believe the nesting of your IF statements is not correct.
Also it's not easy to read your code, you've made it more complicated than it needs to be.
Have a look at my solution below, follow the flow carefully and see if you can understand it.
It might be worth your time looking at the MQL5 documentation too.
I believe the nesting of your IF statements is not correct.
Also it's not easy to read your code, you've made it more complicated than it needs to be.
Have a look at my solution below, follow the flow carefully and see if you can understand it.
It might be worth your time looking at the MQL5 documentation too.
void CloseAllSellPositionsThisPair() { for(int i=PositionsTotal()-1; i>=0; i--) { if(m_Position.SelectByIndex(i)) { if(m_Position.PositionType()==POSITION_TYPE_SELL) { m_Trade.PositionClose(m_Position.Ticket()); } } } }CPositionInfo m_Position;CTrade m_Trade;
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 really need your help, please. I'm still in the learning phase on MQL5 programming. I'm actually trying to write a simple program of what I've been learning so far. But there is one thing giving me headache.
This code enters a sell trade at the close of a candle. It exit trade if it goes above the close, and re-enters if it goes below. Now the problem I have with this program is it always enters a sell trade at the close of each candle formed. I know quite well that it has to do with this part of the code.
It enters trade at the close of the previous or second candle which is always set to "1" above.
Now, I've been trying my best to see how I can make it remain at the very first entry trade level even if newer candles are formed below the close. And when price redirect to the trade level and above, it should do its normal operation. It should not enter trades at the close of each candle which is always set to 1 below the the main entry point.
I think this has to do with the index number changing as newer candles are formed. But this is just the problem for me. I don't know how I can loop this and make it work. Attached is the file, and below is the code. Any help is highly appreciated.