diff --git a/Scripts/MyScripts/Market_Scanner_Pro.mq5 b/Scripts/MyScripts/Market_Scanner_Pro.mq5 index 9b1b2be..e3835d0 100644 --- a/Scripts/MyScripts/Market_Scanner_Pro.mq5 +++ b/Scripts/MyScripts/Market_Scanner_Pro.mq5 @@ -199,19 +199,11 @@ void OnStart() total_symbols = StringSplit(InpSymbolList, u_sep, symbols); } -// 2. Global Sentiment - string sentiment_line = "### GLOBAL_SENTIMENT | "; +// 2. Global Sentiment (Prices) + double bench_change_pct = 0.0; bool has_us500 = SymbolSelect(InpBenchmark, true); bool has_dxy = SymbolSelect(InpForexBench, true); - if(has_us500 && has_dxy) - { - sentiment_line += GetSentimentForTF(InpTFSlow) + " | " + GetSentimentForTF(InpTFMiddle) + " | " + GetSentimentForTF(InpTFFast) + " ###"; - } - else - sentiment_line += "Benchmarks Missing ###"; - - double bench_change_pct = 0.0; if(has_us500) { double b_close[], b_open[]; @@ -220,20 +212,74 @@ void OnStart() bench_change_pct = ((b_close[0] - b_open[0]) / b_open[0]) * 100.0; } -// 3. File Setup string filename = "QuantScan_" + TimeToString(TimeCurrent(), TIME_DATE|TIME_MINUTES) + ".csv"; StringReplace(filename, ":", ""); StringReplace(filename, " ", "_"); int file_handle = FileOpen(filename, FILE_CSV|FILE_WRITE|FILE_ANSI, ";"); if(file_handle == INVALID_HANDLE) - { - Print("Error: CSV File."); return; + +// 3. SCAN & STORE (Phase 1) + PrintFormat("Scanning %d symbols...", total_symbols); + + QuantData results[]; + int success_count = 0; + + for(int i=0; i 0) + vel_pos_count++; + if(StringFind(results[i].mtf_align, "FULL_") != -1) + mtf_full_count++; + } + + double breadth_tsi = (success_count>0) ? ((double)tsi_bull_count/success_count)*100.0 : 0; + double breadth_vel = (success_count>0) ? ((double)vel_pos_count/success_count)*100.0 : 0; + + string sentiment_line = "### GLOBAL_SENTIMENT | "; + if(has_us500 && has_dxy) + { + sentiment_line += GetSentimentForTF(InpTFSlow) + " | " + GetSentimentForTF(InpTFMiddle) + " | " + GetSentimentForTF(InpTFFast); + } + else + sentiment_line += "Benchmarks Missing"; + +// Append Breadth Score to Header Line 1 + sentiment_line += StringFormat(" ### BREADTH_SCORE | TSI_BULL: %d/%d (%.0f%%) | VEL_POS: %d/%d (%.0f%%) | MTF_ALIGN: %d ###", + tsi_bull_count, success_count, breadth_tsi, vel_pos_count, success_count, breadth_vel, mtf_full_count); + +// 5. WRITE TO FILE (Phase 3) FileWrite(file_handle, sentiment_line); +// Header Row string str_slow = EnumToString(InpTFSlow); StringReplace(str_slow, "PERIOD_", ""); string str_mid = EnumToString(InpTFMiddle); @@ -241,82 +287,53 @@ void OnStart() string str_fast = EnumToString(InpTFFast); StringReplace(str_fast, "PERIOD_", ""); - string header = ""; - header += "TIME (" + InpBrokerTimeZone + ");"; - header += "SYMBOL;"; - header += "PRICE;"; + string csv_header = "TIME (" + InpBrokerTimeZone + ");SYMBOL;PRICE;"; + csv_header += StringFormat("TREND_SC_%s;TREND_QUAL_%s;TREND_SLOPE_%s;ZONE_%s;DIST_PDH_%s;DIST_PDL_%s;REL_STR_%s;BETA_%s;ALPHA_%s;",str_slow, str_slow, str_slow, str_slow, str_slow, str_slow, str_slow, str_slow, str_slow); + csv_header += StringFormat("MOM_%s;RVOL_%s;SQZ_%s;VWAP_SLOPE_%s;Z_SCORE_%s;VOL_REGIME_%s;COST_ATR_%s;TSI_DIR_%s;",str_mid, str_mid, str_mid, str_mid, str_mid, str_mid, str_mid, str_mid); + csv_header += StringFormat("MOM_%s;RVOL_%s;TSI_DIR_%s;VEL_%s;", str_fast, str_fast, str_fast, str_fast); + csv_header += "REV_PROB;ABSORPTION;MTF_ALIGN"; -// Layer 1 - header += StringFormat("TREND_SC_%s;TREND_QUAL_%s;TREND_SLOPE_%s;ZONE_%s;DIST_PDH_%s;DIST_PDL_%s;REL_STR_%s;BETA_%s;ALPHA_%s;", - str_slow, str_slow, str_slow, str_slow, str_slow, str_slow, str_slow, str_slow, str_slow); + FileWrite(file_handle, csv_header); -// Layer 2 - header += StringFormat("MOM_%s;RVOL_%s;SQZ_%s;VWAP_SLOPE_%s;Z_SCORE_%s;VOL_REGIME_%s;COST_ATR_%s;TSI_DIR_%s;", - str_mid, str_mid, str_mid, str_mid, str_mid, str_mid, str_mid, str_mid); - -// Layer 3 - header += StringFormat("MOM_%s;RVOL_%s;TSI_DIR_%s;VEL_%s;", str_fast, str_fast, str_fast, str_fast); - -// Composites - header += "REV_PROB;ABSORPTION;MTF_ALIGN"; - - FileWrite(file_handle, header); - - PrintFormat("Scanning %d symbols...", total_symbols); - -// 4. Main Loop - for(int i=0; i