Way to get the current streak
Since the ordering of the OrderHistors() is not reliable (as said in the doc) the function
I need to figure out a function which returns the current streak. (5 losses in a row or 3 wins in a row for example)
Where exactly in here do you read that.
But if you want to be paranoid, create a sorted list
int GetHistoryOrderByCloseTime(int tickets[], int asc=1){ // Descending -1 int nTickets = 0; for(int iPos=OrdersHistoryTotal()-1; iPos >= 0; iPos--) if ( OrderSelect(iPos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() <= OP_SELL // Avoid cr/bal forum.mql4.com/32363#325360 ){ int nextTicket = OrderTicket(); datetime nextOCT = OrderCloseTime(); arrayResize(tickets, nTickets+1); for (int iTicket = nTickets; iTicket > 0; iTicket--){ // Insertion sort int prevTicket = tickets[iTicket-1]; OrderSelect(prevTicket, SELECT_BY_TICKET); datetime prevOCT = OrderCloseTime(); if ((prevOCT - nextOCT) * asc <= 0) break; tickets[iTicket] = prevTicket; } nTickets++; tickets[iTicket] = nextTicket; // Insert. } return(nTickets); } : int tickets[], nTickets = GetHistoryOrderByCloseTime(tickets, -1); if (nTickets = 0) int nInARow = 0; else{ nInARow = 0; OrderSelect(tickets[0], SELECT_BY_TICKET); double lastProfit = OrderProfit() + OrderSwap() + OrderCommission(); for (int iPos = 1; iPos < nTickets; iPos++){ OrderSelect(tickets[iPos], SELECT_BY_TICKET); double prevProfit = OrderProfit() + OrderSwap() + OrderCommission(); if (prevProfit * lastProfit < 0) break; // different sign nInARow++; } } if (lastProfit < 0) string last="Losses"; else last="Wins"; Print("I've had ",nInARow," ", last," in a row");Typed, not compiled, not tested.
Hello, seems i can't think right today.
I need to figure out a function which returns the current streak. (5 losses in a row or 3 wins in a row for example)
Since the ordering of the OrderHistors() is not reliable (as said in the doc) the function i have is kind of expensive as it requires a loop trough the whole history for each additional win/loss in a row (3 loops if i had currently 2 win/losses in a row)
Is there a cheaper way of getting the needed results?
Hello, seems i can't think right today.
I need to figure out a function which returns the current streak. (5 losses in a row or 3 wins in a row for example)
Since the ordering of the OrderHistors() is not reliable (as said in the doc) the function i have is kind of expensive as it requires a loop trough the whole history for each additional win/loss in a row (3 loops if i had currently 2 win/losses in a row)
Is there a cheaper way of getting the needed results?