//@version=5
indicator("10m Predictor Complete", overlay=true)
// GET 10m DATA
c10 = request.security(syminfo.tickerid, "10", close)
h10 = request.security(syminfo.tickerid, "10", high)
l10 = request.security(syminfo.tickerid, "10", low)
atr10 = request.security(syminfo.tickerid, "10", ta.atr(14))
rsi10 = request.security(syminfo.tickerid, "10", ta.rsi(close, 14))
[macdLine, signalLine, histLine] = request.security(syminfo.tickerid, "10", ta.macd(close, 12, 26, 9))
stochK = request.security(syminfo.tickerid, "10", ta.stoch(close, high, low, 14))
// PREDICTIONS
slope = ta.change(c10, 3) / 3
pred_close = c10 + slope
pred_high = pred_close + atr10
pred_low = pred_close - atr10
// WEIGHTED SCORE
rsiScore = rsi10 > 70 ? 2 : rsi10 > 50 ? 1 : rsi10 < 30 ? -2 : -1
macdScore = macdLine > signalLine ? 2 : -2
stochScore = stochK > 80 ? 2 : stochK > 50 ? 1 : stochK < 20 ? -2 : -1
weightedScore = (rsiScore * 30) + (macdScore * 40) + (stochScore * 30)
// SIGNALS
confidence = math.min(100, math.abs(weightedScore))
isBullish = weightedScore > 40
isBearish = weightedScore < -40
futureDecision = isBullish ? "HIGH" : isBearish ? "LOW" : "NEUTRAL"
rsiSig = rsi10 > 50 ? "HIGH" : "LOW"
macdSig = macdLine > signalLine ? "HIGH" : "LOW"
stochSig = stochK > 50 ? "HIGH" : "LOW"
// HISTORY
var array hTime = array.new()
var array hEntry = array.new()
var array hPred = array.new()
var array hSig = array.new()
var array hConf = array.new()
var array hClose = array.new()
var array hRes = array.new()
var array hStamp = array.new()
var bool lastBull = false
var bool lastBear = false
getIST() =>
t = time + 19800000
h = hour(t)
m = minute(t)
s = second(t)
(h<10?"0":"") + str.tostring(h) + ":" + (m<10?"0":"") + str.tostring(m) + ":" + (s<10?"0":"") + str.tostring(s)
if barstate.islast
newBull = isBullish and not lastBull
newBear = isBearish and not lastBear
if newBull or newBear
array.unshift(hTime, getIST())
array.unshift(hEntry, c10)
array.unshift(hPred, isBullish ? pred_high : pred_low)
array.unshift(hSig, isBullish ? "HIGH" : "LOW")
array.unshift(hConf, confidence)
array.unshift(hClose, na)
array.unshift(hRes, "PENDING")
array.unshift(hStamp, time)
for i = 0 to array.size(hStamp) - 1
if not na(array.get(hStamp, i))
elapsed = time - array.get(hStamp, i)
if elapsed >= 600000 and na(array.get(hClose, i))
array.set(hClose, i, close)
sig = array.get(hSig, i)
entry = array.get(hEntry, i)
isWin = (sig == "HIGH" and close > entry) or (sig == "LOW" and close < entry)
array.set(hRes, i, isWin ? "WIN ✓" : "LOSS ✗")
lastBull := isBullish
lastBear := isBearish
// PLOTS
plot(c10, "10m Close", color.orange, 3)
plot(h10, "10m High", color.new(color.red, 50), 2)
plot(l10, "10m Low", color.new(color.green, 50), 2)
plot(pred_high, "Pred High", color.red, 2, plot.style_circles)
plot(pred_low, "Pred Low", color.green, 2, plot.style_circles)
// LINES
var line lh = na
var line ll = na
var line lc = na
if barstate.islast
if not na(lh)
line.delete(lh)
if not na(ll)
line.delete(ll)
if not na(lc)
line.delete(lc)
lh := line.new(bar_index, pred_high, bar_index + 6, pred_high, width=2, color=color.red)
ll := line.new(bar_index, pred_low, bar_index + 6, pred_low, width=2, color=color.green)
lc := line.new(bar_index, pred_close, bar_index + 6, pred_close, width=1, style=line.style_dashed, color=color.blue)
// COUNTDOWN
rem = 600000 - (timenow % 600000)
rem := rem == 600000 ? 0 : rem
min = math.floor(rem / 60000)
sec = math.floor((rem % 60000) / 1000)
cd = str.tostring(min) + ":" + (sec < 10 ? "0" : "") + str.tostring(sec)
// LABEL
var label lbl = na
if barstate.islast
txt = (isBullish ? "📈 BULLISH\nHIGH" : isBearish ? "📉 BEARISH\nLOW" : "➡️ NEUTRAL") + "\n" + cd
col = isBullish ? color.green : isBearish ? color.red : color.gray
if na(lbl)
lbl := label.new(bar_index, high, txt, color=color.new(col, 50), textcolor=color.white, size=size.small)
else
label.set_xy(lbl, bar_index, high)
label.set_text(lbl, txt)
label.set_color(lbl, color.new(col, 50))
// INFO TABLE
var table t1 = table.new(position.top_right, 3, 9, bgcolor=color.new(color.black, 85))
if barstate.islast
table.cell(t1, 0, 0, "INDICATOR", text_color=color.yellow, bgcolor=color.new(color.orange, 80), text_size=size.tiny)
table.cell(t1, 1, 0, "VALUE", text_color=color.yellow, bgcolor=color.new(color.orange, 80), text_size=size.tiny)
table.cell(t1, 2, 0, "SIGNAL", text_color=color.yellow, bgcolor=color.new(color.orange, 80), text_size=size.tiny)
table.cell(t1, 0, 1, "WEIGHTED", bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t1, 1, 1, str.tostring(math.round(weightedScore)), bgcolor=color.new(color.purple, 80), text_size=size.tiny)
wc = isBullish ? color.green : isBearish ? color.red : color.gray
table.cell(t1, 2, 1, futureDecision, bgcolor=color.new(wc, 80), text_size=size.tiny)
table.cell(t1, 0, 2, "RSI", bgcolor=color.new(color.blue, 80), text_size=size.tiny)
table.cell(t1, 1, 2, str.tostring(math.round(rsi10)), bgcolor=color.new(color.blue, 80), text_size=size.tiny)
rc = rsiSig == "HIGH" ? color.green : color.red
table.cell(t1, 2, 2, rsiSig, bgcolor=color.new(rc, 80), text_size=size.tiny)
table.cell(t1, 0, 3, "MACD", bgcolor=color.new(color.blue, 80), text_size=size.tiny)
table.cell(t1, 1, 3, str.tostring(math.round(histLine, 2)), bgcolor=color.new(color.blue, 80), text_size=size.tiny)
mc = macdSig == "HIGH" ? color.green : color.red
table.cell(t1, 2, 3, macdSig, bgcolor=color.new(mc, 80), text_size=size.tiny)
table.cell(t1, 0, 4, "STOCH", bgcolor=color.new(color.blue, 80), text_size=size.tiny)
table.cell(t1, 1, 4, str.tostring(math.round(stochK)), bgcolor=color.new(color.blue, 80), text_size=size.tiny)
sc = stochSig == "HIGH" ? color.green : color.red
table.cell(t1, 2, 4, stochSig, bgcolor=color.new(sc, 80), text_size=size.tiny)
table.cell(t1, 0, 5, "HOUSE WIN", bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t1, 1, 5, futureDecision, bgcolor=color.new(wc, 80), text_size=size.tiny)
table.cell(t1, 2, 5, str.tostring(math.round(confidence)) + "%", bgcolor=color.new(color.orange, 80), text_size=size.tiny)
table.cell(t1, 0, 6, "HIGH", bgcolor=color.new(color.green, 80), text_size=size.tiny)
table.cell(t1, 1, 6, str.tostring(pred_high), bgcolor=color.new(color.green, 80), text_size=size.tiny)
table.cell(t1, 2, 6, "LOW", bgcolor=color.new(color.red, 80), text_size=size.tiny)
table.cell(t1, 0, 7, str.tostring(pred_low), bgcolor=color.new(color.red, 80), text_size=size.tiny)
table.cell(t1, 1, 7, "CURRENT", bgcolor=color.new(color.blue, 80), text_size=size.tiny)
table.cell(t1, 2, 7, str.tostring(c10), bgcolor=color.new(color.blue, 80), text_size=size.tiny)
table.cell(t1, 0, 8, "IST: " + getIST(), bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t1, 1, 8, cd, bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t1, 2, 8, "LIVE ✓", bgcolor=color.new(color.green, 80), text_size=size.tiny)
// HISTORY TABLE
var table t2 = table.new(position.bottom_right, 8, 21, bgcolor=color.new(color.black, 85))
if barstate.islast
table.cell(t2, 0, 0, "IST", text_color=color.yellow, bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t2, 1, 0, "Entry", text_color=color.yellow, bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t2, 2, 0, "Pred", text_color=color.yellow, bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t2, 3, 0, "CD", text_color=color.yellow, bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t2, 4, 0, "Sig", text_color=color.yellow, bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t2, 5, 0, "Conf", text_color=color.yellow, bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t2, 6, 0, "Close", text_color=color.yellow, bgcolor=color.new(color.purple, 80), text_size=size.tiny)
table.cell(t2, 7, 0, "Result", text_color=color.yellow, bgcolor=color.new(color.purple, 80), text_size=size.tiny)
sz = math.min(array.size(hTime), 20)
for i = 0 to sz - 1
r = i + 1
stamp = array.get(hStamp, i)
elapsed = time - stamp
remMs = math.max(0, 600000 - elapsed)
cdMin = math.floor(remMs / 60000)
cdSec = math.floor((remMs % 60000) / 1000)
cdTxt = str.tostring(cdMin) + ":" + (cdSec < 10 ? "0" : "") + str.tostring(cdSec)
table.cell(t2, 0, r, array.get(hTime, i), bgcolor=color.new(color.blue, 80), text_size=size.tiny)
table.cell(t2, 1, r, str.tostring(array.get(hEntry, i)), bgcolor=color.new(color.blue, 80), text_size=size.tiny)
table.cell(t2, 2, r, str.tostring(array.get(hPred, i)), bgcolor=color.new(color.blue, 80), text_size=size.tiny)
table.cell(t2, 3, r, cdTxt, bgcolor=color.new(color.blue, 80), text_size=size.tiny)
sig = array.get(hSig, i)
sigC = sig == "HIGH" ? color.green : color.red
table.cell(t2, 4, r, sig, bgcolor=color.new(sigC, 80), text_size=size.tiny)
table.cell(t2, 5, r, str.tostring(math.round(array.get(hConf, i))) + "%", bgcolor=color.new(color.orange, 80), text_size=size.tiny)
cls = array.get(hClose, i)
clsTxt = na(cls) ? "Wait" : str.tostring(cls)
table.cell(t2, 6, r, clsTxt, bgcolor=color.new(color.blue, 80), text_size=size.tiny)
res = array.get(hRes, i)
resC = res == "PENDING" ? color.orange : str.contains(res, "WIN") ? color.green : color.red
table.cell(t2, 7, r, res, bgcolor=color.new(resC, 80), text_size=size.tiny)
plotshape(isBullish, "BUY", shape.labelup, location.belowbar, color.green, text="BUY", size=size.small)
plotshape(isBearish, "SELL", shape.labeldown, location.abovebar, color.red, text="SELL", size=size.small)
# app.py from flask import Flask, jsonify import numpy as np import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import LSTM, Dense import requests app = Flask(__name__) # Binance se last 60 minute price data fetch karna def fetch_binance_data(): url = "https://api.binance.com/api/v3/klines?symbol=BTCUSDT&interval=1m&limit=60" data = requests.get(url).json() closes = [float(item[4]) for item in data] return closes # LSTM input prepare karna sliding window ke form me def prepare_data(series, n_steps): X, y = [], [] for i in range(len(series) - n_steps): X.append(series[i:i+n_steps]) y.append(series[i+n_steps]) return np.array(X), np.array(y) # LSTM model train karna def train_model(series): n_steps = 10 X, y = prepare_data(series, n_steps) X = X.reshape((X.shape[0], X.shape[1], 1)) model = Sequential([ LSTM(50, activation='relu', input_shape=...
Comments
Post a Comment