time check to open a position does not work as expected in backTest (Strategy tester)

time check to open a position does not work as expected in backTest (Strategy tester)

Manage alerts

Loading saved threads...

mohaddese abbasi · External communityPost link
External question — Stack Overflow Stack Exchange Author: mohaddese abbasi Original post: https://stackoverflow.com/questions/78598831 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. i have an expert advisor that opens positions each day at 1:10am only. it works perfectly on chart on forward test but when i try to back test it using strategy tester, i see that it opens positions on 1:10 but also on some other random times as well! does any one know what could be the problem? here is the code that checks the time: datetime tradeTime=D'01:10:00'; datetime currentTime = TimeCurrent(); void OnTick(){ if (TimeHour(currentTime) == TimeHour(tradeTime)) { if(TimeMinute(currentTime) == TimeMinute(tradeTime)){ //strategy } } }
Quote
Report
Mark SdS · External communityPost link
External answer — Stack Overflow Stack Exchange Author: Mark SdS Original post: https://stackoverflow.com/a/78603283 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. In strategy tester it's best to refer to time of a bar instead of TimeCurrent() . I don't recall precisely how that's been done in MQL4; in MQL5 it is iTime(Symbol(),PERIOD_CURRENT,shift) where shift is the referring integer to the relevant bar.
Quote
Report
4xPip Official · External communityPost link
External answer — Stack Overflow Stack Exchange Author: 4xPip Official Original post: https://stackoverflow.com/a/79068099 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. Your code is correct, all the pending trades (Buy Limit & Sell Limit) are being opened at 01:10 AM everyday. The Market Buy and Market Sell trades are opening on other times, they are converted trades from Pending Trades. A Pending trade can be converted into market trade whenever price hits that price level. Kindly execute the same script and execute a Market Buy order , and you will see its only opening at 01:10 AM
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External question — Stack Overflow Stack Exchange Author: mohaddese abbasi Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/questions/78598831 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. i have an expert advisor that opens positions each day at 1:10am only. it works perfectly on chart on forward test but when i try to back test it using strategy tester, i see that it opens positions on 1:10 but also on some other random times as well! does any one know what could be the problem? here is the code that checks the time: datetime tradeTime=D'01:10:00'; datetime currentTime = TimeCurrent(); void OnTick(){ if (TimeHour(currentTime) == TimeHour(tradeTime)) { if(TimeMinute(currentTime) == TimeMinute(tradeTime)){ //strategy } } }

Cancel quote

Checking account access…