Say it in english, please.
Matthias
-- weltenweiter Wanderer --
Forum on trading, automated trading systems and testing trading strategies
When you post code please use the CODE button (Alt-S)!
Hi, I am trying to include the following logic in my EA and would like help; If the result of the last transaction is TakeProfit - Wait 5 minutes to start the next operation. If the result of the last transaction is StopLoss - Wait 5 minutes to start the next operation. If the result of the last transaction is BreakEven - Wait 5 minutes to start the next operation. I have the settings working for TakeProfit, StopLoss and BreakEven, but all the logic I tried to apply to wait 5 minutes for the next operation did not bring satisfactory results. I tried with "Sleep (300000);" but in this case, the EA only delayed the start of the operation after the signal that happened 5 minutes before, but what I need is for the EA to evaluate if there is a signal to enter just 5 minutes after the negotiations with StopLoss, TakeProfit and BreakEven. Follow the codes for evaluation (as the code is large, I highlighted only the lines of OnTick () with the logic of the operations; In the case below, the EA is evaluating the signal but the operation takes 5 minutes after the signal, and in fact, what I need is for the EA to evaluate the + sign and start the operation after 5 minutes; Another attempt I made was the Boolean logic below, and I added the condition in the code for operations, but in this case the EA stopped sending orders. Have you tried to apply similar logic? The objective is to give the EA time to reconsider the condition and the input signal after a stoploss or takeprofit and not to enter immediately after the stoploss or takeprofit. I appreciate if you can help. See the code;
//-- "includes" relevant; double PRC; double STL; double TKP; bool posAberta; bool ordPendente; bool beAtivo; bool riskControl; bool NovaBarra(); double smaArray[]; int smaHandle; MqlTick ultimoTick; MqlRates rates[]; MqlDateTime horaAtual; //-- Signal and condition to open transaction with "Sleep" in part of "OnInit(); if(ultimoTick.last>smaArray[ 0 ] && rates[ 1 ].close>rates[ 1 ].open && !posAberta && !ordPendente && HoraNegociacao() && NovaBarra()) { Comment("Buy"); PRC = NormalizeDouble(ultimoTick.ask, _Digits); STL = NormalizeDouble(PRC - Stop, _Digits); TKP = NormalizeDouble(PRC + TakeProfit, _Digits); Sleep(300000); if(trade.Buy(Lote, _Symbol, PRC, STL, TKP, "")) { Print("Buy Successfully. RessultRetcode: ", trade.ResultRetcode(), "RetcodeDescription: ", trade.ResultRetcodeDescription()); } else { Print("Transaction Error. RessultRetcode: ", trade.ResultRetcode(), "RetcodeDescription: ", trade.ResultRetcodeDescription()); } } else if(ultimoTick.last<smaArray[ 0 ] && rates[ 1 ].close<rates[ 1 ].open && !posAberta && !ordPendente && HoraNegociacao() && NovaBarra()) { Comment("Venda"); PRC = NormalizeDouble(ultimoTick.bid, _Digits); STL = NormalizeDouble(PRC + Stop, _Digits); TKP = NormalizeDouble(PRC - TakeProfit, _Digits); Sleep(300000); if(trade.Sell(Lote, _Symbol, PRC, STL, TKP, "")) { Print("Sell successfully. RessultRetcode: ", trade.ResultRetcode(), "RetcodeDescription: ", trade.ResultRetcodeDescription()); } else { Print("Transaction error. RessultRetcode: ", trade.ResultRetcode(), "RetcodeDescription: ", trade.ResultRetcodeDescription()); } } } //-- Attempt include bool strategy for wait five minutes; riskControl = false ; for(int i = PositionsTotal()- 1 ; i>= 0 ; i--) { string symbol = PositionGetSymbol(i); ulong magic = PositionGetInteger(POSITION_MAGIC); if(rates[ 0 ].close= ORDER_TYPE_BUY_LIMIT) { riskControl = true ; Sleep(300000); } if(rates[ 0 ].close= ORDER_TYPE_BUY_STOP) { riskControl = true ; Sleep(300000); } if(rates[ 0 ].close= ORDER_TYPE_BUY_STOP_LIMIT) { riskControl = true ; Sleep(300000); } if(rates[ 0 ].close= ORDER_TYPE_SELL_LIMIT) { riskControl = true ; Sleep(300000); } if(rates[ 0 ].close= ORDER_TYPE_SELL_STOP) { riskControl = true ; Sleep(300000); } if(rates[ 0 ].close= ORDER_TYPE_SELL_STOP_LIMIT) { riskControl = true ; Sleep(300000); } } //-- And include the boolean condition to open transaction with "Sleep" in part of "OnInit() if(ultimoTick.last>smaArray[ 0 ] && rates[ 1 ].close>rates[ 1 ].open && !posAberta && !ordPendente && HoraNegociacao() && NovaBarra() && !riskControl) { Comment("Buy"); PRC = NormalizeDouble(ultimoTick.ask, _Digits); STL = NormalizeDouble(PRC - Stop, _Digits); TKP = NormalizeDouble(PRC + TakeProfit, _Digits); Sleep(300000); if(trade.Buy(Lote, _Symbol, PRC, STL, TKP, "")) { Print("Buy Successfully. RessultRetcode: ", trade.ResultRetcode(), "RetcodeDescription: ", trade.ResultRetcodeDescription()); } else { Print("Transaction Error. RessultRetcode: ", trade.ResultRetcode(), "RetcodeDescription: ", trade.ResultRetcodeDescription()); } } else if(ultimoTick.last<smaArray[ 0 ] && rates[ 1 ].close<rates[ 1 ].open && !posAberta && !ordPendente && HoraNegociacao() && NovaBarra() && !riskControl) { Comment("Venda"); PRC = NormalizeDouble(ultimoTick.bid, _Digits); STL = NormalizeDouble(PRC + Stop, _Digits); TKP = NormalizeDouble(PRC - TakeProfit, _Digits); Sleep(300000); if(trade.Sell(Lote, _Symbol, PRC, STL, TKP, "")) { Print("Sell successfully. RessultRetcode: ", trade.ResultRetcode(), "RetcodeDescription: ", trade.ResultRetcodeDescription()); } else { Print("Transaction error. RessultRetcode: ", trade.ResultRetcode(), "RetcodeDescription: ", trade.ResultRetcodeDescription()); } } } //+------------------------------------------------------------------+
![Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Position Properties](https://c.mql5.com/36/44/documentation-on-mql5-constants__52.png)
- www.mql5.com
The algorithm should be as follows: declare a variable of the datetime type in the expert header. When your event fires, write the time into a variable.
In the signal search block, check the condition: if the difference between the current time and the time in the variable is less than five minutes, you should not search for a signal.
Thank you very much, I will test and let you know if it worked
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I tried with "Sleep (300000);" but in this case, the EA only delayed the start of the operation after the signal that happened 5 minutes before, but what I need is for the EA to evaluate if there is a signal to enter just 5 minutes after the negotiations with StopLoss, TakeProfit and BreakEven.
Follow codes for evaluation (as the code is large, I highlighted only the lines of OnTick () with the logic for operations; In the case below, the EA is evaluating the signal but the operation takes 5 minutes after the signal, and in fact what I need is for the EA to evaluate the + signal and start the operation after 5 minutes;
***
Another attempt I made was the logic below, but in this case the EA stopped sending orders; "Boolean" part;
***
And I added the condition in the code for operations below;
***
Have you tried to apply similar logic? The objective is to give the EA time to reconsider the condition and the input signal after a stoploss or takeprofit and not to enter immediately after the stoploss or takeprofit. I appreciate if you can help.