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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
+
import io
|
| 6 |
+
|
| 7 |
+
def trading_dashboard(digit, bias, digit_bias_list, bias_file, digit_sequence):
|
| 8 |
+
# Bias interpretation + gauge zone
|
| 9 |
+
if bias < 30:
|
| 10 |
+
bias_msg = f"Bias {bias}% β Weak (Red Zone)"
|
| 11 |
+
gauge_color = "red"
|
| 12 |
+
elif 30 <= bias < 60:
|
| 13 |
+
bias_msg = f"Bias {bias}% β Moderate (Yellow Zone)"
|
| 14 |
+
gauge_color = "yellow"
|
| 15 |
+
else:
|
| 16 |
+
bias_msg = f"Bias {bias}% β Strong (Green Zone)"
|
| 17 |
+
gauge_color = "green"
|
| 18 |
+
|
| 19 |
+
# --- Bias Gauge Plot ---
|
| 20 |
+
fig_gauge, axg = plt.subplots(figsize=(4,1))
|
| 21 |
+
axg.barh(["Bias"], [bias], color=gauge_color)
|
| 22 |
+
axg.set_xlim(0,100)
|
| 23 |
+
axg.set_title("Bias Strength Gauge")
|
| 24 |
+
axg.set_xlabel("%")
|
| 25 |
+
for spine in axg.spines.values():
|
| 26 |
+
spine.set_visible(False)
|
| 27 |
+
|
| 28 |
+
# --- Digit Bias Analyzer (0β9 bar chart) ---
|
| 29 |
+
if bias_file is not None:
|
| 30 |
+
try:
|
| 31 |
+
df = pd.read_csv(bias_file) if bias_file.name.endswith(".csv") else pd.read_excel(bias_file)
|
| 32 |
+
digit_bias_values = df.iloc[0].values.tolist()[:10]
|
| 33 |
+
except Exception:
|
| 34 |
+
digit_bias_values = np.random.randint(0,100,10)
|
| 35 |
+
elif digit_bias_list is not None and len(digit_bias_list) == 10:
|
| 36 |
+
digit_bias_values = digit_bias_list
|
| 37 |
+
else:
|
| 38 |
+
digit_bias_values = np.random.randint(0,100,10)
|
| 39 |
+
|
| 40 |
+
fig_digits, axd = plt.subplots()
|
| 41 |
+
axd.bar(range(10), digit_bias_values, color="skyblue")
|
| 42 |
+
axd.set_xticks(range(10))
|
| 43 |
+
axd.set_xticklabels([str(i) for i in range(10)])
|
| 44 |
+
axd.set_title("Digit Bias Analyzer (0β9)")
|
| 45 |
+
axd.set_ylabel("Bias %")
|
| 46 |
+
|
| 47 |
+
# --- Digit Psychology Module ---
|
| 48 |
+
streaks = []
|
| 49 |
+
bias_summary = {}
|
| 50 |
+
if digit_sequence:
|
| 51 |
+
digits = [int(d) for d in str(digit_sequence) if d.isdigit()]
|
| 52 |
+
if digits:
|
| 53 |
+
# Streak awareness
|
| 54 |
+
current_streak = 1
|
| 55 |
+
for i in range(1, len(digits)):
|
| 56 |
+
if digits[i] == digits[i-1]:
|
| 57 |
+
current_streak += 1
|
| 58 |
+
else:
|
| 59 |
+
streaks.append((digits[i-1], current_streak))
|
| 60 |
+
current_streak = 1
|
| 61 |
+
streaks.append((digits[-1], current_streak))
|
| 62 |
+
|
| 63 |
+
# Bias summary (frequency %)
|
| 64 |
+
freq = pd.Series(digits).value_counts(normalize=True) * 100
|
| 65 |
+
bias_summary = freq.to_dict()
|
| 66 |
+
|
| 67 |
+
psychology_text = "π Digit Psychology Analysis\n\n"
|
| 68 |
+
if streaks:
|
| 69 |
+
psychology_text += "Streaks:\n" + "\n".join([f"Digit {d} β {s} times" for d,s in streaks]) + "\n\n"
|
| 70 |
+
if bias_summary:
|
| 71 |
+
psychology_text += "Bias Summary (%):\n" + "\n".join([f"Digit {d}: {round(p,1)}%" for d,p in bias_summary.items()]) + "\n\n"
|
| 72 |
+
psychology_text += "Checklist:\n- Bias > 30%\n- Streak awareness checked\n- Indicators aligned (MACD/RSI)\n- Candle confirmation done"
|
| 73 |
+
|
| 74 |
+
# Example market data
|
| 75 |
+
data = pd.DataFrame(np.random.randn(50, 3), columns=['Price', 'Volume', 'Signal'])
|
| 76 |
+
data['MACD'] = data['Price'].ewm(span=12).mean() - data['Price'].ewm(span=26).mean()
|
| 77 |
+
data['RSI'] = 100 - (100 / (1 + (data['Price'].diff().clip(lower=0).rolling(14).mean() /
|
| 78 |
+
data['Price'].diff().clip(upper=0).abs().rolling(14).mean())))
|
| 79 |
+
|
| 80 |
+
# Plot MACD
|
| 81 |
+
fig1, ax1 = plt.subplots()
|
| 82 |
+
ax1.plot(data['Price'], label="Price")
|
| 83 |
+
ax1.plot(data['MACD'], label="MACD", color="orange")
|
| 84 |
+
ax1.set_title("Price vs MACD")
|
| 85 |
+
ax1.legend()
|
| 86 |
+
|
| 87 |
+
# Plot RSI
|
| 88 |
+
fig2, ax2 = plt.subplots()
|
| 89 |
+
ax2.plot(data['RSI'], label="RSI", color="green")
|
| 90 |
+
ax2.axhline(70, linestyle="--", color="red")
|
| 91 |
+
ax2.axhline(30, linestyle="--", color="blue")
|
| 92 |
+
ax2.set_title("RSI Indicator")
|
| 93 |
+
ax2.legend()
|
| 94 |
+
|
| 95 |
+
# Checklist summary
|
| 96 |
+
checklist = [
|
| 97 |
+
"Bias > 30%",
|
| 98 |
+
"Even/Odd bias matches entry",
|
| 99 |
+
"Over/Under bias matches entry",
|
| 100 |
+
"Indicators aligned (MACD/RSI)",
|
| 101 |
+
"Final candle confirmation"
|
| 102 |
+
]
|
| 103 |
+
|
| 104 |
+
# Master Trading Board Poster text
|
| 105 |
+
poster = """
|
| 106 |
+
π Master Trading Board Poster
|
| 107 |
+
|
| 108 |
+
Bias Rules:
|
| 109 |
+
- Trade only if Bias > 30%
|
| 110 |
+
- Strong bias preferred (>60%)
|
| 111 |
+
|
| 112 |
+
Even/Odd Rules:
|
| 113 |
+
- Trade EVEN if bias favors even digits
|
| 114 |
+
- Trade ODD if bias favors odd digits
|
| 115 |
+
|
| 116 |
+
Over/Under Rules:
|
| 117 |
+
- Trade OVER if bias favors digits 5β9
|
| 118 |
+
- Trade UNDER if bias favors digits 0β4
|
| 119 |
+
|
| 120 |
+
Indicator Rules:
|
| 121 |
+
- MACD confirms trend
|
| 122 |
+
- RSI not overbought/oversold
|
| 123 |
+
- Candle pattern matches strategy
|
| 124 |
+
"""
|
| 125 |
+
|
| 126 |
+
# --- Export results to CSV ---
|
| 127 |
+
export_df = pd.DataFrame({
|
| 128 |
+
"Digit Bias Values": digit_bias_values,
|
| 129 |
+
"Checklist": checklist
|
| 130 |
+
})
|
| 131 |
+
buffer = io.StringIO()
|
| 132 |
+
export_df.to_csv(buffer, index=False)
|
| 133 |
+
buffer.seek(0)
|
| 134 |
+
|
| 135 |
+
return bias_msg, fig_gauge, fig_digits, fig1, fig2, checklist, poster, psychology_text, buffer
|
| 136 |
+
|
| 137 |
+
with gr.Blocks() as demo:
|
| 138 |
+
with gr.Row():
|
| 139 |
+
with gr.Column():
|
| 140 |
+
digit = gr.Number(label="Digit (0β9)")
|
| 141 |
+
bias = gr.Slider(0, 100, step=5, label="Bias %")
|
| 142 |
+
digit_bias_list = gr.Dataframe(headers=[str(i) for i in range(10)], row_count=1, col_count=10,
|
| 143 |
+
label="Digit Bias Input (0β9)", type="numpy")
|
| 144 |
+
bias_file = gr.File(label="Upload Bias Data (CSV/Excel)", file_types=[".csv", ".xlsx"])
|
| 145 |
+
digit_sequence = gr.Textbox(label="Digit Sequence (e.g. 1234555777)")
|
| 146 |
+
bias_out = gr.Textbox(label="Bias Interpretation")
|
| 147 |
+
gauge_plot = gr.Plot(label="Bias Gauge")
|
| 148 |
+
digit_bias_plot = gr.Plot(label="Digit Bias Analyzer")
|
| 149 |
+
macd_plot = gr.Plot(label="MACD Chart")
|
| 150 |
+
rsi_plot = gr.Plot(label="RSI Chart")
|
| 151 |
+
psychology_out = gr.Textbox(label="Digit Psychology")
|
| 152 |
+
download_out = gr.File(label="Download Results (CSV)")
|
| 153 |
+
with gr.Column():
|
| 154 |
+
checklist_out = gr.Label(label="Checklist")
|
| 155 |
+
poster_out = gr.Textbox(label="Master Trading Board Poster")
|
| 156 |
+
|
| 157 |
+
demo.load(trading_dashboard,
|
| 158 |
+
inputs=[digit, bias, digit_bias_list, bias_file, digit_sequence],
|
| 159 |
+
outputs=[bias_out, gauge_plot, digit_bias_plot, macd_plot, rsi_plot, checklist_out, poster_out, psychology_out, download_out])
|
| 160 |
+
|
| 161 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
pandas
|
| 3 |
+
numpy
|
| 4 |
+
matplotlib
|
| 5 |
+
openpyxl
|