The problem with your logic is that you are looking through the entire order history but you want only the last few trades. You need to read the history, sort into date order, then pick the last few, working backwards in time from the most recently closed. The OrderHistory should be considered as being in a random order.
Some idea not example https://www.mql5.com/en/forum/138894
Another idea : since this actually a money management you should consider to "disable trading when you loss some $$$ or some % of your account, or the remain of your account is $$$", not disable trading when previous 3 or 6 trades were loss consecutively.
dabbler:
The problem with your logic is that you are looking through the entire order history but you want only the last few trades. You need to read the history, sort into date order, then pick the last few, working backwards in time from the most recently closed. The OrderHistory should be considered as being in a random order.
Exactly, random order, and you only want to look at the magic number, current pair.The problem with your logic is that you are looking through the entire order history but you want only the last few trades. You need to read the history, sort into date order, then pick the last few, working backwards in time from the most recently closed. The OrderHistory should be considered as being in a random order.
bool isDisabled; datetime disableOCT; int init(){ isDisabled = false; disableOCT = TimeCurrent(); : } int start(){ if (isDisabled){ comment("disabled"); return(0); } int nLoss = 0, tickets[], nTickets = GetHistoryOrderByCloseTime(tickets); for(int iTicket = 0; iTicket < nTickets; iTicket++) if ( OrderSelect(tickets[iTicket], SELECT_BY_TICKET) ){ if (OrderCloseTime() < disableOCT) break; double profit = OrderProfit() + OrderSwap() + OrderCommission(); if (profit > 0) break; nLoss++; } isDisabled = nLoss >= 3; : }Could EA Really Live By Order_History Alone? - MQL4 forum
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I'm having dificulty writing the logic and OR implementation... Hoping you guru's can help out.
I have a external variable that set the # of consecutive losses for a pair can have before trading is disabled. It can be traded again by a reset flag as external parameter