You should look at the journal to see why it's not working (see what it's saying). When a position is open, you can't make a new position with the same lot size if you don't have enough free margin left. So that is already a potential problem. You'll need an automatic lot size calculation function. Someone wrote before about how to make this new trade on breakeven work but for MT4
https://www.mql5.com/en/code/35609
I didn't look at it, it might give you ideas even though you're working with MQL5

- www.mql5.com
You should look at the journal to see why it's not working (see what it's saying). When a position is open, you can't make a new position with the same lot size if you don't have enough free margin left. So that is already a potential problem. You'll need an automatic lot size calculation function. Someone wrote before about how to make this new trade on breakeven work but for MT4
https://www.mql5.com/en/code/35609
I didn't look at it, it might give you ideas even though you're working with MQL5
well , the issue is at it opens too many trades , not that it won't open any. i will check the link provided, thanks
I think iTime will help you limit trades. Just know that the time variables below (on the global scope) will reset to 0 upon EA restart. The preferred way to limit trades is to call data from the appropriate trade pools, but this requires object-oriented programming which you're not using.
datetime dprevtime1; ulong prevtime1 = ulong(dprevtime); datetime dtime1 = iTime(_Symbol, PERIOD_CURRENT, 1); ulong time1 = ulong(dtime1); //... if(your_trading_conditions && time1 > prevtime1) { your_order_send; dprevtime1 = dtime1; }
As a "hack" of sorts, you could alternatively create special terminal-wide GlobalVariables (GV's) that would persist through EA restart.

- www.mql5.com
I posted similar code in the OP's other thread regarding same, but the OP is looking to perpetually stack/pyramid trades.
but when you do the condition with bar open time, you're not allowing the new trade to execute within the time of the same bar. This might not be efficient on higher timeframes, but could work on lower timeframes
PositionsTotal is a great function which I use a lot. It only concerns itself with opened positions. He can perpetually stack trades based on a limit, it constantly recomputes how many positions are open every tick.but when you do the condition with bar open time, you're not allowing the new trade to execute within the time of the same bar. This might not be efficient on higher timeframes, but could work on lower timeframes
PositionsTotal is a great function which I use a lot. It only concerns itself with opened positions. He can perpetually stack trades based on a limit, it constantly recomputes how many positions are open every tick.If you want the current bar open time, then use:
datetime dtime1 = iTime(_Symbol, PERIOD_CURRENT, 0);
The open price does not change intrabar regarless of timeframe.
My understanding is that the OP does not want rapid-fire trades sent upon the arrival of every tick within the same bar.
If you want the current bar open time, then use:
The open price does not change intrabar regarless of timeframe.
My understanding is that the OP does not want rapid-fire trades sent upon the arrival of every tick within the same bar.
well he has this "beTrigger" variable, my feeling was that he wants a new trade as soon as possible once breakeven is triggered because of how volatile the markets can be and how easily opportunities are lost. Your solution is fine for the use case though, I already do what you are doing in my own EA
well he has this "beTrigger" variable, my feeling was that he wants a new trade as soon as possible once breakeven is triggered because of how volatile the markets can be and how easily opportunities are lost. Your solution is fine for the use case though, I already do what you are doing in my own EA
I actually do what you're doing because I don't stack trades.😂

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
As you can see in my code i tried to use isPosOpen to make my ea stop opening more than 1 trade when the conditions are met, but i failed when i tried it to use it to stop my bot to open more than 1 trade when the prev trade is set to be. My plan is to keep opening trade when conditions are met if the previous trade is at be. Is there a way i can make ma ea to forget the trade as soon as it's set to be? I will post my full code here , as a description is a simple bullish engulfing EA. Thanks!