Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
this is my mt5 EA it has a recovery function.it trades one trade per day and i want to make is if it loses the first trade the recovery trade enters at the opposite direction with more lots so far i made it but i need the EA also to not taka a recover trade if the first trade is profitable but i cant make it
help pls
In order to know if the position was profitable, you could compare the positions profit with the account equity and then set a flag to true if the position was profitable (before the position closes)
//global variables bool sufficient_gain = false; double current_equity = 0; void OnTick() { current_equity = AccountInfoDouble(ACCOUNT_EQUITY); for(int i = PositionsTotal() - 1; i >= 0; i--) { ulong posTicket = PositionGetTicket(i); double pos_profit = PositionGetDouble(POSITION_PROFIT); if(pos_profit > (2/100)*current_equity){ // if your position is profitable by more than 2% of account equity (for example) sufficient_gain = true; } } }
then you will make conditions with this new flag
if (!sufficient_gain && !IsRecoveryTradeExecutedToday && !IsRecoveryTradeOpen) { if (LastTradeIsBuy) { Sell(LastTradeLot * RecoveryLotMultiplier, RecoveryStopLoss, RecoveryTakeProfit); } else { Buy(LastTradeLot * RecoveryLotMultiplier, RecoveryStopLoss, RecoveryTakeProfit); } IsRecoveryTradeExecutedToday = true; IsRecoveryTradeOpen = true; } else if(sufficient_gain){ //the position was profitable if(sufficient_gain){ // do something for the case that the position was profitable sufficient_gain = false; //reset the flag again at the end of this condition } }
I haven't tested your code or anything, but I have used this POSITION_PROFIT in my own EA and it worked like this
In order to know if the position was profitable, you could compare the positions profit with the account equity and then set a flag to true if the position was profitable (before the position closes)
then you will make conditions with this new flag
I haven't tested your code or anything, but I have used this POSITION_PROFIT in my own EA and it worked like this
thanks bro I love the mql5 community I will test it out when I come home
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
help pls