Kaito Box with RSI Div(Dynamic Adjustment + MA + Long)

Key Features:
Box Range Detection:
The script identifies price ranges using the highest high and lowest low of a configurable boxLength period.
These levels are plotted on the chart to visualize the price range.
RSI Divergence Detection:
The script calculates RSI using a configurable rsiLength.
Detects bullish divergence when price makes a lower low, but RSI makes a higher low.
Detects bearish divergence when price makes a higher high, but RSI makes a lower high.
Includes separate left and right lookback periods (leftLookback, rightLookback) for precise local extrema detection.
Customizable Moving Averages:
Supports multiple types of Moving Averages (SMA, EMA, SMMA, WMA, VWMA).
Calculates and plots MA20, MA50, MA100, and MA200 on a user-defined timeframe (custom_timeframe).
Identifies uptrends and downtrends based on the alignment of the moving averages and price levels.
Dynamic Position Scaling:
Implements dynamic position sizing for long entries and partial position closing for exits.
The percentage of position size added or closed is based on the difference between the current price and the average position price (avgPrice), with configurable minimum thresholds (minEnterPercent, minExitPercent).
Signal Integration for OKX Bots:
Sends buy/sell signals to OKX Signal Bots using the configured signalToken.
Supports market or limit orders with configurable price offsets and investment types.
Trend-Based Signal Filtering:
Only triggers long signals during downtrends and short signals during uptrends, ensuring trades align with the overall market context.
Visual Annotations:
Plots bullish and bearish divergence signals on the chart.
Displays labels showing dynamic position size adjustments and current average price during trades.
How It Works:
Long Signals:
Triggered when the price breaches the lower box range, and a bullish RSI divergence is detected.
Additional filtering ensures long trades are executed only during downtrend conditions.
Dynamically adjusts the position size based on the price difference from the average entry price.
Short Signals:
Triggered when the price breaches the upper box range, and a bearish RSI divergence is detected.
Additional filtering ensures short trades are executed only during uptrend conditions.
Dynamically closes portions of the position based on price movement relative to the average entry price.
Alerts:
Generates actionable alerts formatted for OKX bots, including order type, signal token, and dynamically calculated position sizes.
Use Case:
This strategy is well-suited for automated trading on platforms like OKX, where it can:
Exploit price ranges and RSI divergences for precise entries and exits.
Dynamically manage position sizes to optimize risk-reward.
Adapt to different market conditions using configurable parameters like moving averages, divergence lookbacks, and trend filters.
This script provides a robust foundation for traders looking to automate their strategies while maintaining flexibility and control over their trading logic.
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.
Penafian
Skrip sumber terbuka
Dalam semangat sebenar TradingView, pencipta skrip ini telah menjadikannya sumber terbuka supaya pedagang dapat menilai dan mengesahkan kefungsiannya. Terima kasih kepada penulis! Walaupun anda boleh menggunakannya secara percuma, ingat bahawa menerbitkan semula kod ini adalah tertakluk kepada Peraturan Dalaman kami.
Untuk akses pantas pada carta, tambah skrip ini kepada kegemaran anda — ketahui lebih lanjut di sini.