//+------------------------------------------------------------------+ //| 선택한 기간의 총 수익 및 거래 수 계산하기 || //+------------------------------------------------------------------+ void CalculateProfit() { total_profit = 0; total_deals = 0; HistorySelect(0, TimeCurrent()); int total_orders = HistoryDealsTotal(); for (int i = total_orders - 1; i >= 0; i--) { ulong deal_ticket = HistoryDealGetTicket(i); datetime deal_time = (datetime)HistoryDealGetInteger(deal_ticket, DEAL_TIME); // 왜 이 줄이 다음 줄보다 낮지 않나요? if (HistoryDealGetInteger(deal_ticket, DEAL_ENTRY) != 1) continue; // 클로즈바이 거래와 인커미션은 어떻게 되나요? if (deal_time >= start_date && deal_time <= end_date) // 왜 HistorySelect가 아닌가요? { string deal_symbol = HistoryDealGetString(deal_ticket, DEAL_SYMBOL); int deal_magic = (int)HistoryDealGetInteger(deal_ticket, DEAL_MAGIC); int deal_type = (int)HistoryDealGetInteger(deal_ticket, DEAL_TYPE); // 거래 유형별 필터링(매수 또는 매도) bool type_filter = (deal_type == 0 || deal_type == 1); // 문자 필터링 bool symbol_filter = (StringFind(current_symbols, "ALL") != -1) || (StringFind(current_symbols, deal_symbol) != -1); // 루프에서 매번 첫 번째 조건을 확인하는 것은 비용이 많이 듭니다. // 매직으로 필터링 bool magic_filter_all = (StringFind(current_magics, "ALL") != -1); // 루프에서 매번 확인하는 것은 비용이 많이 듭니다. // 마법사가 포함된 문자열을 배열로 분할합니다. string magic_values[]; int count = StringSplit(current_magics, ',', magic_values); // 이것도 루프에서 제거해야 합니다. // "비어 있음" 및 마법 0 확인 bool magic_filter_empty = false; for (int j = 0; j < count; j++) // Dear Cycle. { if (magic_values[j] == "Empty" && deal_magic == 0) // 두 번째 조건을 먼저 확인하는 것이 더 저렴합니다. { magic_filter_empty = true; break; } } // 특정 마법이 있는지 확인 bool magic_filter_exact = false; for (int j = 0; j < count; j++) { if (IntegerToString(deal_magic) == magic_values[j]) // 문자열 변수를 서로 비교하는 이유는 무엇인가요? { magic_filter_exact = true; break; } }
코드에 대한 몇 가지 의견.
수고하셨습니다. 공유해 주셔서 감사합니다.
내역 수익 계산용 패널:
이 CalculateHistoryProfit 스크립트 버전 1.0은 차트 패널을 사용하여 지정된 기간 동안의 수익을 계산하도록 설계되었습니다.
Author: Sergey Porphiryev