Hi,
i need to insert a time condition on which the EA trade only between 2pm and 5pm (variables that I will change on backtesting).
I've read several thread but cannot find a way to understand to how to manage "time variables" properly.
Any idea on implement it very easily? (an IF Timecurrent > 2pm and <5pm then trade)
Thanks
This is a recurring topic - have a look at this thread please
- 2023.12.06
- www.mql5.com
- 2023.12.12
- www.mql5.com
Hi, I need some help to understand Time management in my EA
this is part of my EA. I would need to open a trade short or long following a specific condition (X<lastprice or X>lastprice) during specific timehours (3pm to 8pm in this case) opening 1 unique trade per hour.
It almost work, what is not working is the following:
If I insert as starting hour 8am or 9am, it open positions, if (as in the case below) I will put 3pm as starting hour it doesn't open any position, during the whole year, for the backtesting. Cannot really understand why...
The position it opens, I would like to be within the first minute of the hour (ex: at 4.00.01 pm max 4.01.00 pm), if not, to skip the position. but I really don't know how to put this condition (anyway, I'm stucked in the problem above).
Thanks for your help. I'm stuying by myself MQL5 since a week and I've coded helping me with this forum and AI.
#include<Trade\Trade.mqh> CTrade trade; // Dichiarazione delle variabili globali double lotSize = 0.01; int pendingOrderExpiration = 3600; // Tempo di scadenza dell'ordine pending in secondi (1 ora) datetime lastOrderTime = 0; // Ora dell'ultima esecuzione dell'ordine int tradeIntervalSeconds = 3600; ulong secsStartTime = 15 * 3600; // dalle 9 ulong secsEndTime = 20 * 3600; // alle 16 // Funzione eseguita all'arrivo di ogni tick void OnTick() { // Ottieni il valore dell'ultima candela oraria double lastHourlyHigh = iHigh(Symbol(), PERIOD_H1, 0); double lastHourlyLow = iLow(Symbol(), PERIOD_H1, 0); ulong secsSinceMidnight = TimeCurrent()%(24*3600); MqlTick Latest_Price; // Structure to get the latest prices SymbolInfoTick(_Symbol, Latest_Price); // Assign current prices to structure // Ottieni l'ora corrente datetime currentTime = TimeCurrent(); //controlla orario funzionamento bot if (secsSinceMidnight > secsStartTime && secsSinceMidnight < secsEndTime){ // Controlla se è trascorso almeno un'ora dall'ultima esecuzione dell'ordine if ((currentTime - lastOrderTime) >= tradeIntervalSeconds) { // Verifica le condizioni per aprire una posizione if (X > Latest_Price.bid) { // Apri una posizione long trade.BuyLimit ( lotSize, //lotsize entryPriceLong, //Entry _Symbol, //Symbol stopLossLong, //SL targetPriceLong, //TP ORDER_TIME_GTC, //Expiration date pendingOrderExpiration, //Expiration time "comment" //Comment ); lastOrderTime = currentTime; } else if (X < Latest_Price.bid) { // Apri una posizione short trade.SellLimit ( lotSize, //lotsize entryPriceShort, //Entry _Symbol, //Symbol stopLossShort, //SL targetPriceShort, //TP ORDER_TIME_GTC, //Expiration date pendingOrderExpiration, //Expiration time "comment" //Comment ); lastOrderTime = currentTime; } } } }
- 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 need to insert a time condition on which the EA trade only between 2pm and 5pm (variables that I will change on backtesting).
I've read several thread but cannot find a way to understand to how to manage "time variables" properly.
Any idea on implement it very easily? (an IF Timecurrent > 2pm and <5pm then trade)
Thanks