SUPER TRADECORPThis tool represents a comprehensive analytical engine built upon a deep synthesis of multiple market parameters and dynamic price and volume characteristics. At its core lies the integration of advanced ICP (Smart Money Concepts), enabling the identification of key zones of institutional activity and decision-making based on subtle market impulses.
The indicator adaptively responds to market conditions, detecting moments of potential trend reversals or continuations with high precision through complex multi-layered signal filtering. Visualization includes not only entry and exit signals but also dynamic risk management levels constructed on adaptive algorithms that take into account current market structure and volatility.
The result is a powerful instrument that provides traders with a timely and high-quality informational advantage, helping minimize errors and optimize trading decisions across various timeframes and asset classes.
อินดิเคเตอร์และกลยุทธ์
RSI BUY SELL BY Josh2 — Signals )RSI BY Josh2 — Signals คืออินดิเคเตอร์ RSI ระดับโปรสำหรับ TradingView ที่เพิ่มตรรกะสัญญาณ, เส้น High/Low ของ RSI และตรวจจับ Divergence พร้อมระบบแจ้งเตือนครบชุด ช่วยให้ตัดสินใจเข้า–ออกได้มั่นใจและทันจังหวะมากขึ้น
✅ สิ่งที่ผู้ซื้อจะได้รับ
สัญญาณ BUY/SELL แบบอัตโนมัติ ตามโหมดที่เลือก (เข้มงวด/ผ่อนคลาย/เชิงรุก)
ลูกศร + ป้ายข้อความบนกราฟ มองเห็นสัญญาณชัดเจน ไม่ต้องตีความเอง
ระบบแจ้งเตือน (Alerts) ครบทั้งสัญญาณ BUY/SELL, New RSI High/Low, และ Divergence
เส้น RSI High/Low ตามช่วงดูย้อนหลัง บอกบริบทแรงซื้อ–ขายช่วงล่าสุด
ตรวจจับ Divergence ระหว่างราคาและ RSI (Bullish/Bearish) พร้อมวาดเส้นและป้าย
คูลดาวน์สัญญาณ (Min bars) ป้องกันสัญญาณถี่เกินไป
เลือกปล่อยสัญญาณแบบ Realtime ได้ (intrabar) หรือรอยืนยันแท่งปิดเพื่อความแม่นยำ
ปรับแต่งยืดหยุ่น: RSI length, โซน OB/OS, โหมดสัญญาณ, ช่วง lookback, ขนาดและการแสดงผลต่าง ๆ
🔄 แตกต่างจาก RSI ธรรมดายังไง?
RSI ปกติ: ให้แค่ค่า RSI/เส้นระดับ → ผู้ใช้ต้องตีความเอง
RSI BY Josh2: มีตรรกะสัญญาณ 3 โหมด + คูลดาวน์ + เส้น High/Low + Divergence + Alerts → แจ้งชัด, ใช้งานจริงง่าย, ลดการพลาดจังหวะ
⚙️ อธิบายการตั้งค่าหลัก (สั้น ๆ)
RSI Length: ค่าเริ่มต้น 14 (มาตรฐาน)
Overbought/Oversold: 70/30 (ปรับได้)
Signal Mode
Strict 30/70: เข้มงวด—ซื้อเมื่อ RSI ตัดขึ้นเหนือ 30 / ขายเมื่อ RSI ตัดลงต่ำกว่า 70
Loose: ยืดหยุ่น—ดูว่าช่วงล่าสุดเคยหลุด 30/70 และ RSI กำลัง “ไต่ขึ้น/ลง”
Aggressive: เชิงรุก—ตัดขึ้น/ลงเส้น 50 เพื่อจับโมเมนตัมไว
Min bars between signals: เว้นช่วงสัญญาณเพื่อเลี่ยง “ยิงรัว”
Show RSI High/Low: วาดเส้น High/Low ของ RSI จากค่า lookback ที่กำหนด
Divergence: ปรับ Pivot length เพื่อความไว/ช้าในการจับจุดกลับตัว
🔔 การตั้ง Alert (แนะนำ)
ใส่สคริปต์ลงกราฟ → คลิก Create Alert
เลือกเงื่อนไขเป็นชื่ออินดิเคเตอร์นี้
มีเงื่อนไขให้เลือก: RSI BUY / RSI SELL / RSI New High / RSI New Low / RSI Bullish/Bearish Divergence
เลือกรูปแบบการแจ้งเตือน (ครั้งเดียว/ย้ำทุกครั้ง) และช่องทาง (แอป/อีเมล/เว็บฮุค)
🧠 เคล็ดลับใช้งาน
โหมด Strict เหมาะกับสวิงเทรด/ยืนยันแรงซื้อ–ขายชัดเจน
โหมด Loose ใช้จับสัญญาณ “รีเทส” หลังออกจากโซน 30/70
โหมด Aggressive ใช้จับโมเมนตัมเร็ว แนะนำเปิดคูลดาวน์เพื่อลดสัญญาณหลอก
ใช้ร่วมกับแนวรับ–ต้าน หรือ Price Action เพื่อยกระดับความมั่นใจ
คำเตือน: ไม่มีอินดิเคเตอร์ใดแม่น 100% ควรบริหารความเสี่ยงเสมอ
RSI BY Josh2 — Signals is a pro-grade RSI indicator for TradingView that adds multi-mode signal logic, RSI High/Low bands, divergence detection, and full alert support—so you can act faster with greater confidence.
✅ What you get
Automatic BUY/SELL signals across three modes (Strict/Loose/Aggressive)
On-chart arrows & text labels for crystal-clear entries/exits
Comprehensive Alerts: BUY/SELL, RSI New High/Low, Bullish/Bearish Divergence
RSI High/Low lines over a lookback window to frame current strength/weakness
Divergence detection between price and RSI with lines and labels
Signal cooldown (Min bars) to reduce noise/over-triggering
Realtime option (intrabar) or bar-close confirmation for reliability
Full customization of RSI length, OB/OS, modes, lookbacks, and visuals
🔄 How it beats “plain RSI”
Plain RSI: values + thresholds → you must interpret manually
RSI BY Josh2: three signal modes + cooldown + RSI High/Low + Divergence + Alerts → clearer, faster, more actionable
⚙️ Key settings (at a glance)
RSI Length: default 14
Overbought/Oversold: 70/30 (adjustable)
Signal Mode
Strict 30/70: classic OB/OS re-entries (safer)
Loose: requires recent touches of 30/70 + rising/falling context
Aggressive: 50-line crosses for early momentum
Min bars between signals: enforce spacing
RSI High/Low: plots rolling extremes for context
Divergence: tune Pivot length to control sensitivity
🔔 Alerts (quick setup)
Add the script → Create Alert
Choose this indicator as the condition
Pick from RSI BUY / RSI SELL / RSI New High / RSI New Low / RSI Bullish/Bearish Divergence
Select frequency and delivery (app/email/webhook)
🧠 Pro tips
Strict for swing traders & confirmation
Loose to catch retests after leaving OB/OS
Aggressive for early momentum (pair with cooldown)
Combine with SR/price action for higher conviction
Note: No indicator is perfect—use risk management
MACD Buy Sell Josh สิ่งที่ได้เมื่อซื้อไป
MACD เวอร์ชันปรับปรุง – ไม่ใช่แค่เส้น MACD ธรรมดา แต่เพิ่มการแจ้งเตือนและลูกศรชี้จุดซื้อ–ขายทันที
สัญญาณที่ชัดเจน – มีข้อความ “BUY” / “SELL” แสดงบนกราฟ ไม่ต้องมานั่งตีความเอง
ระบบแจ้งเตือนอัตโนมัติ (Alerts) – เมื่อมีสัญญาณเกิดขึ้น TradingView จะแจ้งเตือนทันที ไม่พลาดโอกาสเข้าเทรด
การปรับแต่งได้เต็มที่ – ตั้งค่า EMA ได้ตามสไตล์การเทรด ไม่จำกัด
ใช้งานง่าย – ทั้งมือใหม่และมือโปรเข้าใจได้ทันที ไม่ซับซ้อน
สบายใจเรื่องความน่าเชื่อถือ – ใช้หลักการ MACD ของ MT5 มาตรฐานโลก
แตกต่างจาก MACD ธรรมดาอย่างไร?
MACD ปกติ: ต้องดูกราฟ ตีความเอง เสี่ยงพลาดจังหวะ
MACD Buy/Sell Josh: มีลูกศร + ข้อความ + แจ้งเตือนให้พร้อม ไม่ต้องนั่งเฝ้าหน้าจอ
What you get with this indicator
Enhanced MACD – Not just a simple MACD line, but with instant BUY/SELL signals and alerts.
Clear Trading Signals – Arrows and text (“BUY” / “SELL”) appear directly on the chart, no guesswork needed.
Automatic Alerts – TradingView notifies you instantly when a signal appears, so you never miss an entry.
Full Customization – Adjustable EMA lengths to fit your trading style.
Easy to Use – Designed for both beginners and professional traders.
Reliable Standard – Built on MT5-style MACD logic, trusted worldwide.
How it’s different from normal MACD
Normal MACD: You must analyze and interpret signals yourself → higher chance of missing opportunities.
MACD Buy/Sell Josh: Provides arrows, labels, and alerts automatically → saves time, increases confidence.
Spectrometer Candle colorCandle's color changes based on spectrometer.
Red = mm > hft
Green = mm < hft
TEWMA Supertrend - [JTCAPITAL]TEWMA Supertrend is a modified way to use Triple Exponential Weighted Moving Average inside Supertrend logic for Trend-Following
The indicator works by calculating in the following steps:
1. Calculate the Triple Exponential Moving Average with Weighted Moving Average as input.
2. Calculate the ATR over the Supertrend Length
3. Use the Triple Exponential Weighted Moving Average, and add the multiplier times the ATR for the upper limit, and subtract the multiplier times the ATR for the lower limit.
4. Define Buy and Sell conditions based on the price closing above or below the upper and lower limits.
--Buy and sell conditions--
- The buy and sell conditions are defined by the price going above/below the upper and lower limits, calculated by (TEWMA +/- multi * ATR).
- When this goes on the opposite direction of the current trend, the trend changes. If this goes in the same direction of the current trend, the line follows the price by moving up.
- When price gets closer to the limits the limits do not change. The upper limit only moves when the upper decreases, and the lower limit only moves when the lower increases.
- The ATR gets subtracted from the lows or added onto the highs to eliminate false signals in choppy markets, while enforcing fast entries and exits.
--Features and Parameters--
- Allows the usage of different sources
- Allows the changing of the length of the ATR
- Allows the changing of the length of the TEWMA
- Allows the changing of the multiplier to increase or decrease ATR usage
--Details--
This script is using TEWMA as input for the modified Supertrend. Using a TEWMA and getting a higher multiplier to the ATR is meant to decrease false signals. Which can be a problem when using a normal Supertrend. Using the TEWMA also ensures fast entries and exits from fast market moves after a calm period. Ensuring you don't stay left behind.
Be aware that lowering the multiplier for the ATR will allow for faster entries and exits but also allow for more false signals. It is recommended to change the parameters to fit your liking and to adjust to the timeframe you are working on.
Enjoy!
ICT 00:00, 08:30 & 09:30 Opens (NY) ICT 00:00, 08:30 & 09:30 Opens (NY)
Clean intraday reference levels for 0000, 0830, and 0930 anchored to America/New_York.
Lines start at each session’s open and extend just a few bars past the last candle (configurable).
Labels are text-only (0000, 0830, 0930), placed at the right end of each line and adjust as you change timeframes.
Why these times?
0000 NY – daily anchor / session bias
0830 NY – common US data windows (CPI, NFP, claims)
0930 NY – US cash equity market open
Features
NY-time detection (works regardless of chart/exchange timezone; DST handled by TradingView)
Right-padded stubs (no full-chart lines)
Side labels at line tip (no bubbles, subtle opacity)
History toggle → show Today only or Today + Prior Day (older lines/labels auto-pruned)
Per-level styling: color · line style · width
Visibility toggles for 0830 and 0930
Inputs
00:00 (NY): Style, Color, Width, Show Label
08:30 (NY): Display, Style, Color, Width, Show Label
09:30 (NY): Display, Style, Color, Width, Show Label
Right Edge:
Right Pad (bars) – how far the line extends beyond the latest bar
Label Pad (bars) – extra space for the text to the right of the line
History:
Show Prior Day (History) – off = today only; on = today + yesterday
Tips
Works best on intraday charts (≤ 60m).
If two levels are close, nudge Label Pad or vary colors/styles for clarity.
Futures (ES/NQ/CL, etc.) remain NY-anchored even if the exchange is not.
Notes
Pine v5.
Minimalist: no day dividers by design.
Educational tool; not financial advice.
Changelog
Current: Added Show Prior Day (History) toggle; switched to right-padded stubs; labels moved to line tip and made text-only.
License: MPL-2.0
© ALPHAICTRADER
Keywords: ICT, New York midnight, 0830, 0930, NY open, session open, daily open, CPI open, cash open, levels, anchors, intraday, futures, forex, indices
Intraday scalping indicator @Tharanithar.007v1.5.3
PDLHM & Session Break, FX Session, SBT, Fractal, True day open, day light saving with day high low and session high low alert
Pendulum scalper 2ndProjectMulti TF pendulum helper for scalper traders. Shows index for each timeframe on one table.
1H - FVG (Imbalance) ZonesFVG (Imbalance) Zones
FVG (Imbalance) Zones
FVG (Imbalance) Zones
FVG (Imbalance) Zones
Minervini Trend Template (v6, fixed)Using Mark Minervini Trend Template to identify stock in Stage 2 Accumulation/Uptrend
Supertrend Channel Histogram OscillatorThis histogram is based on the script "Supertrend Channels "
The idea of the indicator is to visually represent the interaction of price with several different supertrend channels of various lengths in an oscillator in order to make it much more clear to the trader how the longer trends are interacting with shorter trends of the price movement of an asset. I got this idea from the "Kurutoga Cloud" and "Kurutoga Histogram" by D7R which is based on the centerlines of 3 Donchian Channels, however after I started using the Supertrend Channel by LuxAlgo I found that it was a more reliable price range channel than a standard Donchian Channel and I made this indicator to accompany it.
This indicator plots a positive value above 0 when the price is above the centerline of the supertrend channel and a negative value below 0 when the price is below the centerline.
The first supertrend's length and multiple can be adjusted in the settings.
The given supertrend input is then doubled and quadrupled in both length and multiplication so that a supertrend histogram with the values of 3, 3 will be accompanied by 2 additional supertrend histograms with the values of 6, 6 and 12, 12.
The larger price trend histograms are clearly visible behind the short term supertrend channel's histogram, giving traders a balanced view of short and long term trends interacting. The less visible columns of the larger trend remain above or below the 0 line behind the more visible short term channel trend, helping to spot pullbacks within a larger trend.
Additionally, when the 3 separate histograms are all positive or all negative but the histogram columns are separating from each other this can indicate a potential trend exhaustion leading to reversal or pullback about to happen.
The overbought and oversold lines at 50 and -50 are representative primarily of the short term trend with above 50 or below -50 indicating that the price is pushing the boundary and potentially beginning a new short term supertrend in the opposite direction. If values do not noticably exceed these levels, then the current short term trend movement can be viewed as a pullback within a larger trend, with continuation potentially to follow.
I have had troubles converting the original code to v6 so this will be published here in v5 of pinescript to be used in conjunction with the original. I was intending to create a companion indicator for this oscillator that represents 3 supertrends with corresponding 2x and 4x calculations based on LuxAlgo's script, but I can't seem to get it to work correctly in v5.
For best visualization of the trends 3 LuxAlgo Supertrend channels with 2x and 4x values should be used in conjunction with each other to fully visualize the histogram.
Used in conjunction with other indicators this can be a very effective strategy to capture larger trend moves and pullbacks within trends, as well as warn of potential price trend exhaustion.
Morrizen - EMA 7/25/99This indicator plots three Exponential Moving Averages (EMAs) with periods of 7, 25, and 99.
The 7 EMA captures short-term momentum.
The 25 EMA reflects medium-term trend direction.
The 99 EMA highlights the broader, long-term trend.
Traders often use the interaction between these EMAs to identify entry and exit signals, trend strength, and potential reversals. For example, when the shorter EMAs (7 or 25) cross above the 99 EMA, it may indicate bullish momentum; when they cross below, it may suggest bearish momentum.
Cruce TEMA SMMA con Alarma a 12 BarrasPROBANDO Una estrategia de 12 velas para la venta de xauusd en temporalidades de 1h a 1 minuto
EMA 26n50 Cross - Easy_Singnals_Red_Green_Yashpal_RajputFeatures Included:
Green Line: 26-period EMA.
Red Line: 50-period EMA.
Candlesticks: Preserved as the base chart.
Condition 1 : Green Shading : Now shows Green when EMA 26 is above EMA 50.
Condition 2 : Red Shading : Now shows Red when EMA 50 is above EMA 26.
Condition-Based Shading: When Condition 1 meet then it will show Green shade.
Condition-Based Shading: When Condition 2 meet then it will show Red shade.
Estocástico ZenPrice change based on stochastic, it identifies possible reversals and continuation in price
Reference timesThe user defines a weekday and time he wants to inquire.
The script searches for past weekdays and similar hours.
It marks these bars at their wicks.
The user can also inquire "opposite hours" - 12 hours ahead or earlier.
The user can also inquire "opposite days" - Monday<->Wednesday, Tuesday<->Thursday.
In addition, the User may inquire the previous day of his selected weekday, which will mark the most recent previous day existent.
Side note: The Time zone offset is set for Jerusalem time. and so it may need future adjustment.
Bozethe ICT Extended MacrosBozethe ICT Extended Macros
Overview
This indicator automatically marks the London and New York ICT killzones on your chart, extended to run from xx:45 → xx:15 instead of the classic xx:50 → xx:10.
It highlights the high/low range of each session window, fills zones with custom colors, and labels them directly on the chart for easy reference.
The script is DST-aware, timezone-flexible, and highly customizable, making it ideal for traders who follow ICT’s intraday trading models.
Included Macros
London
Macro 1 (02:33–03:00 / 07:33–08:00 depending on TZ & DST)
Macro 2 (04:03–04:30 / 09:03–09:30)
New York
AM 1: 08:45–09:15
AM 2: 09:45–10:15
AM 3: 10:45–11:15
Lunch: 11:45–12:15
PM: 12:45–13:15
Last Hour: 15:15–15:45
All macros automatically adjust for Standard vs Daylight Saving Time.
Features
✅ Extended ICT windows (:45 → :15).
✅ Auto-adjust for DST (London & New York separately).
✅ Show in UTC, local session time, or your custom timezone.
✅ Toggle on/off each macro individually.
✅ Custom color settings for every session.
✅ Option to display start/end times on labels.
✅ Tracks session highs and lows until the window closes.
Usage
Add to chart (works best on 1m–1h timeframes).
Choose Time Zone Mode (UTC, Session Local, or Your Time Zone).
Enable only the killzones you want to see.
Use shaded ranges as context for entries, SMT divergence, FVGs, or liquidity hunts.
Notes
Visual mapping only — no alerts/signals.
Works on all instruments (indices, futures, forex, crypto).
Tailored for ICT-style intraday setups.
Credits
Script by Bozethe
Based on ICT Killzone concepts (public educational material)
First presented FVG as defined by T2This indicator plots the first presented fair value gap that forms on NQ/MNQ, per the requirements of T2 SMC Trader(www.youtube.com x.com/t2smctrader) It also has 3 extra, time-based fvgs that can be added by the user(for user experiment only, not part of T2's teaching). All starting times, minimum gap size, colors and labels are user-configurable through the indicators settings. Alarms can be set for when a gap forms. Through forward and back testing you will see these fvgs represent significant areas of price for continuation or reversal
VitaLegacy Scalper// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
// Join our channel for more free tools: t.me
//@version=5
indicator("Trader DrFXAi", "VitaLegacy Scalper"
, overlay = true
, max_labels_count = 500
, max_lines_count = 500
, max_boxes_count = 500
, max_bars_back = 500)
//INICIA MODULO SUPERTREND
// Get user input
//INICIA MODULO SUPERTREND
// Get user input
// Instead of inputs, define constants or variables directly
// Instead of inputs, define constants or variables directly
var float nsensitivity = 1
nbuysell = input.bool(true, 'Buy/Sell Signal', inline = "BSNM",group='BUY/SELL SIGNAL')
// SMA
sma4_strong = ta.sma(close, 8)
sma5_strong = ta.sma(close, 9)
// Signal Generation
// Signal Generation Function
supertrend(_src, factor, atrLen) =>
atr = ta.atr(atrLen)
upperBand = _src + factor * atr
lowerBand = _src - factor * atr
prevLowerBand = nz(lowerBand )
prevUpperBand = nz(upperBand )
lowerBand := lowerBand > prevLowerBand or close < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close > prevUpperBand ? upperBand : prevUpperBand
var int direction = na
var float superTrend = na
prevSuperTrend = nz(superTrend )
if na(atr )
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
= supertrend(close, nsensitivity*7,10)
//señales
bull = ta.crossover(close, supertrend)
bear = ta.crossunder(close, supertrend)
//FIN MODULO SUPERTREND
// Risk Management
levels2 = input.bool(true, "Show TP/SL Levels2" , group = "Risk Management" , inline = "MMDB2")
lvlLines = input.bool(true, "Show Lines ", inline="levels2", group = "Risk Management")
linesStyle = input.string("SOLID", "", , inline="levels2", group = "Risk Management")
lvlDistance = input.int(40, "Distance", 1, inline="levels2", group = "Risk Management")
lvlDecimals = input.int(4, " Decimals", 1, 8, inline="levels2", group = "Risk Management")
atrRisk = input.int(3, "Risk % ", 1, group = "Risk Management" , inline="levels3")
atrLen = input.int(14, " ATR Length", 1, group = "Risk Management" , inline="levels3")
decimals = lvlDecimals == 1 ? "#.#" : lvlDecimals == 2 ? "#.##" : lvlDecimals == 3 ? "#.###" : lvlDecimals == 4 ? "#.####" : lvlDecimals == 5 ? "#.#####" : lvlDecimals == 6 ? "#.######" : lvlDecimals == 7 ? "#.#######" : "#.########"
CirrusCloud = input(true, 'Cirrus Cloud', group='TREND FEATURES')
// Plots
windowsize = 100
offset = 0.9
sigma = 6
//plot(ta.alma(source, windowsize, offset, sigma))
windowsize2 = 310
offset2 = 0.85
sigma2 = 32
//plot(ta.alma(source, windowsize2, offset2, sigma2))
// Chart Features
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x ), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng = smoothrng(close, 22, 6)
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt ) ? x - r < nz(rngfilt ) ? nz(rngfilt ) : x - r : x + r > nz(rngfilt ) ? nz(rngfilt ) : x + r
rngfilt
filt = rngfilt(close, smrng)
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
upward = 0.0
upward := filt > filt ? nz(upward ) + 1 : filt < filt ? 0 : nz(upward )
downward = 0.0
downward := filt < filt ? nz(downward ) + 1 : filt > filt ? 0 : nz(downward )
filtcolor = upward > 0 ? color.new(#00e2ff, 50) : downward > 0 ? color.new(#fe0100, 50) : color.new(#56328f, 0)
// Trend Cloud
tclength = 600
hullma = ta.wma(2*ta.wma(close, tclength/2)-ta.wma(close, tclength), math.floor(math.sqrt(tclength)))
// Chart Features
x1 = 22
x2 = 9
x3 = 15
x4 = 5
smoothrngX1(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x ), t)
smoothrngX1 = ta.ema(avrng, wper) * m
smoothrngX1
smrngx1x = smoothrngX1(close, x1, x2)
smrngx1x2 = smoothrngX1(close, x3, x4)
rngfiltx1x1(x, r) =>
rngfiltx1x1 = x
rngfiltx1x1 := x > nz(rngfiltx1x1 ) ? x - r < nz(rngfiltx1x1 ) ? nz(rngfiltx1x1 ) : x - r : x + r > nz(rngfiltx1x1 ) ? nz(rngfiltx1x1 ) : x + r
rngfiltx1x1
filtx1 = rngfiltx1x1(close, smrngx1x)
filtx12 = rngfiltx1x1(close, smrngx1x2)
// ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒
upwardx1 = 0.0
upwardx1 := filtx1 > filtx1 ? nz(upwardx1 ) + 1 : filtx1 < filtx1 ? 0 : nz(upwardx1 )
downwardx1 = 0.0
downwardx1 := filtx1 < filtx1 ? nz(downwardx1 ) + 1 : filtx1 > filtx1 ? 0 : nz(downwardx1 )
filtx1colorx1 = color.rgb(0, 187, 212, 100)
xxx1 = plot(CirrusCloud ? filtx1 : na, color=filtx1colorx1, linewidth=1, title='Trend Tracer', editable = false)
xxx2 = plot(CirrusCloud ? filtx12 : na, color=filtx1colorx1, linewidth=1, title='Trend Tracer', editable = false)
fill(xxx1, xxx2, color= filtx1 > filtx12 ? color.rgb(254, 0, 0, 86) : color.rgb(21, 255, 0, 86))
trigger2 = bull ? 1 : 0
countBull = ta.barssince(bull)
countBear = ta.barssince(bear)
trigger = nz(countBull, bar_index) < nz(countBear, bar_index) ? 1 : 0
atrBand = ta.atr(atrLen) * atrRisk
atrStop = trigger == 1 ? low - atrBand : high + atrBand
// Colors
green = #2BBC4D, green2 = color.rgb(0, 221, 0, 27)
red = #C51D0B, red2 = #c51d0b
adxlen = 15
dilen = 15
dirmov(len) =>
up = ta.change(high)
down = -ta.change(low)
plusDM = na(up) ? na : up > down and up > 0 ? up : 0
minusDM = na(down) ? na : down > up and down > 0 ? down : 0
truerange = ta.rma(ta.tr, len)
plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
adx(dilen, adxlen) =>
= dirmov(dilen)
sum = plus + minus
adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
adx
sig = adx(dilen, adxlen)
// range ADX threshold
sidewaysThreshold = input.int(title='ADX Sideways Threshold (10-30)', minval=2, defval=15)
// boolean expression to see if the ADX is below tehe sideways threshold
bool isSideways = sig < sidewaysThreshold
// adding the option to color the bars when in a trading range
useBarColor = true
bColor = isSideways ? #b102fc : na
barcolor(useBarColor ? bColor : na)
barcolor(close > supertrend ? #3cff00 : #fe0100)
percentStop = input.float(1, "Stop Loss % (0 to Disable)", 0, group="BUY & SELL SIGNALS")
srcStop = close
lastTrade(src) => ta.valuewhen(bull or bear, src, 0)
entry_y = lastTrade(srcStop)
stop_y = lastTrade(atrStop)
tp1_y = (entry_y - lastTrade(atrStop)) * 1 + entry_y
tp2_y = (entry_y - lastTrade(atrStop)) * 2 + entry_y
tp3_y = (entry_y - lastTrade(atrStop)) * 3 + entry_y
labelTpSl(y, txt, color) =>
label labelTpSl = percentStop != 0 ? label.new(bar_index + 1, y, txt, xloc.bar_index, yloc.price, color, label.style_label_left, #000000, size.normal) : na
label.delete(labelTpSl )
if (levels2)
labelTpSl(entry_y, "Join and Enjoy @simpleforextools" + str.tostring(entry_y, decimals), color.rgb(242, 244, 252))
labelTpSl(stop_y , " Stop Loss -- " + str.tostring(stop_y, decimals), #f90808)
labelTpSl(tp1_y, " TP 1 -- " + str.tostring(tp1_y, decimals), #00ff08)
labelTpSl(tp2_y, " TP 2 -- " + str.tostring(tp2_y, decimals), #00ff08)
labelTpSl(tp3_y, " TP 3 -- " + str.tostring(tp3_y, decimals), #00ff08)
style2 = linesStyle == "SOLID" ? line.style_solid : linesStyle == "DASHED" ? line.style_dashed : line.style_dotted
lineTpSl(y, color) =>
line lineTpSl = percentStop != 0 ? line.new(bar_index - (trigger ? countBull : countBear) + 4, y, bar_index + 1, y, xloc.bar_index, extend.none, color, style2) : na
line.delete(lineTpSl )
if (lvlLines)
lineTpSl(entry_y, color.green)
lineTpSl(stop_y, color.red)
lineTpSl(tp1_y, color.green)
lineTpSl(tp2_y, color.green)
lineTpSl(tp3_y, color.green)
y1 = low - (ta.atr(30) * 2), y1B = low - ta.atr(30)
y2 = high + (ta.atr(30) * 2), y2B = high + ta.atr(30)
buy = bull and nbuysell ? label.new(bar_index, y1, sma4_strong >= sma5_strong ? "🚀" : "🚀", xloc.bar_index, yloc.price, color.rgb(10, 247, 18, 60), label.style_label_up, #000000, size.normal) : na
sell = bear and nbuysell ? label.new(bar_index, y2, sma4_strong <= sma5_strong ? "🐻" : "🐻", xloc.bar_index, yloc.price, color.rgb(239, 12, 12, 66), label.style_label_down, #000000, size.normal) : na
int volSen = 3
plotchar(volSen, "volSen", "", location.top)
// Get Components
ema1 = ta.ema(ohlc4, 5*volSen)
ema2 = ta.ema(ohlc4, 9*volSen)
ema3 = ta.ema(ohlc4, 13*volSen)
ema4 = ta.ema(ohlc4, 34*volSen)
ema5 = ta.ema(ohlc4, 50*volSen)
alertcondition(bull, title='Buy Signal', message = "BUY")
alertcondition(bear, title='sell Signal', message = "BUY")
//-----------------------------------------------------------------------------{
//Constants
//-----------------------------------------------------------------------------{
color TRANSP_CSS = #ffffff00
//Tooltips
string MODE_TOOLTIP = 'Allows to display historical Structure or only the recent ones'
string STYLE_TOOLTIP = 'Indicator color theme'
string COLOR_CANDLES_TOOLTIP = 'Display additional candles with a color reflecting the current trend detected by structure'
string SHOW_INTERNAL = 'Display internal market structure'
string CONFLUENCE_FILTER = 'Filter non significant internal structure breakouts'
string SHOW_SWING = 'Display swing market Structure'
string SHOW_SWING_POINTS = 'Display swing point as labels on the chart'
string SHOW_SWHL_POINTS = 'Highlight most recent strong and weak high/low points on the chart'
string INTERNAL_OB = 'Display internal order blocks on the chart Number of internal order blocks to display on the chart'
string SWING_OB = 'Display swing order blocks on the chart Number of internal swing blocks to display on the chart'
string FILTER_OB = 'Method used to filter out volatile order blocks It is recommended to use the cumulative mean range method when a low amount of data is available'
string SHOW_EQHL = 'Display equal highs and equal lows on the chart'
string EQHL_BARS = 'Number of bars used to confirm equal highs and equal lows'
string EQHL_THRESHOLD = 'Sensitivity threshold in a range (0, 1) used for the detection of equal highs & lows Lower values will return fewer but more pertinent results'
string SHOW_FVG = 'Display fair values gaps on the chart'
string AUTO_FVG = 'Filter out non significant fair value gaps'
string FVG_TF = 'Fair value gaps timeframe'
string EXTEND_FVG = 'Determine how many bars to extend the Fair Value Gap boxes on chart'
string PED_ZONES = 'Display premium, discount, and equilibrium zones on chart'
//-----------------------------------------------------------------------------{
//Settings
//-----------------------------------------------------------------------------{
//General
//----------------------------------------{
mode = input.string('Historical'
, options =
, group = 'Smart Money Concepts'
, tooltip = MODE_TOOLTIP)
style = input.string('Colored'
, options =
, group = 'Smart Money Concepts'
, tooltip = STYLE_TOOLTIP)
show_trend = input(false, 'Color Candles'
, group = 'Smart Money Concepts'
, tooltip = COLOR_CANDLES_TOOLTIP)
//----------------------------------------}
//Internal Structure
//----------------------------------------{
show_internals = input(false, 'Show Internal Structure'
, group = 'Real Time Internal Structure'
, tooltip = SHOW_INTERNAL)
show_ibull = input.string('All', 'Bullish Structure'
, options =
, inline = 'ibull'
, group = 'Real Time Internal Structure')
swing_ibull_css = input(#089981, ''
, inline = 'ibull'
, group = 'Real Time Internal Structure')
//Bear Structure
show_ibear = input.string('All', 'Bearish Structure'
, options =
, inline = 'ibear'
, group = 'Real Time Internal Structure')
swing_ibear_css = input(#f23645, ''
, inline = 'ibear'
, group = 'Real Time Internal Structure')
ifilter_confluence = input(false, 'Confluence Filter'
, group = 'Real Time Internal Structure'
, tooltip = CONFLUENCE_FILTER)
internal_structure_size = input.string('Tiny', 'Internal Label Size'
, options =
, group = 'Real Time Internal Structure')
//----------------------------------------}
//Swing Structure
//----------------------------------------{
show_Structure = input(true, 'Show Swing Structure'
, group = 'Real Time Swing Structure'
, tooltip = SHOW_SWING)
//Bull Structure
show_bull = input.string('All', 'Bullish Structure'
, options =
, inline = 'bull'
, group = 'Real Time Swing Structure')
swing_bull_css = input(color.rgb(0, 0, 0), ''
, inline = 'bull'
, group = 'Real Time Swing Structure')
//Bear Structure
show_bear = input.string('All', 'Bearish Structure'
, options =
, inline = 'bear'
, group = 'Real Time Swing Structure')
swing_bear_css = input(#000000, ''
, inline = 'bear'
, group = 'Real Time Swing Structure')
swing_structure_size = input.string('Small', 'Swing Label Size'
, options =
, group = 'Real Time Swing Structure')
//Swings
show_swings = input(false, 'Show Swings Points'
, inline = 'swings'
, group = 'Real Time Swing Structure'
, tooltip = SHOW_SWING_POINTS)
length = input.int(50, ''
, minval = 10
, inline = 'swings'
, group = 'Real Time Swing Structure')
show_hl_swings = input(true, 'Show Strong/Weak High/Low'
, group = 'Real Time Swing Structure'
, tooltip = SHOW_SWHL_POINTS)
//----------------------------------------}
//Order Blocks
//----------------------------------------{
show_iob = input(false, 'Internal Order Blocks'
, inline = 'iob'
, group = 'Order Blocks'
, tooltip = INTERNAL_OB)
iob_showlast = input.int(5, ''
, minval = 1
, inline = 'iob'
, group = 'Order Blocks')
show_ob = input(true, 'Swing Order Blocks'
, inline = 'ob'
, group = 'Order Blocks'
, tooltip = SWING_OB)
ob_showlast = input.int(5, ''
, minval = 1
, inline = 'ob'
, group = 'Order Blocks')
ob_filter = input.string('Atr', 'Order Block Filter'
, options =
, group = 'Order Blocks'
, tooltip = FILTER_OB)
ibull_ob_css = input.color(#ffdd0033, 'Internal Bullish OB'
, group = 'Order Blocks')
ibear_ob_css = input.color(#ffdd0033, 'Internal Bearish OB'
, group = 'Order Blocks')
bull_ob_css = input.color(color.rgb(255, 255, 255, 80), 'Bullish OB'
, group = 'Order Blocks')
bear_ob_css = input.color(color.rgb(255, 255, 255, 80), 'Bearish OB'
, group = 'Order Blocks')
//----------------------------------------}
//EQH/EQL
//----------------------------------------{
show_eq = input(false, 'Equal High/Low'
, group = 'EQH/EQL'
, tooltip = SHOW_EQHL)
eq_len = input.int(3, 'Bars Confirmation'
, minval = 1
, group = 'EQH/EQL'
, tooltip = EQHL_BARS)
eq_threshold = input.float(0.1, 'Threshold'
, minval = 0
, maxval = 0.5
, step = 0.1
, group = 'EQH/EQL'
, tooltip = EQHL_THRESHOLD)
eq_size = input.string('Tiny', 'Label Size'
, options =
, group = 'EQH/EQL')
//----------------------------------------}
//Fair Value Gaps
//----------------------------------------{
show_fvg = input(true, 'Fair Value Gaps'
, group = 'Fair Value Gaps'
, tooltip = SHOW_FVG)
fvg_auto = input(true, "Auto Threshold"
, group = 'Fair Value Gaps'
, tooltip = AUTO_FVG)
fvg_tf = input.timeframe('', "Timeframe"
, group = 'Fair Value Gaps'
, tooltip = FVG_TF)
bull_fvg_css = input.color(#ddff006f, 'Bullish FVG'
, group = 'Fair Value Gaps')
bear_fvg_css = input.color(#f2ff0060, 'Bearish FVG'
, group = 'Fair Value Gaps')
fvg_extend = input.int(10, "Extend FVG"
, minval = 0
, group = 'Fair Value Gaps'
, tooltip = EXTEND_FVG)
//----------------------------------------}
//Previous day/week high/low
//----------------------------------------{
//Daily
show_pdhl = input(false, 'Daily'
, inline = 'daily'
, group = 'Highs & Lows MTF')
pdhl_style = input.string('⎯⎯⎯', ''
, options =
, inline = 'daily'
, group = 'Highs & Lows MTF')
pdhl_css = input(#2157f3, ''
, inline = 'daily'
, group = 'Highs & Lows MTF')
//Weekly
show_pwhl = input(false, 'Weekly'
, inline = 'weekly'
, group = 'Highs & Lows MTF')
pwhl_style = input.string('⎯⎯⎯', ''
, options =
, inline = 'weekly'
, group = 'Highs & Lows MTF')
pwhl_css = input(#2157f3, ''
, inline = 'weekly'
, group = 'Highs & Lows MTF')
//Monthly
show_pmhl = input(false, 'Monthly'
, inline = 'monthly'
, group = 'Highs & Lows MTF')
pmhl_style = input.string('⎯⎯⎯', ''
, options =
, inline = 'monthly'
, group = 'Highs & Lows MTF')
pmhl_css = input(#2157f3, ''
, inline = 'monthly'
, group = 'Highs & Lows MTF')
//----------------------------------------}
//Premium/Discount zones
//----------------------------------------{
show_sd = input(false, 'Premium/Discount Zones'
, group = 'Premium & Discount Zones'
, tooltip = PED_ZONES)
premium_css = input.color(#f23645, 'Premium Zone'
, group = 'Premium & Discount Zones')
eq_css = input.color(#b2b5be, 'Equilibrium Zone'
, group = 'Premium & Discount Zones')
discount_css = input.color(#089981, 'Discount Zone'
, group = 'Premium & Discount Zones')
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
n = bar_index
atr = ta.atr(200)
cmean_range = ta.cum(high - low) / n
//HL Output function
hl() =>
//Get ohlc values function
get_ohlc()=> [close , open , high, low, high , low ]
//Display Structure function
display_Structure(x, y, txt, css, dashed, down, lbl_size)=>
structure_line = line.new(x, y, n, y
, color = css
, style = dashed ? line.style_dashed : line.style_solid)
structure_lbl = label.new(int(math.avg(x, n)), y, txt
, color = TRANSP_CSS
, textcolor = css
, style = down ? label.style_label_down : label.style_label_up
, size = lbl_size)
if mode == 'Present'
line.delete(structure_line )
label.delete(structure_lbl )
//Swings detection/measurements
swings(len)=>
var os = 0
upper = ta.highest(len)
lower = ta.lowest(len)
os := high > upper ? 0 : low < lower ? 1 : os
top = os == 0 and os != 0 ? high : 0
btm = os == 1 and os != 1 ? low : 0
//Order block coordinates function
ob_coord(use_max, loc, target_top, target_btm, target_left, target_type)=>
min = 99999999.
max = 0.
idx = 1
ob_threshold = ob_filter == 'Atr' ? atr : cmean_range
//Search for highest/lowest high within the structure interval and get range
if use_max
for i = 1 to (n - loc)-1
if (high - low ) < ob_threshold * 2
max := math.max(high , max)
min := max == high ? low : min
idx := max == high ? i : idx
else
for i = 1 to (n - loc)-1
if (high - low ) < ob_threshold * 2
min := math.min(low , min)
max := min == low ? high : max
idx := min == low ? i : idx
array.unshift(target_top, max)
array.unshift(target_btm, min)
array.unshift(target_left, time )
array.unshift(target_type, use_max ? -1 : 1)
//Set order blocks
display_ob(boxes, target_top, target_btm, target_left, target_type, show_last, swing, size)=>
for i = 0 to math.min(show_last-1, size-1)
get_box = array.get(boxes, i)
box.set_lefttop(get_box, array.get(target_left, i), array.get(target_top, i))
box.set_rightbottom(get_box, array.get(target_left, i), array.get(target_btm, i))
box.set_extend(get_box, extend.right)
color css = na
if swing
if style == 'Monochrome'
css := array.get(target_type, i) == 1 ? color.new(#b2b5be, 80) : color.new(#5d606b, 80)
border_css = array.get(target_type, i) == 1 ? #b2b5be : #5d606b
box.set_border_color(get_box, border_css)
else
css := array.get(target_type, i) == 1 ? bull_ob_css : bear_ob_css
box.set_border_color(get_box, css)
box.set_bgcolor(get_box, css)
else
if style == 'Monochrome'
css := array.get(target_type, i) == 1 ? color.new(#b2b5be, 80) : color.new(#5d606b, 80)
else
css := array.get(target_type, i) == 1 ? ibull_ob_css : ibear_ob_css
box.set_border_color(get_box, css)
box.set_bgcolor(get_box, css)
//Line Style function
get_line_style(style) =>
out = switch style
'⎯⎯⎯' => line.style_solid
'----' => line.style_dashed
'····' => line.style_dotted
//Set line/labels function for previous high/lows
phl(h, l, tf, css)=>
var line high_line = line.new(na,na,na,na
, xloc = xloc.bar_time
, color = css
, style = get_line_style(pdhl_style))
var label high_lbl = label.new(na,na
, xloc = xloc.bar_time
, text = str.format('P{0}H', tf)
, color = TRANSP_CSS
, textcolor = css
, size = size.small
, style = label.style_label_left)
var line low_line = line.new(na,na,na,na
, xloc = xloc.bar_time
, color = css
, style = get_line_style(pdhl_style))
var label low_lbl = label.new(na,na
, xloc = xloc.bar_time
, text = str.format('P{0}L', tf)
, color = TRANSP_CSS
, textcolor = css
, size = size.small
, style = label.style_label_left)
hy = ta.valuewhen(h != h , h, 1)
hx = ta.valuewhen(h == high, time, 1)
ly = ta.valuewhen(l != l , l, 1)
lx = ta.valuewhen(l == low, time, 1)
if barstate.islast
ext = time + (time - time )*20
//High
line.set_xy1(high_line, hx, hy)
line.set_xy2(high_line, ext, hy)
label.set_xy(high_lbl, ext, hy)
//Low
line.set_xy1(low_line, lx, ly)
line.set_xy2(low_line, ext, ly)
label.set_xy(low_lbl, ext, ly)
//-----------------------------------------------------------------------------}
//Global variables
//-----------------------------------------------------------------------------{
var trend = 0, var itrend = 0
var top_y = 0., var top_x = 0
var btm_y = 0., var btm_x = 0
var itop_y = 0., var itop_x = 0
var ibtm_y = 0., var ibtm_x = 0
var trail_up = high, var trail_dn = low
var trail_up_x = 0, var trail_dn_x = 0
var top_cross = true, var btm_cross = true
var itop_cross = true, var ibtm_cross = true
var txt_top = '', var txt_btm = ''
//Alerts
bull_choch_alert = false
bull_bos_alert = false
bear_choch_alert = false
bear_bos_alert = false
bull_ichoch_alert = false
bull_ibos_alert = false
bear_ichoch_alert = false
bear_ibos_alert = false
bull_iob_break = false
bear_iob_break = false
bull_ob_break = false
bear_ob_break = false
eqh_alert = false
eql_alert = false
//Structure colors
var bull_css = style == 'Monochrome' ? #b2b5be
: swing_bull_css
var bear_css = style == 'Monochrome' ? #b2b5be
: swing_bear_css
var ibull_css = style == 'Monochrome' ? #b2b5be
: swing_ibull_css
var ibear_css = style == 'Monochrome' ? #b2b5be
: swing_ibear_css
//Labels size
var internal_structure_lbl_size = internal_structure_size == 'Tiny'
? size.tiny
: internal_structure_size == 'Small'
? size.small
: size.normal
var swing_structure_lbl_size = swing_structure_size == 'Tiny'
? size.tiny
: swing_structure_size == 'Small'
? size.small
: size.normal
var eqhl_lbl_size = eq_size == 'Tiny'
? size.tiny
: eq_size == 'Small'
? size.small
: size.normal
//Swings
= swings(length)
= swings(5)
//-----------------------------------------------------------------------------}
//Pivot High
//-----------------------------------------------------------------------------{
var line extend_top = na
var label extend_top_lbl = label.new(na, na
, color = TRANSP_CSS
, textcolor = bear_css
, style = label.style_label_down
, size = size.tiny)
if top
top_cross := true
txt_top := top > top_y ? 'HH' : 'LH'
if show_swings
top_lbl = label.new(n-length, top, txt_top
, color = TRANSP_CSS
, textcolor = bear_css
, style = label.style_label_down
, size = swing_structure_lbl_size)
if mode == 'Present'
label.delete(top_lbl )
//Extend recent top to last bar
line.delete(extend_top )
extend_top := line.new(n-length, top, n, top
, color = bear_css)
top_y := top
top_x := n - length
trail_up := top
trail_up_x := n - length
if itop
itop_cross := true
itop_y := itop
itop_x := n - 5
//Trailing maximum
trail_up := math.max(high, trail_up)
trail_up_x := trail_up == high ? n : trail_up_x
//Set top extension label/line
if barstate.islast and show_hl_swings
line.set_xy1(extend_top, trail_up_x, trail_up)
line.set_xy2(extend_top, n + 20, trail_up)
label.set_x(extend_top_lbl, n + 20)
label.set_y(extend_top_lbl, trail_up)
label.set_text(extend_top_lbl, trend < 0 ? 'Strong High' : 'Weak High')
//-----------------------------------------------------------------------------}
//Pivot Low
//-----------------------------------------------------------------------------{
var line extend_btm = na
var label extend_btm_lbl = label.new(na, na
, color = TRANSP_CSS
, textcolor = bull_css
, style = label.style_label_up
, size = size.tiny)
if btm
btm_cross := true
txt_btm := btm < btm_y ? 'LL' : 'HL'
if show_swings
btm_lbl = label.new(n - length, btm, txt_btm
, color = TRANSP_CSS
, textcolor = bull_css
, style = label.style_label_up
, size = swing_structure_lbl_size)
if mode == 'Present'
label.delete(btm_lbl )
//Extend recent btm to last bar
line.delete(extend_btm )
extend_btm := line.new(n - length, btm, n, btm
, color = bull_css)
btm_y := btm
btm_x := n-length
trail_dn := btm
trail_dn_x := n-length
if ibtm
ibtm_cross := true
ibtm_y := ibtm
ibtm_x := n - 5
//Trailing minimum
trail_dn := math.min(low, trail_dn)
trail_dn_x := trail_dn == low ? n : trail_dn_x
//Set btm extension label/line
if barstate.islast and show_hl_swings
line.set_xy1(extend_btm, trail_dn_x, trail_dn)
line.set_xy2(extend_btm, n + 20, trail_dn)
label.set_x(extend_btm_lbl, n + 20)
label.set_y(extend_btm_lbl, trail_dn)
label.set_text(extend_btm_lbl, trend > 0 ? 'Strong Low' : 'Weak Low')
//-----------------------------------------------------------------------------}
//Order Blocks Arrays
//-----------------------------------------------------------------------------{
var iob_top = array.new_float(0)
var iob_btm = array.new_float(0)
var iob_left = array.new_int(0)
var iob_type = array.new_int(0)
var ob_top = array.new_float(0)
var ob_btm = array.new_float(0)
var ob_left = array.new_int(0)
var ob_type = array.new_int(0)
//-----------------------------------------------------------------------------}
//Pivot High BOS/CHoCH
//-----------------------------------------------------------------------------{
//Filtering
var bull_concordant = true
if ifilter_confluence
bull_concordant := high - math.max(close, open) > math.min(close, open - low)
//Detect internal bullish Structure
if ta.crossover(close, itop_y) and itop_cross and top_y != itop_y and bull_concordant
bool choch = na
if itrend < 0
choch := true
bull_ichoch_alert := true
else
bull_ibos_alert := true
txt = choch ? 'CHoCH' : 'BOS'
if show_internals
if show_ibull == 'All' or (show_ibull == 'BOS' and not choch) or (show_ibull == 'CHoCH' and choch)
display_Structure(itop_x, itop_y, txt, ibull_css, true, true, internal_structure_lbl_size)
itop_cross := false
itrend := 1
//Internal Order Block
if show_iob
ob_coord(false, itop_x, iob_top, iob_btm, iob_left, iob_type)
//Detect bullish Structure
if ta.crossover(close, top_y) and top_cross
bool choch = na
if trend < 0
choch := true
bull_choch_alert := true
else
bull_bos_alert := true
txt = choch ? 'CHoCH' : 'BOS'
if show_Structure
if show_bull == 'All' or (show_bull == 'BOS' and not choch) or (show_bull == 'CHoCH' and choch)
display_Structure(top_x, top_y, txt, bull_css, false, true, swing_structure_lbl_size)
//Order Block
if show_ob
ob_coord(false, top_x, ob_top, ob_btm, ob_left, ob_type)
top_cross := false
trend := 1
//-----------------------------------------------------------------------------}
//Pivot Low BOS/CHoCH
//-----------------------------------------------------------------------------{
var bear_concordant = true
if ifilter_confluence
bear_concordant := high - math.max(close, open) < math.min(close, open - low)
//Detect internal bearish Structure
if ta.crossunder(close, ibtm_y) and ibtm_cross and btm_y != ibtm_y and bear_concordant
bool choch = false
if itrend > 0
choch := true
bear_ichoch_alert := true
else
bear_ibos_alert := true
txt = choch ? 'CHoCH' : 'BOS'
if show_internals
if show_ibear == 'All' or (show_ibear == 'BOS' and not choch) or (show_ibear == 'CHoCH' and choch)
display_Structure(ibtm_x, ibtm_y, txt, ibear_css, true, false, internal_structure_lbl_size)
ibtm_cross := false
itrend := -1
//Internal Order Block
if show_iob
ob_coord(true, ibtm_x, iob_top, iob_btm, iob_left, iob_type)
//Detect bearish Structure
if ta.crossunder(close, btm_y) and btm_cross
bool choch = na
if trend > 0
choch := true
bear_choch_alert := true
else
bear_bos_alert := true
txt = choch ? 'CHoCH' : 'BOS'
if show_Structure
if show_bear == 'All' or (show_bear == 'BOS' and not choch) or (show_bear == 'CHoCH' and choch)
display_Structure(btm_x, btm_y, txt, bear_css, false, false, swing_structure_lbl_size)
//Order Block
if show_ob
ob_coord(true, btm_x, ob_top, ob_btm, ob_left, ob_type)
btm_cross := false
trend := -1
//-----------------------------------------------------------------------------}
//Order Blocks
//-----------------------------------------------------------------------------{
//Set order blocks
var iob_boxes = array.new_box(0)
var ob_boxes = array.new_box(0)
//Delete internal order blocks box coordinates if top/bottom is broken
for element in iob_type
index = array.indexof(iob_type, element)
if close < array.get(iob_btm, index) and element == 1
array.remove(iob_top, index)
array.remove(iob_btm, index)
array.remove(iob_left, index)
array.remove(iob_type, index)
bull_iob_break := true
else if close > array.get(iob_top, index) and element == -1
array.remove(iob_top, index)
array.remove(iob_btm, index)
array.remove(iob_left, index)
array.remove(iob_type, index)
bear_iob_break := true
//Delete internal order blocks box coordinates if top/bottom is broken
for element in ob_type
index = array.indexof(ob_type, element)
if close < array.get(ob_btm, index) and element == 1
array.remove(ob_top, index)
array.remove(ob_btm, index)
array.remove(ob_left, index)
array.remove(ob_type, index)
bull_ob_break := true
else if close > array.get(ob_top, index) and element == -1
array.remove(ob_top, index)
array.remove(ob_btm, index)
array.remove(ob_left, index)
array.remove(ob_type, index)
bear_ob_break := true
iob_size = array.size(iob_type)
ob_size = array.size(ob_type)
if barstate.isfirst
if show_iob
for i = 0 to iob_showlast-1
array.push(iob_boxes, box.new(na,na,na,na, xloc = xloc.bar_time))
if show_ob
for i = 0 to ob_showlast-1
array.push(ob_boxes, box.new(na,na,na,na, xloc = xloc.bar_time))
if iob_size > 0
if barstate.islast
display_ob(iob_boxes, iob_top, iob_btm, iob_left, iob_type, iob_showlast, false, iob_size)
if ob_size > 0
if barstate.islast
display_ob(ob_boxes, ob_top, ob_btm, ob_left, ob_type, ob_showlast, true, ob_size)
//-----------------------------------------------------------------------------}
//EQH/EQL
//-----------------------------------------------------------------------------{
var eq_prev_top = 0.
var eq_top_x = 0
var eq_prev_btm = 0.
var eq_btm_x = 0
if show_eq
eq_top = ta.pivothigh(eq_len, eq_len)
eq_btm = ta.pivotlow(eq_len, eq_len)
if eq_top
max = math.max(eq_top, eq_prev_top)
min = math.min(eq_top, eq_prev_top)
if max < min + atr * eq_threshold
eqh_line = line.new(eq_top_x, eq_prev_top, n-eq_len, eq_top
, color = bear_css
, style = line.style_dotted)
eqh_lbl = label.new(int(math.avg(n-eq_len, eq_top_x)), eq_top, 'EQH'
, color = #00000000
, textcolor = bear_css
, style = label.style_label_down
, size = eqhl_lbl_size)
if mode == 'Present'
line.delete(eqh_line )
label.delete(eqh_lbl )
eqh_alert := true
eq_prev_top := eq_top
eq_top_x := n-eq_len
if eq_btm
max = math.max(eq_btm, eq_prev_btm)
min = math.min(eq_btm, eq_prev_btm)
if min > max - atr * eq_threshold
eql_line = line.new(eq_btm_x, eq_prev_btm, n-eq_len, eq_btm
, color = bull_css
, style = line.style_dotted)
eql_lbl = label.new(int(math.avg(n-eq_len, eq_btm_x)), eq_btm, 'EQL'
, color = #00000000
, textcolor = bull_css
, style = label.style_label_up
, size = eqhl_lbl_size)
eql_alert := true
if mode == 'Present'
line.delete(eql_line )
label.delete(eql_lbl )
eq_prev_btm := eq_btm
eq_btm_x := n-eq_len
//-----------------------------------------------------------------------------}
//Fair Value Gaps
//-----------------------------------------------------------------------------{
var bullish_fvg_max = array.new_box(0)
var bullish_fvg_min = array.new_box(0)
var bearish_fvg_max = array.new_box(0)
var bearish_fvg_min = array.new_box(0)
float bullish_fvg_avg = na
float bearish_fvg_avg = na
bullish_fvg_cnd = false
bearish_fvg_cnd = false
=
request.security(syminfo.tickerid, fvg_tf, get_ohlc())
if show_fvg
delta_per = (src_c1 - src_o1) / src_o1 * 100
change_tf = timeframe.change(fvg_tf)
threshold = fvg_auto ? ta.cum(math.abs(change_tf ? delta_per : 0)) / n * 2
: 0
//FVG conditions
bullish_fvg_cnd := src_l > src_h2
and src_c1 > src_h2
and delta_per > threshold
and change_tf
bearish_fvg_cnd := src_h < src_l2
and src_c1 < src_l2
and -delta_per > threshold
and change_tf
//FVG Areas
if bullish_fvg_cnd
array.unshift(bullish_fvg_max, box.new(n-1, src_l, n + fvg_extend, math.avg(src_l, src_h2)
, border_color = bull_fvg_css
, bgcolor = bull_fvg_css))
array.unshift(bullish_fvg_min, box.new(n-1, math.avg(src_l, src_h2), n + fvg_extend, src_h2
, border_color = bull_fvg_css
, bgcolor = bull_fvg_css))
if bearish_fvg_cnd
array.unshift(bearish_fvg_max, box.new(n-1, src_h, n + fvg_extend, math.avg(src_h, src_l2)
, border_color = bear_fvg_css
, bgcolor = bear_fvg_css))
array.unshift(bearish_fvg_min, box.new(n-1, math.avg(src_h, src_l2), n + fvg_extend, src_l2
, border_color = bear_fvg_css
, bgcolor = bear_fvg_css))
for bx in bullish_fvg_min
if low < box.get_bottom(bx)
box.delete(bx)
box.delete(array.get(bullish_fvg_max, array.indexof(bullish_fvg_min, bx)))
for bx in bearish_fvg_max
if high > box.get_top(bx)
box.delete(bx)
box.delete(array.get(bearish_fvg_min, array.indexof(bearish_fvg_max, bx)))
//-----------------------------------------------------------------------------}
//Previous day/week high/lows
//-----------------------------------------------------------------------------{
//Daily high/low
= request.security(syminfo.tickerid, 'D', hl()
, lookahead = barmerge.lookahead_on)
//Weekly high/low
= request.security(syminfo.tickerid, 'W', hl()
, lookahead = barmerge.lookahead_on)
//Monthly high/low
= request.security(syminfo.tickerid, 'M', hl()
, lookahead = barmerge.lookahead_on)
//Display Daily
if show_pdhl
phl(pdh, pdl, 'D', pdhl_css)
//Display Weekly
if show_pwhl
phl(pwh, pwl, 'W', pwhl_css)
//Display Monthly
if show_pmhl
phl(pmh, pml, 'M', pmhl_css)
//-----------------------------------------------------------------------------}
//Premium/Discount/Equilibrium zones
//-----------------------------------------------------------------------------{
var premium = box.new(na, na, na, na
, bgcolor = color.new(premium_css, 80)
, border_color = na)
var premium_lbl = label.new(na, na
, text = 'Premium'
, color = TRANSP_CSS
, textcolor = premium_css
, style = label.style_label_down
, size = size.small)
var eq = box.new(na, na, na, na
, bgcolor = color.rgb(120, 123, 134, 80)
, border_color = na)
var eq_lbl = label.new(na, na
, text = 'Equilibrium'
, color = TRANSP_CSS
, textcolor = eq_css
, style = label.style_label_left
, size = size.small)
var discount = box.new(na, na, na, na
, bgcolor = color.new(discount_css, 80)
, border_color = na)
var discount_lbl = label.new(na, na
, text = 'Discount'
, color = TRANSP_CSS
, textcolor = discount_css
, style = label.style_label_up
, size = size.small)
//Show Premium/Discount Areas
if barstate.islast and show_sd
avg = math.avg(trail_up, trail_dn)
box.set_lefttop(premium, math.max(top_x, btm_x), trail_up)
box.set_rightbottom(premium, n, .95 * trail_up + .05 * trail_dn)
label.set_xy(premium_lbl, int(math.avg(math.max(top_x, btm_x), n)), trail_up)
box.set_lefttop(eq, math.max(top_x, btm_x), .525 * trail_up + .475*trail_dn)
box.set_rightbottom(eq, n, .525 * trail_dn + .475 * trail_up)
label.set_xy(eq_lbl, n, avg)
box.set_lefttop(discount, math.max(top_x, btm_x), .95 * trail_dn + .05 * trail_up)
box.set_rightbottom(discount, n, trail_dn)
label.set_xy(discount_lbl, int(math.avg(math.max(top_x, btm_x), n)), trail_dn)
//-----------------------------------------------------------------------------}
//Trend
//-----------------------------------------------------------------------------{
var color trend_css = na
if show_trend
if style == 'Colored'
trend_css := itrend == 1 ? bull_css : bear_css
else if style == 'Monochrome'
trend_css := itrend == 1 ? #b2b5be : #5d606b
plotcandle(open, high, low, close
, color = trend_css
, wickcolor = trend_css
, bordercolor = trend_css
, editable = false)
//-----------------------------------------------------------------------------}
//Alerts
//-----------------------------------------------------------------------------{
//Internal Structure
alertcondition(bull_ibos_alert, 'Internal Bullish BOS', 'Internal Bullish BOS formed')
alertcondition(bull_ichoch_alert, 'Internal Bullish CHoCH', 'Internal Bullish CHoCH formed')
alertcondition(bear_ibos_alert, 'Internal Bearish BOS', 'Internal Bearish BOS formed')
alertcondition(bear_ichoch_alert, 'Internal Bearish CHoCH', 'Internal Bearish CHoCH formed')
//Swing Structure
alertcondition(bull_bos_alert, 'Bullish BOS', 'Internal Bullish BOS formed')
alertcondition(bull_choch_alert, 'Bullish CHoCH', 'Internal Bullish CHoCH formed')
alertcondition(bear_bos_alert, 'Bearish BOS', 'Bearish BOS formed')
alertcondition(bear_choch_alert, 'Bearish CHoCH', 'Bearish CHoCH formed')
//order Blocks
alertcondition(bull_iob_break, 'Bullish Internal OB Breakout', 'Price broke bullish internal OB')
alertcondition(bear_iob_break, 'Bearish Internal OB Breakout', 'Price broke bearish internal OB')
alertcondition(bull_ob_break, 'Bullish Swing OB Breakout', 'Price broke bullish swing OB')
alertcondition(bear_ob_break, 'Bearish Swing OB Breakout', 'Price broke bearish swing OB')
//EQH/EQL
alertcondition(eqh_alert, 'Equal Highs', 'Equal highs detected')
alertcondition(eql_alert, 'Equal Lows', 'Equal lows detected')
//FVG
alertcondition(bullish_fvg_cnd, 'Bullish FVG', 'Bullish FVG formed')
alertcondition(bearish_fvg_cnd, 'Bearish FVG', 'Bearish FVG formed')
//-----------------------------------------------------------------------------}
// ==========================================================================================
// === Dashboard with Telegram Link ===
var table myTable = table.new(position.top_center, 1, 1, border_width=1, frame_color=color.black, bgcolor=color.white)
// Add Telegram Message to Dashboard
table.cell(myTable, 0, 0, "VitaLegacy Team", bgcolor=color.blue, text_color=color.white, text_size=size.normal)
VitaLegacy Top// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
// Join our channel for more free tools: t.me
//@version=5
//This source code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
indicator('VitaLegacy Top', overlay=true, max_boxes_count=500, max_lines_count=500)
plotOB = input.bool(defval=true, title='Plot OB', group='Order Blocks')
obBullColor = input.color(defval=color.new(color.green, 90), title='Bullish OB Color', inline='Set Custom Color', group='Order Blocks')
obBearColor = input.color(defval=color.new(color.red, 90), title='Bearish OB Color', inline='Set Custom Color', group='Order Blocks')
obBoxBorder = input.string(defval=line.style_solid, title='OB Box Border Style', options= , group='Order Blocks', tooltip='To disable border, set Border Width below to 0')
obBorderTransparency = input.int(defval=80, title='OB Border Box Transparency', minval=0, maxval=100, group='Order Blocks')
obMaxBoxSet = input.int(defval=10, title='Maximum OB Box Displayed', minval=1, maxval=100, group='Order Blocks', tooltip='Minimum = 1, Maximum = 100')
filterMitOB = input.bool(defval=false, title='Custom Color Mitigated OB', group='Order Blocks')
mitOBColor = input.color(defval=color.new(color.gray, 90), title='Mitigated OB Color', group='Order Blocks', inline='Set Custom Color Mit OB', tooltip='Set Transparency to 0 to make mitigated OB disappear')
plotFVG = input.bool(defval=true, title='Plot FVG', group='Fair Value Gaps', inline='FVG sets')
plotStructureBreakingFVG = input.bool(defval=true, title='Plot Structure Breaking FVG', group='Fair Value Gaps', inline='FVG sets')
fvgBullColor = input.color(defval=color.new(color.black, 90), title='Bullish FVG Color', inline='Set Custom Color', group='Fair Value Gaps')
fvgBearColor = input.color(defval=color.new(color.black, 90), title='Bearish FVG Color', inline='Set Custom Color', group='Fair Value Gaps')
fvgStructBreakingColor = input.color(defval=color.new(color.blue, 90), title='Structure Breaking FVG Color', inline='Set Custom Color', group='Fair Value Gaps')
fvgBoxBorder = input.string(defval=line.style_solid, title='FVG Box Border Style', options= , group='Fair Value Gaps', tooltip='To disable border, set Border Width below to 0')
fvgBorderTransparency = input.int(defval=80, title='FVG Border Box Transparency', minval=0, maxval=100, group='Fair Value Gaps')
fvgMaxBoxSet = input.int(defval=10, title='Maximum FVG Box Displayed', minval=1, maxval=100, group='Fair Value Gaps', tooltip='Minimum = 1, Maximum = 100')
filterMitFVG = input.bool(defval=false, title='Custom Color Mitigated FVG', group='Fair Value Gaps')
mitFVGColor = input.color(defval=color.new(color.gray, 90), title='Mitigated FVG Color', group='Fair Value Gaps', inline='Set Custom Color Mit FVG', tooltip='Set Transparency to 0 to make mitigated FVG disappear')
plotRJB = input.bool(defval=false, title='Plot RJB', group='Rejection Blocks', inline='RJB sets')
rjbBullColor = input.color(defval=color.new(color.green, 90), title='Bullish RJB Color', inline='Set Custom Color', group='Rejection Blocks')
rjbBearColor = input.color(defval=color.new(color.red, 90), title='Bearish RJB Color', inline='Set Custom Color', group='Rejection Blocks')
rjbBoxBorder = input.string(defval=line.style_solid, title='RJB Box Border Style', options= , group='Rejection Blocks', tooltip='To disable border, set Border Width below to 0')
rjbBorderTransparency = input.int(defval=80, title='RJB Border Box Transparency', minval=0, maxval=100, group='Rejection Blocks')
rjbMaxBoxSet = input.int(defval=10, title='Maximum RJB Box Displayed', minval=1, maxval=100, group='Rejection Blocks', tooltip='Minimum = 1, Maximum = 100')
filterMitRJB = input.bool(defval=false, title='Custom Color Mitigated RJB', group='Rejection Blocks')
mitRJBColor = input.color(defval=color.new(color.gray, 90), title='Mitigated RJB Color', group='Rejection Blocks', inline='Set Custom Color Mit RJB', tooltip='Set to 100 to make mitigated RJB disappear')
plotPVT = input.bool(defval=true, title='Plot Pivots', group='Pivots')
pivotLookup = input.int(defval=1, minval=1, maxval=5,title='Pivot Lookup', group='Pivots', tooltip='Minimum = 1, Maximum = 5')
pvtTopColor = input.color(defval=color.new(color.silver, 0), title='Pivot Top Color', group='Pivots', inline='PVT Color')
pvtBottomColor = input.color(defval=color.new(color.silver, 0), title='Pivot Bottom Color', group='Pivots', inline='PVT Color')
plotBOS = input.bool(defval=false, title='Plot BoS', group='Crossovers', inline='BOS sets')
useHighLowForBullishBoS = input.bool(defval=false, title='Use High/Low for Bullish BoS (for Bearish setup)', group='Crossovers')
useHighLowForBearishBoS = input.bool(defval=false, title='Use High/Low for Bearish BoS (for Bullish setup)', group='Crossovers')
bosBoxFlag = input.bool(title='BoS Box Length Manually', defval=false, group='Crossovers', tooltip='If activated the BoS Boxes will not extend unitl crossed by price. Instead will extend by the amount of bars choosen in the "Set BoS Box Length Manually" option')
bosBoxLength = input.int(title='BoS Box Length Manually', defval=3, minval=1, maxval=5, group='Crossovers', inline='BoS Boxes', tooltip='If "Set BoS Box Length Manually" is marked, choose by how many bars. Minimum = 1, Maximum = 5')
bosBullColor = input.color(defval=color.new(color.green, 90), title='Bullish BoS Color', inline='Set Custom Color', group='Crossovers')
bosBearColor = input.color(defval=color.new(color.red, 90), title='Bearish BoS Color', inline='Set Custom Color', group='Crossovers')
bosBoxBorder = input.string(defval=line.style_solid, title='BoS Box Border Style', options= , group='Crossovers', tooltip='To disable border, set Border Width below to 0')
bosBorderTransparency = input.int(defval=80, title='BoS Border Box Transparency', minval=0, maxval=100, group='Crossovers')
bosMaxBoxSet = input.int(defval=10, title='Maximum BoS Box Displayed', minval=1, maxval=100, group='Crossovers', tooltip='Minimum = 1, Maximum = 100')
plotHVB = input.bool(defval=true, title='Plot HVB', group='High Volume Bar', tooltip='A candle where the average volume is higher than last few bars.')
hvbBullColor = input.color(defval=color.green, title='Bullish HVB Color', inline='Set Custom Color', group='High Volume Bar')
hvbBearColor = input.color(defval=color.red, title='Bearish HVB Color', inline='Set Custom Color', group='High Volume Bar')
hvbEMAPeriod = input.int(defval=12, minval=1, title='Volume EMA Period', group='High Volume Bar')
hvbMultiplier = input.float(defval=1.5, title='Volume Multiplier', minval=1, maxval=100, group='High Volume Bar')
plotPPDD = input.bool(defval=true, title="Plot PPDD OB's", group='Qualitative indicators', tooltip='Premium Premium Discount Discount (PPDD) is an OB formed after liquidity sweep. It will show up by default as a triangle (Bull ▲ / Bear ▼). Also PPDD1 (by deafult maked with a x-cross ⨯) which is a weak OB formed after liquidity sweep, that fails to completely engulf the high/low, but closes beyond the trapped candles open price.')
ppddBullColor = input.color(defval=color.new(color.green, 0), title="Bullish PPDD OB's Color", group='Qualitative indicators', inline='PPDD Color')
ppddBearColor = input.color(defval=color.new(color.red, 0), title="Bearish PPDD OB's Color", group='Qualitative indicators', inline='PPDD Color')
plotOBFVG = input.bool(defval=true, title='Plot Stacked OB+FVG', group='Qualitative indicators', tooltip='Marks the candle (default with a diamond ◆) when an OB & FVG are stacked, showing momentum')
obfvgBullColor = input.color(defval=color.new(color.green, 0), title='Bullish Stacked OB+FVG Color', group='Qualitative indicators', inline='OBFVG Color')
obfvgBearColor = input.color(defval=color.new(color.red, 0), title='Bearish Stacked OB+FVG Color', group='Qualitative indicators', inline='OBFVG Color')
plotLabelOB = input.bool(defval=true, title='Plot OB Label', inline='OB label', group='Label Options')
obLabelColor = input.color(defval=color.gray, title='Color', inline='OB label', group='Label Options')
obLabelSize = input.string(defval=size.tiny, title="Size", options= , inline='OB label', group='Label Options')
plotLabelFVG = input.bool(defval=true, title='Plot FVG Label', inline='FVG label', group='Label Options')
fvgLabelColor = input.color(defval=color.gray, title='Color', inline='FVG label', group='Label Options')
fvgLabelSize = input.string(defval=size.tiny, title="Size", options= , inline='FVG label', group='Label Options')
plotLabelRJB = input.bool(defval=true, title='Plot RJB Label', inline='RJB label', group='Label Options')
rjbLabelColor = input.color(defval=color.gray, title='Color', inline='RJB label', group='Label Options')
rjbLabelSize = input.string(defval=size.tiny, title="Size", options= , inline='RJB label', group='Label Options')
plotLabelBOS = input.bool(defval=true, title='Plot BoS Label', inline='BOS label', group='Label Options')
bosLabelColor = input.color(defval=color.gray, title='Color', inline='BOS label', group='Label Options')
bosLabelSize = input.string(defval=size.tiny, title="Size", options= , inline='BOS label', group='Label Options')
//Box Types
var int _ob = 1
var int _fvg = 2
var int _rjb = 3
var int _bos = 4
//Box Labels
var string _obLabel = "OB"
var string _fvgLabel = "FVG"
var string _rjbLabel = "RJB"
var string _bosLabel = "BoS"
var string _plus = "+"
var string _minus = "-"
var string _empty = ""
//Box Arrays
var box _bearBoxesOB = array.new_box()
var box _bullBoxesOB = array.new_box()
var box _bearBoxesFVG = array.new_box()
var box _bullBoxesFVG = array.new_box()
var box _bearBoxesRJB = array.new_box()
var box _bullBoxesRJB = array.new_box()
var box _bearBoxesBOS = array.new_box()
var box _bullBoxesBOS = array.new_box()
//Functions
isUp(index) =>
close > open
isDown(index) =>
close < open
isObUp(index) =>
isDown(index + 1) and isUp(index) and close > high
isObDown(index) =>
isUp(index + 1) and isDown(index) and close < low
isFvgUp(index) =>
(low > high )
isFvgDown(index) =>
(high < low )
//Function to Calculte Box Length
_controlBox(_boxes, _high, _low, _type) =>
if array.size(_boxes) > 0
for i = array.size(_boxes) - 1 to 0 by 1
_box = array.get(_boxes, i)
_boxLow = box.get_bottom(_box)
_boxHigh = box.get_top(_box)
_boxRight = box.get_right(_box)
if bosBoxFlag and _type == _bos
if na or (bar_index + bosBoxLength - 1 == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
box.set_right(_box, bar_index + bosBoxLength - 1)
else if (filterMitOB and _type == _ob) or (filterMitFVG and _type == _fvg) or (filterMitRJB and _type == _rjb)
if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
box.set_right(_box, bar_index + 1)
else
if _type == _ob
box.set_bgcolor(_box, mitOBColor)
box.set_border_color(_box, mitOBColor)
else if _type == _fvg
box.set_bgcolor(_box, mitFVGColor)
box.set_border_color(_box, mitFVGColor)
else if _type == _rjb
box.set_bgcolor(_box, mitRJBColor)
box.set_border_color(_box, mitRJBColor)
else
if na or (bar_index == _boxRight and not((_high > _boxLow and _low < _boxLow) or (_high > _boxHigh and _low < _boxHigh)))
box.set_right(_box, bar_index + 1)
hih = ta.pivothigh(high, pivotLookup, pivotLookup)
lol = ta.pivotlow(low, pivotLookup, pivotLookup)
// Исправленная версия - используем условие, что пивот не равен na
top = ta.valuewhen(not na(hih), high , 0)
bottom = ta.valuewhen(not na(lol), low , 0)
plot(top, offset=-pivotLookup, linewidth=1, color=(top != top ? na : (plotPVT ? pvtTopColor : na)), title="Pivot Top")
plot(bottom, offset=-pivotLookup, linewidth=1, color=(bottom != bottom ? na : (plotPVT ? pvtBottomColor : na)), title="Pivot Bottom")
//////////////////// Order Block //////////////////
//Bullish OB Box Plotting
if isObUp(1) and plotOB
_bullboxOB = box.new(left=bar_index - 2, top=high , right=bar_index, bottom=math.min(low , low ), border_color=color.new(obBullColor, obBorderTransparency), border_style=obBoxBorder, border_width=1, bgcolor=obBullColor,
text=plotLabelOB ? _obLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=obLabelSize, text_color=obLabelColor)
if array.size(_bullBoxesOB) > obMaxBoxSet
box.delete(array.shift(_bullBoxesOB))
array.push(_bullBoxesOB, _bullboxOB)
//Bearish OB Box Plotting
if isObDown(1) and plotOB
_bearboxOB = box.new(left=bar_index - 2, top=math.max(high , high ), right=bar_index, bottom=low , border_color=color.new(obBearColor, obBorderTransparency), border_style=obBoxBorder, border_width=1, bgcolor=obBearColor,
text=plotLabelOB ? _obLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=obLabelSize, text_color=obLabelColor)
if array.size(_bearBoxesOB) > obMaxBoxSet
box.delete(array.shift(_bearBoxesOB))
array.push(_bearBoxesOB, _bearboxOB)
if plotOB
_controlBox(_bearBoxesOB, high, low, _ob)
_controlBox(_bullBoxesOB, high, low, _ob)
//////////////////// Fair Value Gap //////////////////
//Bullish FVG Box Plotting
if isFvgUp(0)
box _bullboxFVG = na
if plotStructureBreakingFVG and (close > top) and (low < top) and (high < top) and (low > top)
_bullboxFVG := box.new(left=bar_index-2, top=low , right=bar_index, bottom=high , bgcolor=fvgStructBreakingColor, border_color=color.new(fvgStructBreakingColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
text=plotLabelFVG ? _fvgLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
else if plotFVG
_bullboxFVG := box.new(left=bar_index-2, top=low , right=bar_index, bottom=high , bgcolor=fvgBullColor, border_color=color.new(fvgBullColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
text=plotLabelFVG ? _fvgLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
if array.size(_bullBoxesFVG) > fvgMaxBoxSet
box.delete(array.shift(_bullBoxesFVG))
array.push(_bullBoxesFVG, _bullboxFVG)
//Bearish FVG Box Plotting
if isFvgDown(0)
box _bearboxFVG = na
if plotStructureBreakingFVG and (close < bottom) and (high > bottom) and (low > bottom) and (high < bottom)
_bearboxFVG := box.new(left=bar_index-2, top=low , right=bar_index, bottom=high , bgcolor=fvgStructBreakingColor, border_color=color.new(fvgStructBreakingColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
text=plotLabelFVG ? _fvgLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
else if plotFVG
_bearboxFVG := box.new(left=bar_index-2, top=low , right=bar_index, bottom=high , bgcolor=fvgBearColor, border_color=color.new(fvgBearColor, fvgBorderTransparency), border_style=fvgBoxBorder, border_width=1,
text=plotLabelFVG ? _fvgLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=fvgLabelSize, text_color=fvgLabelColor)
if array.size(_bearBoxesFVG) > fvgMaxBoxSet
box.delete(array.shift(_bearBoxesFVG))
array.push(_bearBoxesFVG, _bearboxFVG)
if plotFVG or plotStructureBreakingFVG
_controlBox(_bearBoxesFVG, high, low, _fvg)
_controlBox(_bullBoxesFVG, high, low, _fvg)
//////////////////// Rejection Block //////////////////
if plotRJB
isDownRjbObCondition = isObDown(1)
isDownRjb1 = isDownRjbObCondition and (high < (close + 0.2*(high -close ))) // RJB is on trapped's wick and <50% of the wick was covered by signal
isDownRjb2 = isDownRjbObCondition and (high > high ) // RJB is on signal's wick
if isDownRjb1 and plotRJB
_bearboxRJB = box.new(left=bar_index-2, top=high , right=bar_index, bottom=close , bgcolor=rjbBearColor, border_color=color.new(rjbBearColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
text=plotLabelRJB ? _rjbLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
if array.size(_bearBoxesRJB) > rjbMaxBoxSet
box.delete(array.shift(_bearBoxesRJB))
array.push(_bearBoxesRJB, _bearboxRJB)
if isDownRjb2 and plotRJB
_bearboxRJB = box.new(left=bar_index-1, top=high , right=bar_index, bottom=open , bgcolor=rjbBearColor, border_color=color.new(rjbBearColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
text=plotLabelRJB ? _rjbLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
if array.size(_bearBoxesRJB) > rjbMaxBoxSet
box.delete(array.shift(_bearBoxesRJB))
array.push(_bearBoxesRJB, _bearboxRJB)
//Bullish RJB Box Plotting
if plotRJB
isUpRjbObCondition = isObUp(1)
isUpRjb1 = isUpRjbObCondition and (low > (close - 0.2*(close -low ))) // RJB is on trapped's wick and <50% of the wick was covered by signal
isUpRjb2 = isUpRjbObCondition and (low < low ) // RJB is on signal's wick
if isUpRjb1 and plotRJB
_bullboxRJB = box.new(left=bar_index-2, top=close , right=bar_index, bottom=low , bgcolor=rjbBullColor, border_color=color.new(rjbBullColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
text=plotLabelRJB ? _rjbLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
if array.size(_bullBoxesRJB) > rjbMaxBoxSet
box.delete(array.shift(_bullBoxesRJB))
array.push(_bullBoxesRJB, _bullboxRJB)
if isUpRjb2 and plotRJB
_bullboxRJB = box.new(left=bar_index-1, top=open , right=bar_index, bottom=low , bgcolor=rjbBullColor, border_color=color.new(rjbBullColor, rjbBorderTransparency), border_style=rjbBoxBorder, border_width=1,
text=plotLabelRJB ? _rjbLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=rjbLabelSize, text_color=rjbLabelColor)
if array.size(_bullBoxesRJB) > rjbMaxBoxSet
box.delete(array.shift(_bullBoxesRJB))
array.push(_bullBoxesRJB, _bullboxRJB)
if plotRJB
_controlBox(_bearBoxesRJB, high, low, _rjb)
_controlBox(_bullBoxesRJB, high, low, _rjb)
//////////////////// Crossovers a.k.a. Break of Structure ////////////////////
//Bullish BOS Box Plotting
if plotBOS
if ta.crossover(useHighLowForBullishBoS ? high : close, top)
_bullboxBOS = box.new(left=bar_index, top=top, right=bosBoxFlag ? bar_index+bosBoxLength : bar_index+1, bottom=bottom, bgcolor=bosBullColor, border_color=color.new(bosBullColor, bosBorderTransparency), border_style=bosBoxBorder, border_width=1,
text=plotLabelBOS ? _bosLabel + _plus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=bosLabelSize, text_color=bosLabelColor)
if array.size(_bullBoxesBOS) > bosMaxBoxSet
box.delete(array.shift(_bullBoxesBOS))
array.push(_bullBoxesBOS, _bullboxBOS)
//Bearish BOS Box Plotting
if plotBOS
if ta.crossunder(useHighLowForBearishBoS ? low : close, bottom)
_bearboxBOS = box.new(left=bar_index, top=top, right=bosBoxFlag ? bar_index+bosBoxLength : bar_index+1, bottom=bottom, bgcolor=bosBearColor, border_color=color.new(bosBearColor, bosBorderTransparency), border_style=bosBoxBorder, border_width=1,
text=plotLabelBOS ? _bosLabel + _minus : _empty, text_halign=text.align_right, text_valign=text.align_bottom, text_size=bosLabelSize, text_color=bosLabelColor)
if array.size(_bearBoxesBOS) > bosMaxBoxSet
box.delete(array.shift(_bearBoxesBOS))
array.push(_bearBoxesBOS, _bearboxBOS)
if plotBOS
_controlBox(_bearBoxesBOS, high, low, _bos)
_controlBox(_bullBoxesBOS, high, low, _bos)
swingSize = input.int(25, "Market Structure Time-Horizon", tooltip='Defines the number of candles used to determine market structure. Larger values smooth out market structure changes but may delay signals.', group="Inputs")
bosConfType = input.string('Candle Close', 'BOS Confirmation Type', , tooltip='Specifies whether a candle close or a wick surpassing the previous swing point is used to confirm a Break of Structure (BOS).', group="Inputs")
choch = input.bool(true, 'Show CHoCH', tooltip='Enables or disables the display of Change of Character (CHoCH) labels, highlighting the first structural break against the trend.', group="Inputs")
color BULL = input.color(#00ffbb, "Bullish Color", group="Visualization", tooltip='Sets the color used to represent bullish signals and breakout lines.')
color BEAR = input.color(#ff1100, "Bearish Color", group="Visualization", tooltip='Sets the color used to represent bearish signals and breakout lines.')
MS(int swingSize, int src_BI, string bosConfType, bool enms, float src_close, float src_high, float src_low) =>
pivHi = ta.pivothigh(src_high, swingSize, swingSize)
pivLo = ta.pivotlow(src_low, swingSize, swingSize)
var float prevHigh = na
var float prevLow = na
var int prevHighIndex = na
var int prevLowIndex = na
var bool highActive = false
var bool lowActive = false
bool hh = false
bool lh = false
bool hl = false
bool ll = false
var int prevSwing = 0
if not na(pivHi) and enms
if pivHi >= prevHigh
hh := true
prevSwing := 2
else
lh := true
prevSwing := 1
prevHigh := pivHi
highActive := true
prevHighIndex := src_BI - swingSize
if not na(pivLo) and enms
if pivLo >= prevLow
hl := true
prevSwing := -1
else
ll := true
prevSwing := -2
prevLow := pivLo
lowActive := true
prevLowIndex := src_BI - swingSize
bool highBroken = false
bool lowBroken = false
float highSrc = bosConfType == 'Candle Close' ? src_close : src_high
float lowSrc = bosConfType == 'Candle Close' ? src_close : src_low
if highSrc > prevHigh and highActive and enms
highBroken := true
highActive := false
if lowSrc < prevLow and lowActive and enms
lowBroken := true
lowActive := false
= MS(swingSize, bar_index, bosConfType, true, close, high, low)
var int prevBreakoutDir = 0
length = 0
if highBroken
line.new(prevHighIndex, prevHigh, bar_index, prevHigh, color=BULL, width=1, force_overlay=true)
label.new(math.floor(bar_index - (bar_index - prevHighIndex) / 2), prevHigh, prevBreakoutDir == -1 and choch ? 'CHoCH' : 'BOS', color=color.rgb(0, 0, 0, 100), textcolor=BULL, size=size.tiny, force_overlay=true)
alert("Bullish Breakout Detected", alert.freq_once_per_bar)
prevBreakoutDir := 1
length := bar_index - prevHighIndex
if lowBroken
line.new(prevLowIndex, prevLow, bar_index, prevLow, color=BEAR, width=1, force_overlay=true)
label.new(math.floor(bar_index - (bar_index - prevLowIndex) / 2), prevLow, prevBreakoutDir == 1 and choch ? 'CHoCH' : 'BOS', color=color.rgb(0, 0, 0, 100), textcolor=BEAR, style=label.style_label_up, size=size.tiny, force_overlay=true)
alert("Bearish Breakout Detected", alert.freq_once_per_bar)
prevBreakoutDir := -1
length := bar_index - prevLowIndex
x = math.max(1, nz(length))
v = ta.highest(x) - ta.lowest(x)
dist = v / 3
trigger = 0
RR = 1
var active = 0
var active1 = 0
var active2 = 0
var TP = 0.0
var TP1 = 0.0
var TP2 = 0.0
var SL = 0.0
var TPs = array.new_line()
var TPs1 = array.new_line()
var TPs2 = array.new_line()
var total = 0
var tp1s = 0
var tp2s = 0
var tp3s = 0
if highBroken
active := 1
active1 := 1
active2 := 1
trigger := 1
total += 1
TP := prevHigh + dist
TP1 := prevHigh + dist * 2 / 3
TP2 := prevHigh + dist * 1 / 3
SL := prevHigh - dist / RR
TPs.unshift(line.new(prevHighIndex, TP, bar_index, TP, color=color.new(BULL, 70), width=1, force_overlay=true, style=line.style_dashed))
TPs1.unshift(line.new(prevHighIndex, TP1, bar_index, TP1, color=color.new(BULL, 50), width=1, force_overlay=true, style=line.style_dashed))
TPs2.unshift(line.new(prevHighIndex, TP2, bar_index, TP2, color=color.new(BULL, 30), width=1, force_overlay=true, style=line.style_dashed))
linefill.new(TPs.first(), TPs1.first(), color.new(BULL, 90))
if lowBroken
active := -1
active1 := -1
active2 := -1
trigger := 1
total += 1
TP := prevLow - dist
TP1 := prevLow - dist * 2 / 3
TP2 := prevLow - dist * 1 / 3
SL := prevLow + dist / RR
TPs.unshift(line.new(prevLowIndex, TP, bar_index, TP, color=color.new(BEAR, 70), width=1, force_overlay=true, style=line.style_dashed))
TPs1.unshift(line.new(prevLowIndex, TP1, bar_index, TP1, color=color.new(BEAR, 50), width=1, force_overlay=true, style=line.style_dashed))
TPs2.unshift(line.new(prevLowIndex, TP2, bar_index, TP2, color=color.new(BEAR, 30), width=1, force_overlay=true, style=line.style_dashed))
linefill.new(TPs.first(), TPs1.first(), color.new(BEAR, 90))
if active == 1 and high > TP
tp1s += 1
if active1 == 1 and high > TP1
tp2s += 1
active1 := 0
if active2 == 1 and high > TP2
tp3s += 1
active2 := 0
if active == -1 and low < TP
tp1s += 1
if active1 == -1 and low < TP1
tp2s += 1
active1 := 0
if active2 == -1 and low < TP2
tp3s += 1
active2 := 0
if ((active == 1 and high > TP) or (active == 1 and low < SL) or (active == -1 and low < TP) or (active == -1 and high > SL)) and not (trigger != 0 and trigger == 0)
active := 0
if TPs.size() > 0
if active == 0 or (active != 0 and active != 0 and trigger == 1)
TPs.remove(math.min(1, TPs.size() - 1))
else
TPs.first().set_x2(bar_index)
if TPs1.size() > 0
if active == 0 or (active != 0 and active != 0 and trigger == 1)
TPs1.remove(math.min(1, TPs1.size() - 1))
else
TPs1.first().set_x2(bar_index)
if TPs2.size() > 0
if active == 0 or (active != 0 and active != 0 and trigger == 1)
TPs2.remove(math.min(1, TPs2.size() - 1))
else
TPs2.first().set_x2(bar_index)
barcolor(active == 0 ? color.new(color.gray, 40) : active == 1 ? color.new(BULL , 40) : color.new(BEAR , 40))
plotshape(highBroken, "Bullish Signal", shape.labelup, location.belowbar, BULL, size=size.small)
plotshape(lowBroken, "Bearish Signal", shape.labeldown, location.abovebar, BEAR, size=size.small)
// plot(total)
// plot(tp1s, color = color.white)
// plot(tp2s, color = color.red)
// plot(tp3s, color = color.yellow)
if barstate.islast
var table data_table = table.new(
position=position.top_right,
columns=2,
rows=5,
bgcolor=chart.bg_color,
border_width=1,
border_color=chart.fg_color,
frame_color=chart.fg_color,
frame_width=1
)
t1_rate = total > 0 ? (tp1s / total) * 100.0 : na
t2_rate = total > 0 ? (tp2s / total) * 100.0 : na
t3_rate = total > 0 ? (tp3s / total) * 100.0 : na
table.cell(
data_table,
column = 0,
row = 0,
text = "Stats",
text_size= size.tiny,
text_color = chart.fg_color,
text_halign= text.align_center
)
table.cell(
data_table,
column = 1,
row = 0,
text = "Value",
text_size= size.tiny,
text_color = chart.fg_color,
text_halign= text.align_center
)
table.cell(
data_table,
column = 0,
row = 1,
text = "Total Signals",
text_size= size.tiny,
text_color = chart.fg_color
)
table.cell(
data_table,
column = 1,
row = 1,
text = str.tostring(total),
text_size= size.tiny,
text_color = chart.fg_color,
text_halign= text.align_center
)
table.cell(
data_table,
column = 0,
row = 2,
text = "TP1 Win Rate",
text_size= size.tiny,
text_color = chart.fg_color
)
table.cell(
data_table,
column = 1,
row = 2,
text = total > 0 ? str.format("{0,number,#.##}%", t3_rate) : "No Trades",
text_size= size.tiny,
text_color = chart.fg_color,
text_halign= text.align_center
)
table.cell(
data_table,
column = 0,
row = 3,
text = "TP2 Win Rate",
text_size= size.tiny,
text_color = chart.fg_color
)
table.cell(
data_table,
column = 1,
row = 3,
text = total > 0 ? str.format("{0,number,#.##}%", t2_rate) : "No Trades",
text_size= size.tiny,
text_color = chart.fg_color,
text_halign= text.align_center
)
table.cell(
data_table,
column = 0,
row = 4,
text = "TP3 Win Rate",
text_size= size.tiny,
text_color = chart.fg_color
)
table.cell(
data_table,
column = 1,
row = 4,
text = total > 0 ? str.format("{0,number,#.##}%", t1_rate) : "No Trades",
text_size= size.tiny,
text_color = chart.fg_color,
text_halign= text.align_center
)
//////Alerts
alertcondition(highBroken, "Bullish Signal")
alertcondition(lowBroken, "Bearish Signal")
// ==========================================================================================
// === Dashboard with Telegram Link ===
var table myTable = table.new(position.top_center, 1, 1, border_width=1, frame_color=color.black, bgcolor=color.white)
// Add Telegram Message to Dashboard
table.cell(myTable, 0, 0, "Join Team VitaLegacy", bgcolor=color.blue, text_color=color.white, text_size=size.normal)
Stochastic RSI (Persistent Crossover Colors)Stochastic RSI single line. color change to green when K crosses above B and to Red when cross below
VitaLegacy Magic// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
// Join our channel for more free tools: t.me
//@version=5
indicator("VitaLegacy Magic", overlay=true, max_labels_count=500)
//------------------------------------------------------------------------------
// Input Settings
useBody = input(false, 'Use Candle Body')
signalMode = input.string('Simple Entry + Exits', 'Signal Strategy', , tooltip='Change Your Signal Appearance And Strategies')
sensitivity = input.float(2.3, "Sensitivity", 0.6, 15.1, step=0.1, tooltip='Change Your Signal Sensitivity And Accuracy')
strongSignalOnly = input(false, "STRONG Only", inline='BasicFilters')
noRepainting = input(false, 'No Repainting', inline='BasicFilters', tooltip='Disables all signals except strong signals Disables repainting for signals')
Multiplier = input.float(1.5, "ATR Multiplier", step=0.1)
align_with_supertrend = input.bool(false, "Align Signals with Supertrend", tooltip="Enable to align buy/sell signals with Supertrend direction")
//------------------------------------------------------------------------------
// ATR and Supertrend Calculation
atr = ta.atr(14)
st_atr_length = input.int(10, "Supertrend ATR Length", minval=1)
st_multiplier = input.float(3.0, "Supertrend Multiplier", step=0.1)
upper_band = ta.sma(close, st_atr_length) + st_multiplier * atr
lower_band = ta.sma(close, st_atr_length) - st_multiplier * atr
var float supertrend = na
supertrend := close > nz(supertrend ) ? math.max(lower_band, nz(supertrend )) : math.min(upper_band, nz(supertrend ))
supertrend_up = close > supertrend
supertrend_down = close < supertrend
//------------------------------------------------------------------------------
// Signal Logic
src = close
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x ), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng = smoothrng(close, 100, sensitivity)
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt ) ? x - r < nz(rngfilt ) ? nz(rngfilt ) : x - r : x + r > nz(rngfilt ) ? nz(rngfilt ) : x + r
rngfilt
filt = rngfilt(src, smrng)
var float upward = na
var float downward = na
var int CondIni = na
upward := filt > filt ? nz(upward ) + 1 : filt < filt ? 0 : nz(upward )
downward := filt < filt ? nz(downward ) + 1 : filt > filt ? 0 : nz(downward )
longCond = src > filt and src > src and upward > 0 or src > filt and src < src and upward > 0
shortCond = src < filt and src < src and downward > 0 or src < filt and src > src and downward > 0
CondIni := longCond ? 1 : shortCond ? -1 : nz(CondIni )
buyCond = longCond and CondIni == -1
strongBuyCond = buyCond and close <= filt - smrng
sellCond = shortCond and CondIni == 1
strongSellCond = sellCond and open >= filt + smrng
if noRepainting
buyCond := buyCond and barstate.isconfirmed
strongBuyCond := strongBuyCond and barstate.isconfirmed
sellCond := sellCond and barstate.isconfirmed
strongSellCond := strongSellCond and barstate.isconfirmed
//------------------------------------------------------------------------------
// Tradingview indicators. Join ->>> t.me
// -------------------- 👆👆👆👆👆👆 ---------------
//------------------------------------------------------------------------------
// ATR-Based Book Profit and Wait for Supertrend Break
var float buy_entry_price = na
var float sell_entry_price = na
var bool buy_profit_plotted = false
var bool sell_profit_plotted = false
if (buyCond or strongBuyCond)
buy_entry_price := close
buy_profit_plotted := false
if (sellCond or strongSellCond)
sell_entry_price := close
sell_profit_plotted := false
buy_target = buy_entry_price + (atr * Multiplier)
sell_target = sell_entry_price - (atr * Multiplier)
if (not na(buy_entry_price) and close >= buy_target and not buy_profit_plotted)
label.new(bar_index, high, "Book Profit", color=#00db0a, style=label.style_label_down, textcolor=color.white, size=size.normal)
buy_profit_plotted := true
label.new(bar_index, high - atr, "Wait for Supertrend to break", color=color.orange, style=label.style_label_down, textcolor=color.white, size=size.normal)
if (not na(sell_entry_price) and close <= sell_target and not sell_profit_plotted)
label.new(bar_index, low, "Book Profit", color=#ff0000, style=label.style_label_up, textcolor=color.white, size=size.normal)
sell_profit_plotted := true
label.new(bar_index, low + atr, "Wait for Supertrend to break", color=color.orange, style=label.style_label_up, textcolor=color.white, size=size.normal)
//------------------------------------------------------------------------------
// Candle Coloring
barcolor_cond = src > filt and upward > 0 ? color.new(#00db0a, 5) : src < filt and downward > 0 ? color.new(#c90505, 5) : na
barcolor(barcolor_cond, title='Candle Colors')
// Plot Signals
plotshape(buyCond and not strongSignalOnly, 'Buy', shape.labelup, location.belowbar, color.new(#21ff30, 0), size=size.small, textcolor=color.black, text='BUY')
plotshape(strongBuyCond, 'Strong Buy', shape.labelup, location.belowbar, color.new(#09ff00, 0), size=size.small, textcolor=color.black, text='BUY')
plotshape(sellCond and not strongSignalOnly, 'Sell', shape.labeldown, location.abovebar, color.new(#ff0000, 0), size=size.small, textcolor=color.black, text='SELL')
plotshape(strongSellCond, 'Strong Sell', shape.labeldown, location.abovebar, color.new(#ff0000, 0), size=size.small, textcolor=color.black, text='SELL')
// Supertrend Plot
plot(supertrend, color=supertrend_up ? color.green : color.red, title="Supertrend", linewidth=2)
// ==========================================================================================
// === Dashboard with Telegram Link ===
var table myTable = table.new(position.top_center, 1, 1, border_width=1, frame_color=color.black, bgcolor=color.white)
// Add Telegram Message to Dashboard
table.cell(myTable, 0, 0, "VitaLegacy", bgcolor=color.blue, text_color=color.white, text_size=size.normal)
NOSTRADAMUS// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at mozilla.org
bbars = input.int(title='Number of Bars', defval=150, minval=1, maxval=500)
cnum = input.int(title='Row Size', defval=24, minval=5, maxval=100)
percent = input.float(100., title='Value Area Volume %', minval=0, maxval=100)
poc_color = input.color(defval=#ffffff57, title='POC Color', inline='poc')
poc_width = input.int(defval=2, title='Width', minval=1, maxval=5, inline='poc')
vup_color = input(defval=color.new(color.blue, 30), title='Value Area Up')
vdown_color = input(defval=color.new(color.orange, 30), title='Value Area Down')
up_color = input(defval=color.new(color.blue, 75), title='UP Volume')
down_color = input(defval=color.new(color.orange, 75), title='Down Volume')
show_poc = input.bool(defval = false, title = "Show POC Label")
top = ta.highest(bbars)
bot = ta.lowest(bbars)
dist = (top - bot) / 500
step = (top - bot) / cnum
// calculate/keep channel levels
levels5 = array.new_float(cnum + 1)
for x = 0 to cnum by 1
array.set(levels5, x, bot + step * x)
// get the volume if there is intersection
get_vol(y11, y12, y21, y22, height, vol) =>
nz(math.max(math.min(math.max(y11, y12), math.max(y21, y22)) - math.max(math.min(y11, y12), math.min(y21, y22)), 0) * vol / height)
if barstate.islast
// calculate/get volume for each channel and candle
volumes = array.new_float(cnum * 2, 0.)
for bars = 0 to bbars - 1 by 1
body_top = math.max(close , open )
body_bot = math.min(close , open )
itsgreen = close >= open
topwick = high - body_top
bottomwick = body_bot - low
body = body_top - body_bot
bodyvol = body * volume / (2 * topwick + 2 * bottomwick + body)
topwickvol = 2 * topwick * volume / (2 * topwick + 2 * bottomwick + body)
bottomwickvol = 2 * bottomwick * volume / (2 * topwick + 2 * bottomwick + body)
for x = 0 to cnum - 1 by 1
array.set(volumes, x, array.get(volumes, x) + (itsgreen ? get_vol(array.get(levels5, x), array.get(levels5, x + 1), body_bot, body_top, body, bodyvol) : 0) + get_vol(array.get(levels5, x), array.get(levels5, x + 1), body_top, high , topwick, topwickvol) / 2 + get_vol(array.get(levels5, x), array.get(levels5, x + 1), body_bot, low , bottomwick, bottomwickvol) / 2)
array.set(volumes, x + cnum, array.get(volumes, x + cnum) + (itsgreen ? 0 : get_vol(array.get(levels5, x), array.get(levels5, x + 1), body_bot, body_top, body, bodyvol)) + get_vol(array.get(levels5, x), array.get(levels5, x + 1), body_top, high , topwick, topwickvol) / 2 + get_vol(array.get(levels5, x), array.get(levels5, x + 1), body_bot, low , bottomwick, bottomwickvol) / 2)
totalvols = array.new_float(cnum, 0.)
for x = 0 to cnum - 1 by 1
array.set(totalvols, x, array.get(volumes, x) + array.get(volumes, x + cnum))
int poc = array.indexof(totalvols, array.max(totalvols))
// calculate value area
totalmax = array.sum(totalvols) * percent / 100.
va_total = array.get(totalvols, poc)
int up = poc
int down = poc
for x = 0 to cnum - 1 by 1
if va_total >= totalmax
break
uppervol = up < cnum - 1 ? array.get(totalvols, up + 1) : 0.
lowervol = down > 0 ? array.get(totalvols, down - 1) : 0.
if uppervol == 0 and lowervol == 0
break
if uppervol >= lowervol
va_total += uppervol
up += 1
up
else
va_total += lowervol
down -= 1
down
maxvol = array.max(totalvols)
for x = 0 to cnum * 2 - 1 by 1
array.set(volumes, x, array.get(volumes, x) * bbars / (3 * maxvol))
// Draw VP rows
var vol_bars = array.new_box(cnum * 2, na)
for x = 0 to cnum - 1 by 1
box.delete(array.get(vol_bars, x))
box.delete(array.get(vol_bars, x + cnum))
array.set(vol_bars, x, box.new(bar_index - bbars + 1,
array.get(levels5, x + 1) - dist,
bar_index - bbars + 1 + math.round(array.get(volumes, x)),
array.get(levels5, x) + dist,
border_width=0,
bgcolor=x >= down and x <= up ? vup_color : up_color))
array.set(vol_bars, x + cnum, box.new(bar_index - bbars + 1 + math.round(array.get(volumes, x)),
array.get(levels5, x + 1) - dist,
bar_index - bbars + 1 + math.round(array.get(volumes, x)) + math.round(array.get(volumes, x + cnum)),
array.get(levels5, x) + dist,
border_width=0,
bgcolor=x >= down and x <= up ? vdown_color : down_color))
// Draw POC line and label
poc_level = (array.get(levels5, poc) + array.get(levels5, poc + 1)) / 2
var line poc_line = na
line.delete(poc_line)
poc_line := line.new(bar_index - bbars + 1, poc_level, bar_index - bbars + 2, poc_level, extend=extend.right, color=poc_color, width=poc_width)
if show_poc
var label poc_label = na
label.delete(poc_label)
poc_label := label.new(bar_index + 15, poc_level,
text = "POC: " + str.tostring(math.round_to_mintick(poc_level)),
style = close >= poc_level ? label.style_label_up : label.style_label_down)
//Gathers User Inputs
dashOn = input(true, 'Dashboard On / Off')
dashDist = input(93, 'Dashboard Distance')
dashColor = input.color(color.new(#000000, 0), 'Dashboard Color', inline='Dash Line')
dashTextColor = input.color(color.new(#00c8ff, 0), 'Text Color', inline='Dash Line')
//Calculates Volatility for Dashboard
atr9 = ta.atr(14)
stdAtr = 2 * ta.stdev(atr9, 20)
smaAtr = ta.sma(atr9, 20)
topAtrDev = smaAtr + stdAtr
bottomAtrDev = smaAtr - stdAtr
calcDev = (atr9 - bottomAtrDev) / (topAtrDev - bottomAtrDev)
percentVol = 40 * calcDev + 30
//Calculates Volume for Dashboard
volumeDash = volume
//RSI for Dashboard
rsiDash = ta.rsi(close, 14)
//Calculates Sentiment for Dashboard
ema9 = ta.ema(close, 9)
totalSentTxt = ema9 > ema9 ? 'Bullish' : ema9 < ema9 ? 'Bearish' : 'Flat'
//Defines Each Timeframe for Trend Panel
sma = ta.sma(close, 50)
oneM = request.security(syminfo.tickerid, '1', sma, barmerge.gaps_off, barmerge.lookahead_off)
fiveM = request.security(syminfo.tickerid, '5', sma, barmerge.gaps_off, barmerge.lookahead_off)
fifteenM = request.security(syminfo.tickerid, '15', sma, barmerge.gaps_off, barmerge.lookahead_off)
thirtyM = request.security(syminfo.tickerid, '30', sma, barmerge.gaps_off, barmerge.lookahead_off)
oneH = request.security(syminfo.tickerid, '60', sma, barmerge.gaps_off, barmerge.lookahead_off)
twoH = request.security(syminfo.tickerid, '120', sma, barmerge.gaps_off, barmerge.lookahead_off)
fourH = request.security(syminfo.tickerid, '240', sma, barmerge.gaps_off, barmerge.lookahead_off)
weekly = request.security(syminfo.tickerid, 'W', sma, barmerge.gaps_off, barmerge.lookahead_off)
monthly = request.security(syminfo.tickerid, 'M', sma, barmerge.gaps_off, barmerge.lookahead_off)
daily = request.security(syminfo.tickerid, 'D', sma, barmerge.gaps_off, barmerge.lookahead_off)
//Defines An Uptrend for Trend Panel
oneMUp = oneM > oneM
fiveMUp = fiveM > fiveM
fifteenMUp = fifteenM > fifteenM
thirtyMUp = thirtyM > thirtyM
oneHUp = oneH > oneH
twoHUp = twoH > twoH
fourHUp = fourH > fourH
weeklyUp = weekly > weekly
monthlyUp = monthly > monthly
dailyUp = daily > daily
//Checks if the Current State is an Uptrend or Downtrend for the Trend Panel
up7 = '🟢'
down = '🔴'
oneMTrend = oneMUp ? up7 : down
fiveMTrend = fiveMUp ? up7 : down
fifteenMTrend = fifteenMUp ? up7 : down
thirtyMTrend = thirtyMUp ? up7 : down
oneHTrend = oneHUp ? up7 : down
twoHTrend = twoHUp ? up7 : down
fourHTrend = fourHUp ? up7 : down
weeklyTrend = weeklyUp ? up7 : down
monthlyTrend = monthlyUp ? up7 : down
dailyTrend = dailyUp ? up7 : down
if dashOn
label lemonLabel = label.new(time, close, text='☁️ TABLETA MEGA POWER V3 ☁️' + ' ━━━━━━━━━━━━━━━━━' + ' 💵 informacion de mercado 💵' + ' ━━━━━━━━━━━━━━━━━' + ' 🟡 Volatilidad | ' + str.tostring(percentVol, '##.##') + '%' + ' 🟡 Volumen | ' + str.tostring(volumeDash, '##.##') + ' 🟡 RSI | ' + str.tostring(rsiDash, '##.##') + ' 🟡 Sentimiento mercado | ' + totalSentTxt + ' ━━━━━━━━━━━━━━━━━' + ' 📈 Trend Panel 📉' + ' ━━━━━━━━━━━━━━━━━' + ' 1 Minute | ' + oneMTrend + ' 2 Hour | ' + twoHTrend + ' 5 Minute | ' + fiveMTrend + ' 4 Hour | ' + fourHTrend + ' 15 Minute | ' + fifteenMTrend + ' Weekly | ' + weeklyTrend + ' 30 Minute | ' + thirtyMTrend + ' Monthly | ' + monthlyTrend + ' 1 Hour | ' + oneHTrend + ' Daily | ' + dailyTrend + ' ━━━━━━━━━━━━━━━━━' + ' 🔱CRIPTOM4N 🔱', color=dashColor, xloc=xloc.bar_time, style=label.style_label_left, textcolor=dashTextColor, textalign=text.align_left)
label.set_x(lemonLabel, label.get_x(lemonLabel) + math.round(ta.change(time) * dashDist))
label.delete(lemonLabel )
// Inputs EMA
src = input(close, title='Tipo EMA')
len = input.int(minval=1, defval=200, title='EMA 200')
ema_color = input(color.rgb(255, 242, 0), title="Color de la EMA") // Nuevo input para el color de la EMA
// Cálculo
ema = ta.ema(src, len)
// Determinación de señales
long = close > ema
short = close < ema
// Plot de la EMA con el color personalizado
plot(ema, color=ema_color, title="EMA")
plot(ema)
//
ShowPAC = input(false, title='Show EMA Wave')
ShowBarColor = input(true, title='Show Coloured GRaB Candles')
PACLen = input.int(34, minval=2, title='EMA Wave Length (34 by default)')
src2 = input(close, title='Source for Wave centre EMA')
// --- CONSTANTS ---
DodgerBlue = #1e8fff
// === /INPUTS ===
// Constants colours that include fully non-transparent option.
green100 = #00FF00FF
lime100 = #00FF00FF
red100 = #FF0000FF
blue100 = color.rgb(255, 255, 255)
aqua100 = color.rgb(255, 255, 255)
darkred100 = #FF0000FF
// === SERIES SETUP ===
// Price action channel (Wave)
pacCe = ta.ema(src, PACLen)
pacLo = ta.ema(low, PACLen)
pacHi = ta.ema(high, PACLen)
// === /SERIES ===
// === PLOTTING ===
//
// If selected, Plot the Wave Channel based on EMA high,low and close
L = plot(ShowPAC ? pacLo : na, color=color.new(color.red, 20), linewidth=1, title='High Wave EMA')
H = plot(ShowPAC ? pacHi : na, color=color.new(color.green, 20), linewidth=1, title='Low Wave EMA')
C = plot(ShowPAC ? pacCe : na, color=color.new(color.black, 20), linewidth=1, title='Centre Wave EMA')
fill(L, H, color=color.new(color.gray, 9), title='Fill Channel')
// Colour bars according to the close position relative to the PAC selected.
bColour = close >= open ? close >= pacHi ? lime100 : close <= pacLo ? red100 : aqua100 : close >= pacHi ? green100 : close <= pacLo ? darkred100 : blue100
barcolor(ShowBarColor ? bColour : na, title='Bar Colours')
//------------------ AI Signals | www.getaisignals.com ---------------//
// Get user input
sensitivity = input.string("Low", "Sensitivity", )
suppRes = input.bool(false, "Support & Resistance")
breaks = input.bool(false, "Breaks")
usePsar = input.bool(false, "PSAR")
emaEnergy = input.bool(true, "EMA Energy")
channelBal = input.bool(true, "Channel Balance")
autoTL = input.bool(false, "Auto Trend Lines")
// Functions
supertrend(_src, factor, atrLen) =>
atr = ta.atr(atrLen)
upperBand = _src + factor * atr
lowerBand = _src - factor * atr
prevLowerBand = nz(lowerBand )
prevUpperBand = nz(upperBand )
lowerBand := lowerBand > prevLowerBand or close < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close > prevUpperBand ? upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend
if na(atr )
direction := 1
else if prevSuperTrend == prevUpperBand
direction := close > upperBand ? -1 : 1
else
direction := close < lowerBand ? 1 : -1
superTrend := direction == -1 ? lowerBand : upperBand
lr_slope(_src, _len) =>
x = 0.0, y = 0.0, x2 = 0.0, xy = 0.0
for i = 0 to _len - 1
val = _src
per = i + 1
x += per
y += val
x2 += per * per
xy += val * per
_slp = (_len * xy - x * y) / (_len * x2 - x * x)
_avg = y / _len
_int = _avg - _slp * x / _len + _slp
lr_dev(_src, _len, _slp, _avg, _int) =>
upDev = 0.0, dnDev = 0.0
val = _int
for j = 0 to _len - 1
price = high - val
if price > upDev
upDev := price
price := val - low
if price > dnDev
dnDev := price
price := _src
val += _slp
// Get Components
ocAvg = math.avg(open, close)
sma1 = ta.sma(close, 8)
sma2 = ta.sma(close, 9)
sma3 = ta.sma(close, 10)
sma4 = ta.sma(close, 11)
sma5 = ta.sma(close, 12)
sma6 = ta.sma(close, 13)
sma7 = ta.sma(close, 14)
sma8 = ta.sma(close, 15)
sma9 = ta.sma(close, 15)
psar = ta.sar(0.02, 0.02, 0.2)
= ta.kc(close, 80, 10.5)
= ta.kc(close, 80, 9.5)
= ta.kc(close, 80, 8)
= ta.kc(close, 80, 3)
= supertrend(close, sensitivity == "Low" ? 5 : sensitivity == "Medium" ? 2.5 : 2, 11)
barsL = 10
barsR = 10
pivotHigh = fixnan(ta.pivothigh(barsL, barsR) )
pivotLow = fixnan(ta.pivotlow(barsL, barsR) )
source = close, period = 150
= lr_slope(source, period)
= lr_dev(source, period, s, a, i)
// Colors
green = #1ab3d5, green2 = #00DD00
red = #e4ab1a, red2 = #DD0000
emaEnergyColor(ma) => emaEnergy ? (close >= ma ? green : red) : na
// Plots
k1 = plot(ta.ema(upperKC1, 50), "", na, editable=false)
k2 = plot(ta.ema(upperKC2, 50), "", na, editable=false)
k3 = plot(ta.ema(upperKC3, 50), "", na, editable=false)
k4 = plot(ta.ema(upperKC4, 50), "", na, editable=false)
k5 = plot(ta.ema(lowerKC4, 50), "", na, editable=false)
k6 = plot(ta.ema(lowerKC3, 50), "", na, editable=false)
k7 = plot(ta.ema(lowerKC2, 50), "", na, editable=false)
k8 = plot(ta.ema(lowerKC1, 50), "", na, editable=false)
fill(k1, k2, channelBal ? color.new(red2, 40) : na, editable=false)
fill(k2, k3, channelBal ? color.new(red2, 65) : na, editable=false)
fill(k3, k4, channelBal ? color.new(red2, 90) : na, editable=false)
fill(k5, k6, channelBal ? color.new(green2, 90) : na, editable=false)
fill(k6, k7, channelBal ? color.new(green2, 65) : na, editable=false)
fill(k7, k8, channelBal ? color.new(green2, 40) : na, editable=false)
plot(sma1, "", emaEnergyColor(sma1), editable=false)
plot(sma2, "", emaEnergyColor(sma2), editable=false)
plot(sma3, "", emaEnergyColor(sma3), editable=false)
plot(sma4, "", emaEnergyColor(sma4), editable=false)
plot(sma5, "", emaEnergyColor(sma5), editable=false)
plot(sma6, "", emaEnergyColor(sma6), editable=false)
plot(sma7, "", emaEnergyColor(sma7), editable=false)
plot(sma8, "", emaEnergyColor(sma8), editable=false)
plot(sma9, "", emaEnergyColor(sma9), editable=false)
p3 = plot(ocAvg, "", na, editable=false)
p4 = plot(psar, "PSAR", usePsar ? (close > psar ? green : red) : na, 1, plot.style_circles, editable=false)
fill(p3, p4, usePsar ? (close > psar ? color.new(green, 90) : color.new(red, 90)) : na, editable=false)
y1 = low - (ta.atr(30) * 1.6), y1B = low - ta.atr(30)
y2 = high + (ta.atr(30) * 1.6), y2B = high + ta.atr(30)
bull = ta.crossover(close, supertrend) and close >= sma9
bear = ta.crossunder(close, supertrend) and close <= sma9
buy = bull ? label.new(bar_index, y1, "▲", xloc.bar_index, yloc.price, #102bf8, label.style_label_up, color.white, size.normal) : na
sell = bear ? label.new(bar_index, y2, "▼", xloc.bar_index, yloc.price, #b4060d, label.style_label_down, color.white, size.normal) : na
plot(pivotHigh, "Resistance", not suppRes or ta.change(pivotHigh) ? na : red, 2, offset=-(barsR + 1), editable=false)
plot(pivotLow, "Support", not suppRes or ta.change(pivotLow) ? na : green, 2, offset=-(barsR + 1), editable=false)
upB = breaks and ta.crossover(close, pivotHigh) ? label.new(bar_index, y1B, "B", xloc.bar_index, yloc.price, green, label.style_label_up, color.white, size.small) : na
dnB = breaks and ta.crossunder(close, pivotLow) ? label.new(bar_index, y2B, "B", xloc.bar_index, yloc.price, red, label.style_label_down, color.white, size.small) : na
x1 = bar_index - period + 1, _y1 = i + s * (period - 1), x2 = bar_index, _y2 = i
upperTL = autoTL ? line.new(x1, _y1 + upDev, x2, _y2 + upDev, xloc.bar_index, extend.none, red) : na
line.delete(upperTL )
middleTL = autoTL ? line.new(x1, _y1, x2, _y2, xloc.bar_index, extend.none, color.white) : na
line.delete(middleTL )
lowerTL = autoTL ? line.new(x1, _y1 - dnDev, x2, _y2 - dnDev, xloc.bar_index, extend.none, green) : na
line.delete(lowerTL )
// Alerts
// alertcondition(bull or bear or ta.crossover(close, pivotHigh) or ta.crossunder(close, pivotLow), "Alert Any", "AI Signals Platinum Alert Triggered on {{ticker}} @ {{close}}")
// alertcondition(bull, "Alert Buy", "AI Signals Platinum Buy {{ticker}} @ {{close}}")
// alertcondition(bear, "Alert Sell", "AI Signals Platinum Sell {{ticker}} @ {{close}}")
// alertcondition(ta.crossover(close, pivotHigh), "Broke Resistance", "AI Signals Platinum Broke Resistance on {{ticker}} @ {{close}}")
// alertcondition(ta.crossunder(close, pivotLow), "Broke Support", "AI Signals Platinum Broke Support on {{ticker}} @ {{close}}")
// Module - Signals - SL - TPS mejora enviada por: comgunner
//-----------------------------------------
//@version=5
indicator("NOSTRADAMUS"
, overlay = true
, max_labels_count = 500
, max_lines_count = 500
, max_boxes_count = 500
, max_bars_back = 500)
//=======================================================================================
// MODULO DE SEÑALES PARA MEGA POWER
//=======================================================================================
indicator_name = "Simplealgo.io - MEGAPOWER "
//=======================================================================================
changeCond = bull or bear //NECESARIO PARA EL MODULO DE TPS
//=======================================================================================
// Module - Signals - SL - TPS by @comgunner
//-----------------------------------------
//*********************************************************
//* Module *
//* Signals - SL - TPSEND *
//*********************************************************
// Cálculos
groupEnTpSl = "======= Module - Signals ======="
plot(na)
levels_tip = "Habilita etiquetas compra/venta /SL"
atrLen_tip = "Atr para el Calculo de Stoploss y TakeProfit"
atrRisk_tip = " ATR Risk Multiplier: Recommended 1.5 or 1.9 / Multiplicador de Riesgo ATR: Recomendado 1.5 o 1.9"
tpLen_tip = "Distance in percentage between TakeProfits / Distancia en porcentaje entre TakeProfits"
tpSL_tip = "Distance in percentage for SL / Distancia en porcentaje para SL"
numTP_tip = " Number of Take Profit Levels, min 1 max 10 / Número de niveles de toma de ganancias, mínimo 1 máximo 10 "
numTP = input.int(3, "Number of Take Profit Levels 🎱", minval=1, maxval=5,tooltip =numTP_tip ,group=groupEnTpSl)
PercentOrATR_tip="Select the calculation method for TakeProfits / Selecciona el metodo de calculo para los TakeProfits"
var string PercentOrATR = input.string("ATR", "Calculation method for TakeProfit (% or ATR)", options= , inline="TPS", group=groupEnTpSl,tooltip=PercentOrATR_tip)
levels = input(title='Show Entry Labels/SL/TP /Mostrar Etiquetas de Entrada/SL/TP', defval=true, group=groupEnTpSl, tooltip=levels_tip)
atrLen = input.int(14, "ATR Length TP", group=groupEnTpSl, tooltip=atrLen_tip)
atrRisk = input.float(1.0, "Riesgo trade", group=groupEnTpSl,tooltip=atrRisk_tip )
tpLen = input.float(2.0, "TP 🎱", step=0.1, group=groupEnTpSl, tooltip=tpLen_tip)
tpLenpre_tip = "Initial TP for Predictum type calculation / TP inicial para el cálculo del tipo Predictum"
tpLenpre = input.float(0.5, "TP Initial Predictum 🎱", minval=0.3, step=0.1, group=groupEnTpSl, tooltip=tpLenpre_tip)
tpSL = input.float(3.0, "SL 💀️", step=0.1, group=groupEnTpSl, tooltip=tpSL_tip)
lvlDecimals = input.int(3, "Decimals", 1, 16, inline="lvlDecimals",group=groupEnTpSl)
decimals = lvlDecimals == 1 ? "#.#" : lvlDecimals == 2 ? "#.##" : lvlDecimals == 3 ? "#.###" : lvlDecimals == 4 ? "#.####" : lvlDecimals == 5 ? "#.#####" : lvlDecimals == 6 ? "#.######" : lvlDecimals == 7 ? "#.#######" : lvlDecimals == 8 ? "#.########" : lvlDecimals == 9 ? "#.#########" : lvlDecimals == 10 ? "#.##########" : lvlDecimals == 11 ? "#.###########" : lvlDecimals == 12 ? "#.############" : lvlDecimals == 13 ? "#.#############" : lvlDecimals == 14 ? "#.##############" : lvlDecimals == 15 ? "#.###############" : "#.################"
lvlLines = input.bool(true, "Show TP/SL lines ? / Mostart Lineas TP/SL? ", inline="levels2",group=groupEnTpSl)
linesStyle = input.string("DOTTED", "", , inline="levels2",group=groupEnTpSl)
lvlDistance = input.int(3, "Distance / Distancia", 1, inline="levels2",group=groupEnTpSl)
stylelvl = linesStyle == "SOLID" ? line.style_solid : linesStyle == "DASHED" ? line.style_dashed : line.style_dotted
lvlLinesw = input.int(title=' TP/SL Line Thickness / Grosor de línea TP/SL', defval=1, minval=1,inline="levels2",group=groupEnTpSl)
filllvlLines = input.int(79, "Fill TP/SL Line Alpha %", minval=1, maxval=98,group=groupEnTpSl, inline="levels2")
filllvlLineson = input.bool(true, "Show TP/SL Fill lines ? / Mostart Relleno Lineas TP/SL? ", inline="levels2",group=groupEnTpSl)
trigger = bull ? 1 : 0
atrBand = ta.atr(atrLen) * atrRisk
atrStop = trigger == 1 ? low - atrBand : high + atrBand
lastTrade(src) => ta.valuewhen(changeCond, src, 0 )
//Nuevo, distancia de TP's
DistanceTp = close * tpLen / 100
Distance_CTp = trigger == 1 ? close - DistanceTp : close + DistanceTp
DistanceSL = close * tpSL / 100
Distance_CSL = trigger == 1 ? low - DistanceSL : high + DistanceSL
DistanceTppre = close * tpLenpre / 100
Distance_CTpre = trigger == 1 ? close - DistanceTppre : close + DistanceTppre
var float atrSL = na
if PercentOrATR == "ATR"
atrStop := atrStop
atrSL := atrStop
else
// Lógica para las opciones "PERCENTAGE" y "PREDICTUM"
if PercentOrATR == "PERCENTAGE"
atrStop := Distance_CTp
atrSL := Distance_CSL
else if PercentOrATR == "PREDICTUM"
atrStop := Distance_CTpre // Ajusta según tu lógica específica para "PREDICTUM"
atrSL := Distance_CSL
//numTP := 8
//CONTADOR DE VELAS, APARTIR E LA ULTIMA ENTRADA trigger o changeCondPNL = nz(alertLongPNL, false) != nz(alertShortPNL, false)
var int countOfCandles = 0
if trigger
countOfCandles := 0
else
countOfCandles := na(countOfCandles) ? 0 : countOfCandles + 1
//ENTRADA
entry = levels ? label.new(time, close, "ENTRY 🙈 " + str.tostring(lastTrade(close), decimals), xloc.bar_time, yloc.price, color.rgb(0, 145, 255), label.style_label_left, color.white, size.normal) : na
label.set_x(entry, label.get_x(entry) + math.round(ta.change(time) * lvlDistance))
label.set_y(entry, lastTrade(close))
label.delete(entry )
lineEntry = levels and lvlLines ? line.new(bar_index - countOfCandles, lastTrade(close), bar_index + lvlDistance ,lastTrade(close), xloc.bar_index, extend.none, color.rgb(0, 145, 255),stylelvl, width=lvlLinesw ) : na
line.delete(lineEntry )
//StopLoss
stop_y = lastTrade(atrSL)
stop = levels ? label.new(time, close, "STOP LOSS💀️ : " + str.tostring(stop_y, decimals), xloc.bar_time, yloc.price, red2, label.style_label_left, color.white, size.normal) : na
label.set_x(stop, label.get_x(stop) + math.round(ta.change(time) * lvlDistance))
label.set_y(stop, stop_y)
label.delete(stop )
plot( stop_y , title="SL" ,editable = false , color = #ffffff00)
linestop = levels and lvlLines ? line.new(bar_index - countOfCandles, stop_y, bar_index + lvlDistance ,stop_y, xloc.bar_index, extend.none,red2,stylelvl, width=lvlLinesw ) : na
line.delete(linestop ) // Corregido aquí
// FILLING
if filllvlLineson
linefill.new(linestop, lineEntry, color = color.new(color.red, filllvlLines))
ico_dir = stop_y < close ? "📈" : "📉"
// Array para almacenar las etiquetas y líneas
var label tpLabels = array.new_label(0)
var line tpLines = array.new_line(0)
//################################################################
MovingTarget_tip = "Strategy to move StopLoss (BE), when it reaches a TP / Estrategia para mover StopLoss (BE), cuando alcanza un TP "
showLabel_tip = "Show SIGNAL GENERATOR label / Mostrar etiqueta SIGNAL GENERATOR"
MovingTarget = input.int(2, title="Moving Target (BE)", minval=1,group=groupEnTpSl,inline="SignalG",tooltip=MovingTarget_tip)
showLabel = input(false, title="Showlabel Signal Generator",group=groupEnTpSl,inline="SignalG",tooltip=showLabel_tip)
tf = timeframe.period
//miSimbolo = ticker.standard(syminfo.tickerid)
//========================================================================
buy_label = ' =====SIGNAL GENERATOR====== '
buy_label := buy_label + '=========KAKUPAKAT========= '
buy_label := buy_label + ' '
buy_label := buy_label + 'COIN 🪙 : ' + '' + str.tostring(syminfo.ticker)+ ' '
buy_label := buy_label + 'TIMEFRAME ⏰ : ' + '' + str.tostring(tf)+ ' '
buy_label := buy_label + ' '
buy_label := buy_label + 'Dir: '+ str.tostring(ico_dir) + '' + (stop_y < lastTrade(close) ? 'LONG' : 'SHORT') + ' '
buy_label := buy_label + 'Entry 🚀: ' + '' + str.tostring(lastTrade(close), decimals) +' '
//*********************************************************
// Función para crear TP y líneas by CoMgUnNeR
// ¡Codigo mas simplificado da creditos al autor! me costo bastante.
//*********************************************************
// Función para crear TP y líneas
// Función para calcular potencias
pow(base, exponent) =>
var float result = 1.0
for i = 1 to exponent
result := result * base
result
var float tpValues = array.new_float(0)
// Función para crear TP y líneas
createTP(level) =>
if levels
var float tp_y = na
var string emoji = na
var color textColor = na
var color lineColor = na
var line tpLinePrev = na
if PercentOrATR == "PREDICTUM"
if level == 1
tp_y := (lastTrade(close) - lastTrade(atrStop)) * level + lastTrade(close)
else
tp_y := tp_y + (tp_y - lastTrade(close)) * 0.618
emoji := level == numTP ? "🎱🎱" : "🎱"
textColor := #000000
lineColor := #51ff00
else
tp_y := (lastTrade(close) - lastTrade(atrStop)) * level + lastTrade(close)
emoji := level == numTP ? "🎱🎱" : "🎱"
textColor := #000000
lineColor := #51ff00
tp = label.new(time, tp_y, "TP" + str.tostring(level) + ") " + str.tostring(tp_y, decimals) + " | " + emoji , xloc.bar_time , yloc.price, color=lineColor, style=label.style_label_left, textcolor=textColor, size=size.normal)
label.set_x(tp, label.get_x(tp) + math.round(ta.change(time) * lvlDistance))
array.push(tpLabels, tp)
if lvlLines
tpLine = line.new(bar_index - countOfCandles, tp_y, bar_index + lvlDistance, tp_y, xloc.bar_index, extend.none, lineColor, stylelvl, width=lvlLinesw)
array.push(tpLines, tpLine)
if array.size(tpLines) > numTP
line.delete(array.get(tpLines, 0))
array.shift(tpLines)
if filllvlLineson
if level == 1
linefill.new(lineEntry, tpLine, color = color.new(color.green, filllvlLines))
tpLinePrev := tpLine
else
linefill.new(tpLinePrev, tpLine, color = color.new(color.green, filllvlLines))
tpLinePrev := tpLine
if array.size(tpLabels) > numTP
label.delete(array.get(tpLabels, 0))
array.shift(tpLabels)
tp_y
// Crear TP y líneas basado en el input del usuario
if (bar_index > 10) // Asegurarse de que hay suficientes barras para calcular
for i = 1 to numTP
createTP(i)
// Función para crear TP y líneas
createTP2(level_info) =>
if showLabel
var float tp_y2 = na
var string emoji = na
if PercentOrATR == "PREDICTUM"
if level_info == 1
tp_y2 := (lastTrade(close) - lastTrade(atrStop)) * level_info + lastTrade(close)
else
tp_y2 := tp_y2 + (tp_y2 - lastTrade(close)) * 0.618
emoji := level_info == numTP ? "🎱🎱" : "🎱"
else
tp_y2 := (lastTrade(close) - lastTrade(atrStop)) * level_info + lastTrade(close)
emoji := level_info == numTP ? "🎱🎱" : "🎱"
// Agregar el resultado al texto de la etiqueta
'TP ' + str.tostring(level_info) + ") " + str.tostring(tp_y2, decimals) + " | "+ emoji + ' '
if (bar_index > 10)
for i = 1 to numTP
// Llamar a la función y agregar el resultado a buy_label
buy_label := buy_label + createTP2(i)
buy_label := buy_label + 'StopLoss ⛔️: ' + '' + str.tostring(stop_y, decimals) +' '
buy_label := buy_label + ' '
buy_label := buy_label + '=====Strategy====== '
buy_label := buy_label + ' '
buy_label := buy_label + 'Stop: Moving Target - '
buy_label := buy_label + ' Trigger: Target ' + str.tostring((MovingTarget))+ ' '
buy_label := buy_label + ' '
buy_label := buy_label + 'Take profit strategy: ' + str.tostring((PercentOrATR))+ ' '
buy_label := buy_label + 'Indicator: ' + str.tostring((indicator_name))+ ' '
lab_buy = label.new(bar_index - 15, showLabel ? close : na, buy_label, color=color.new(color.gray, 40), textcolor=color.white, style=label.style_label_down, yloc=yloc.abovebar, textalign=text.align_left)
// Mueve la etiqueta fuera del gráfico cuando no se muestra
//label.set_x(lab_buy, bar_index - 500)
if not showLabel
label.delete(lab_buy)
label.delete(lab_buy )
//################################################################
//*****************************************************************************
// Module - Max Profit by CoMgUnNeR
//-----------------------------------------
//*********************************************************
//* Module *
//* Max Profit *
//*********************************************************
// Cálculos idea original de CoMgUnNeR
//--------
// Grupo : Opciones del Module INFOBOX
groupmaxprofit_maxpro = "====== Max Profit ======"
// Separación visual
plot(na)
/////////////////////////////////////////////////////////////
// CONFIGURAR LAS ENTRADAS if (buy) if (sell)
/////////////////////////////////////////////////////////////
leverage_maxpro = input.int(title="Leverage x", defval=1, minval=1, maxval=125, group=groupmaxprofit_maxpro)
levelsmaxpro = input(title='Show Labels Max Profit / Mostrar Etiquetas Max Profit', defval=false)
yposmaxpro = input.int(title="Y Label Position Max Profit", defval=1, minval=1, maxval=10)
lux_maxpro = #2157f370 //#ff5d0070 //#2157f370 //
var float longHigh_maxpro = 0.0
var label longLabel_maxpro = na
var label shortLabel_maxpro = na
var float entryPrice_maxpro = na
var float exitPrice_maxpro = na
var float peakProfit_maxpro = na
var string peakProfitString_maxpro = ""
var float shortLow_maxpro = na
if (bull)
shortLabel_maxpro := na
longHigh_maxpro := high
if levelsmaxpro == true
longLabel_maxpro := label.new(bar_index, high, str.tostring(high), color=lux_maxpro, textcolor=color.white)
// Guardar el precio de entrada al abrir una posición larga
entryPrice_maxpro := close
if (high > longHigh_maxpro)
longHigh_maxpro := high
longLabel_maxpro.set_x(bar_index + yposmaxpro)
longLabel_maxpro.set_text(str.tostring(high))
longLabel_maxpro.set_y(high)
if (bear)
longLabel_maxpro := na
shortLow_maxpro := low
if levelsmaxpro == true
shortLabel_maxpro := label.new(bar_index, low, str.tostring(low), style=label.style_label_up, color=lux_maxpro, textcolor=color.white)
// Guardar el precio de entrada al abrir una posición corta
entryPrice_maxpro := close
if (low < shortLow_maxpro)
shortLow_maxpro := low
shortLabel_maxpro.set_x(bar_index + yposmaxpro)
shortLabel_maxpro.set_text(str.tostring(low))
shortLabel_maxpro.set_y(low)
// Calcular el porcentaje de Peak Profit al cerrar la posición
if (na(entryPrice_maxpro) == false)
// Guardar el precio de salida al cerrar la posición
exitPrice_maxpro := close
// Calcular el Peak Profit como porcentaje
peakProfit_maxpro := (((math.abs(exitPrice_maxpro - entryPrice_maxpro)) / entryPrice_maxpro) * 100) * leverage_maxpro
peakProfitString_maxpro := str.tostring(math.round(peakProfit_maxpro, 2))
// Mostrar el Peak Profit en la etiqueta correspondiente
if (na(shortLabel_maxpro) == false)
label.set_text(shortLabel_maxpro, "Peak Profit: " + peakProfitString_maxpro + "%")
else
label.set_text(longLabel_maxpro, "Peak Profit: " + peakProfitString_maxpro + "%")
//*****************************************************************************
//MODO FACIL SIN PERSONALIZACION
//import protradingart/pta_plot/6 as pp
//pp.peakprofit(buy, sell)
//https://www.tradingview.com/script/Bcm0mGop-pta-plot/
//Instruction: Don't forget to add ,max_labels_count=500, max_bars_back=500
//*****************************************************************************
//
//SETTINGS
//
// INDICATOR SETTINGS
swing_length = input.int(10, title = 'Swing High/Low Length', group = 'Settings', minval = 1, maxval = 50)
history_of_demand_to_keep = input.int(20, title = 'History To Keep', minval = 5, maxval = 50)
box_width = input.float(2.5, title = 'Supply/Demand Box Width', group = 'Settings', minval = 1, maxval = 10, step = 0.5)
// INDICATOR VISUAL SETTINGS
show_zigzag = input.bool(false, title = 'Show Zig Zag', group = 'Visual Settings', inline = '1')
show_price_action_labels = input.bool(false, title = 'Show Price Action Labels', group = 'Visual Settings', inline = '2')
supply_color = input.color(color.new(#EDEDED,70), title = 'Supply', group = 'Visual Settings', inline = '3')
supply_outline_color = input.color(color.new(color.white,75), title = 'Outline', group = 'Visual Settings', inline = '3')
demand_color = input.color(color.new(#00FFFF,70), title = 'Demand', group = 'Visual Settings', inline = '4')
demand_outline_color = input.color(color.new(color.white,75), title = 'Outline', group = 'Visual Settings', inline = '4')
bos_label_color = input.color(color.white, title = 'BOS Label', group = 'Visual Settings', inline = '5')
poi_label_color = input.color(color.white, title = 'POI Label', group = 'Visual Settings', inline = '7')
swing_type_color = input.color(color.black, title = 'Price Action Label', group = 'Visual Settings', inline = '8')
zigzag_color = input.color(color.new(#000000,0), title = 'Zig Zag', group = 'Visual Settings', inline = '9')
//
//END SETTINGS
//
//
//FUNCTIONS
//
// FUNCTION TO ADD NEW AND REMOVE LAST IN ARRAY
f_array_add_pop(array, new_value_to_add) =>
array.unshift(array, new_value_to_add)
array.pop(array)
// FUNCTION SWING H & L LABELS
f_sh_sl_labels(array, swing_type) =>
var string label_text = na
if swing_type == 1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HH'
else
label_text := 'LH'
label.new(bar_index - swing_length, array.get(array,0), text = label_text, style=label.style_label_down, textcolor = swing_type_color, color = color.new(swing_type_color, 100), size = size.tiny)
else if swing_type == -1
if array.get(array, 0) >= array.get(array, 1)
label_text := 'HL'
else
label_text := 'LL'
label.new(bar_index - swing_length, array.get(array,0), text = label_text, style=label.style_label_up, textcolor = swing_type_color, color = color.new(swing_type_color, 100), size = size.tiny)
// FUNCTION MAKE SURE SUPPLY ISNT OVERLAPPING
f_check_overlapping(new_poi, box_array, atr) =>
atr_threshold = atr * 2
okay_to_draw = true
for i = 0 to array.size(box_array) - 1
top = box.get_top(array.get(box_array, i))
bottom = box.get_bottom(array.get(box_array, i))
poi = (top + bottom) / 2
upper_boundary = poi + atr_threshold
lower_boundary = poi - atr_threshold
if new_poi >= lower_boundary and new_poi <= upper_boundary
okay_to_draw := false
break
else
okay_to_draw := true
okay_to_draw
// FUNCTION TO DRAW SUPPLY OR DEMAND ZONE
f_supply_demand(value_array, bn_array, box_array, label_array, box_type, atr) =>
atr_buffer = atr * (box_width / 10)
box_left = array.get(bn_array, 0)
box_right = bar_index
var float box_top = 0.00
var float box_bottom = 0.00
var float poi = 0.00
if box_type == 1
box_top := array.get(value_array, 0)
box_bottom := box_top - atr_buffer
poi := (box_top + box_bottom) / 2
else if box_type == -1
box_bottom := array.get(value_array, 0)
box_top := box_bottom + atr_buffer
poi := (box_top + box_bottom) / 2
okay_to_draw = f_check_overlapping(poi, box_array, atr)
// okay_to_draw = true
//delete oldest box, and then create a new box and add it to the array
if box_type == 1 and okay_to_draw
box.delete( array.get(box_array, array.size(box_array) - 1) )
f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right = box_right, bottom = box_bottom, border_color = supply_outline_color,
bgcolor = supply_color, extend = extend.right, text = 'SUPPLY', text_halign = text.align_center, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index))
box.delete( array.get(label_array, array.size(label_array) - 1) )
f_array_add_pop(label_array, box.new( left = box_left, top = poi, right = box_right, bottom = poi, border_color = color.new(poi_label_color,90),
bgcolor = color.new(poi_label_color,90), extend = extend.right, text = 'POI', text_halign = text.align_left, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index))
else if box_type == -1 and okay_to_draw
box.delete( array.get(box_array, array.size(box_array) - 1) )
f_array_add_pop(box_array, box.new( left = box_left, top = box_top, right = box_right, bottom = box_bottom, border_color = demand_outline_color,
bgcolor = demand_color, extend = extend.right, text = 'DEMAND', text_halign = text.align_center, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index))
box.delete( array.get(label_array, array.size(label_array) - 1) )
f_array_add_pop(label_array, box.new( left = box_left, top = poi, right = box_right, bottom = poi, border_color = color.new(poi_label_color,90),
bgcolor = color.new(poi_label_color,90), extend = extend.right, text = 'POI', text_halign = text.align_left, text_valign = text.align_center, text_color = poi_label_color, text_size = size.small, xloc = xloc.bar_index))
// FUNCTION TO CHANGE SUPPLY/DEMAND TO A BOS IF BROKEN
f_sd_to_bos(box_array, bos_array, label_array, zone_type) =>
if zone_type == 1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_top(array.get(box_array,i))
// if ta.crossover(close, level_to_break)
if close >= level_to_break
copied_box = box.copy(array.get(box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top(array.get(box_array,i)) + box.get_bottom(array.get(box_array,i))) / 2
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.set_extend( array.get(bos_array,0), extend.none)
box.set_right( array.get(bos_array,0), bar_index)
box.set_text( array.get(bos_array,0), 'BOS' )
box.set_text_color( array.get(bos_array,0), bos_label_color)
box.set_text_size( array.get(bos_array,0), size.small)
box.set_text_halign( array.get(bos_array,0), text.align_center)
box.set_text_valign( array.get(bos_array,0), text.align_center)
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))
if zone_type == -1
for i = 0 to array.size(box_array) - 1
level_to_break = box.get_bottom(array.get(box_array,i))
// if ta.crossunder(close, level_to_break)
if close <= level_to_break
copied_box = box.copy(array.get(box_array,i))
f_array_add_pop(bos_array, copied_box)
mid = (box.get_top(array.get(box_array,i)) + box.get_bottom(array.get(box_array,i))) / 2
box.set_top(array.get(bos_array,0), mid)
box.set_bottom(array.get(bos_array,0), mid)
box.set_extend( array.get(bos_array,0), extend.none)
box.set_right( array.get(bos_array,0), bar_index)
box.set_text( array.get(bos_array,0), 'BOS' )
box.set_text_color( array.get(bos_array,0), bos_label_color)
box.set_text_size( array.get(bos_array,0), size.small)
box.set_text_halign( array.get(bos_array,0), text.align_center)
box.set_text_valign( array.get(bos_array,0), text.align_center)
box.delete(array.get(box_array, i))
box.delete(array.get(label_array, i))
// FUNCTION MANAGE CURRENT BOXES BY CHANGING ENDPOINT
f_extend_box_endpoint(box_array) =>
for i = 0 to array.size(box_array) - 1
box.set_right(array.get(box_array, i), bar_index + 100)
//
//END FUNCTIONS
//
//
//CALCULATIONS
//
// CALCULATE ATR
atr = ta.atr(50)
// CALCULATE SWING HIGHS & SWING LOWS
swing_high = ta.pivothigh(high, swing_length, swing_length)
swing_low = ta.pivotlow(low, swing_length, swing_length)
// ARRAYS FOR SWING H/L & BN
var swing_high_values = array.new_float(5,0.00)
var swing_low_values = array.new_float(5,0.00)
var swing_high_bns = array.new_int(5,0)
var swing_low_bns = array.new_int(5,0)
// ARRAYS FOR SUPPLY / DEMAND
var current_supply_box = array.new_box(history_of_demand_to_keep, na)
var current_demand_box = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR SUPPLY / DEMAND POI LABELS
var current_supply_poi = array.new_box(history_of_demand_to_keep, na)
var current_demand_poi = array.new_box(history_of_demand_to_keep, na)
// ARRAYS FOR BOS
var supply_bos = array.new_box(5, na)
var demand_bos = array.new_box(5, na)
//
//END CALCULATIONS
//
// NEW SWING HIGH
if not na(swing_high)
//MANAGE SWING HIGH VALUES
f_array_add_pop(swing_high_values, swing_high)
f_array_add_pop(swing_high_bns, bar_index )
if show_price_action_labels
f_sh_sl_labels(swing_high_values, 1)
f_supply_demand(swing_high_values, swing_high_bns, current_supply_box, current_supply_poi, 1, atr)
// NEW SWING LOW
else if not na(swing_low)
//MANAGE SWING LOW VALUES
f_array_add_pop(swing_low_values, swing_low)
f_array_add_pop(swing_low_bns, bar_index )
if show_price_action_labels
f_sh_sl_labels(swing_low_values, -1)
f_supply_demand(swing_low_values, swing_low_bns, current_demand_box, current_demand_poi, -1, atr)
f_sd_to_bos(current_supply_box, supply_bos, current_supply_poi, 1)
f_sd_to_bos(current_demand_box, demand_bos, current_demand_poi, -1)
f_extend_box_endpoint(current_supply_box)
f_extend_box_endpoint(current_demand_box)
//ZIG ZAG
h = ta.highest(high, swing_length * 2 + 1)
l = ta.lowest(low, swing_length * 2 + 1)
f_isMin(len) =>
l == low
f_isMax(len) =>
h == high
var dirUp = false
var lastLow = high * 100
var lastHigh = 0.0
var timeLow = bar_index
var timeHigh = bar_index
var line li = na
f_drawLine() =>
_li_color = show_zigzag ? zigzag_color : color.new(#ffffff,100)
line.new(timeHigh - swing_length, lastHigh, timeLow - swing_length, lastLow, xloc.bar_index, color=_li_color, width=2)
if dirUp
if f_isMin(swing_length) and low < lastLow
lastLow := low
timeLow := bar_index
line.delete(li)
li := f_drawLine()
li
if f_isMax(swing_length) and high > lastLow
lastHigh := high
timeHigh := bar_index
dirUp := false
li := f_drawLine()
li
if not dirUp
if f_isMax(swing_length) and high > lastHigh
lastHigh := high
timeHigh := bar_index
line.delete(li)
li := f_drawLine()
li
if f_isMin(swing_length) and low < lastHigh
lastLow := low
timeLow := bar_index
dirUp := true
li := f_drawLine()
if f_isMax(swing_length) and high > lastLow
lastHigh := high
timeHigh := bar_index
dirUp := false
li := f_drawLine()
li
// if barstate.islast
// label.new(x = bar_index + 10, y = close , text = str.tostring( array.size(current_supply_poi) ))
// label.new(x = bar_index + 20, y = close , text = str.tostring( box.get_bottom( array.get(current_supply_box, 0))))
// label.new(x = bar_index + 30, y = close , text = str.tostring( box.get_bottom( array.get(current_supply_box, 1))))
// label.new(x = bar_index + 40, y = close , text = str.tostring( box.get_bottom( array.get(current_supply_box, 2))))
// label.new(x = bar_index + 50, y = close , text = str.tostring( box.get_bottom( array.get(current_supply_box, 3))))
// label.new(x = bar_index + 60, y = close , text = str.tostring( box.get_bottom( array.get(current_supply_box, 4))))
// ==========================================================================================
// ==========================================================================================