MQL5 How can open just a one position per day

MQL5 How can open just a one position per day

Manage alerts

Loading saved threads...

DIAAALDIN QOSA · External communityPost link
External question — Stack Overflow Stack Exchange Author: DIAAALDIN QOSA Original post: https://stackoverflow.com/questions/78296638 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 mean that if the expert opens a position at any time during the day, it should not open any more positions on that day after that. I'm trying to check that with this method and put it before opening a new position, but it's not working. bool IsOneDayPassedSinceLastDeal(string symbol) { int totalDeals = HistoryDealsTotal(); if (totalDeals == 0) return true; for (int i = totalDeals - 1; i >= 0; i--) { ulong dealTicket = HistoryDealGetTicket(i); string dealSymbol = HistoryDealGetString(dealTicket, DEAL_SYMBOL); if (dealSymbol == symbol) { datetime openTime = HistoryDealGetInteger(dealTicket, DEAL_TIME); datetime currentTime = TimeCurrent(); int timeDifference = currentTime - openTime; int secondsInDay = 24 * 60 * 60; if (timeDifference < secondsInDay) return false; } } // If no deal was found for the symbol within the last day, return true return true; }
Quote
Report
DIAAALDIN QOSA · External communityPost link
External answer — Stack Overflow Stack Exchange Author: DIAAALDIN QOSA Original post: https://stackoverflow.com/a/78297021 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. solution for that Edit the method for this bool IsOneDayPassedSinceLastDeal() { MqlDateTime currentDate; TimeCurrent(currentDate); int currentDay = currentDate.day; int lastDay = _lastPositionTime.day; if (currentDay == lastDay ) { return false; } else { return true; } } Define MqlDateTime _lastPositionTime; as a public variable
Quote
Report

Post Reply

Quoted from Forex.com.bd-Editorial External answer — Stack Overflow Stack Exchange Author: DIAAALDIN QOSA Source score (net votes, not local likes): 0 Original post: https://stackoverflow.com/a/78297021 License: CC BY-SA 4.0 — https://creativecommons.org/licenses/by-sa/4.0/ Adaptation: HTML converted to plain text; contact email addresses removed. solution for that Edit the method for this bool IsOneDayPassedSinceLastDeal() { MqlDateTime currentDate; TimeCurrent(currentDate); int currentDay = currentDate.day; int lastDay = _lastPositionTime.day; if (currentDay == lastDay ) { return false; } else { return true; } } Define MqlDateTime _lastPositionTime; as a public variable

Cancel quote

Checking account access…