0% found this document useful (0 votes)
168 views6 pages

11111

The document is a TradingView Pine Script for a trading indicator called 'TradeGenius Scalp V1.0', which includes functions for calculating true range, trend detection, and Fibonacci levels. It also features alert conditions for various trading signals based on price movements relative to Fibonacci levels and trend changes. Additionally, it incorporates Heikin Ashi candle calculations and provides options for customizing alerts.

Uploaded by

qahhnnaarin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
168 views6 pages

11111

The document is a TradingView Pine Script for a trading indicator called 'TradeGenius Scalp V1.0', which includes functions for calculating true range, trend detection, and Fibonacci levels. It also features alert conditions for various trading signals based on price movements relative to Fibonacci levels and trend changes. Additionally, it incorporates Heikin Ashi candle calculations and provides options for customizing alerts.

Uploaded by

qahhnnaarin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//@version=5

indicator(title="TradeGenius Scalp V1.0", shorttitle="TradeGenius Scalp",


overlay=true)
//---------------------- Engulfing ------------------------------
//barcolor(open[1] > close[1] ? close > open ? close >= open[1] ? close[1] >=
open ? close - open > open[1] ? color.yellow :na :na : na : na : na)
//-----------------------------------------------------------------

var timeF = timeframe.period


getResolution(tf) =>
switch tf
'1' => '3'
'3' => '5'
'5' => '15'
'15'=> '30'
'30'=> '45'
'45'=> '60'
'60'=> '120'
'120'=> '180'
'180'=> '240'
'240'=> 'D'
'D'=> 'W'
'W'=> 'M'

var atrP = 10
var atrF = 5

res = getResolution(timeF)

var int ATRPer = 0


var int ATRFac = 0

if timeF == '45'
ATRPer := 12
ATRFac := 12
else if timeF == '15'
ATRPer := 10
ATRFac := 4
else
ATRPer := 10
ATRFac := 5

manualFts = input.bool(false, title = 'use manual FTS')


ATRPeriod = manualFts ? input.int(15, title = 'ATRPeriod') : ATRPer
ATRFactor = manualFts ? input.int(15, title = 'ATRFactor') : ATRFac

norm_o = request.security(ticker.new(syminfo.prefix, syminfo.ticker), res, open)


norm_h = request.security(ticker.new(syminfo.prefix, syminfo.ticker), res, high)
norm_l = request.security(ticker.new(syminfo.prefix, syminfo.ticker), res, low)
norm_c = request.security(ticker.new(syminfo.prefix, syminfo.ticker), res, close)

Wild_ma(_src, _malength) =>


_wild = 0.0
_wild := nz(_wild[1]) + (_src - nz(_wild[1])) / _malength
_wild

/////////// TRUE RANGE CALCULATIONS /////////////////


HiLo = math.min(norm_h - norm_l, 1.5 * nz(ta.sma(norm_h - norm_l, ATRPeriod)))
HRef = norm_l <= norm_h[1] ? norm_h - norm_c[1] : norm_h - norm_c[1] - 0.5 *
(norm_l - norm_h[1])

LRef = norm_h >= norm_l[1] ? norm_c[1] - norm_l : norm_c[1] - norm_l - 0.5 *


(norm_l[1] - norm_h)

trueRange = math.max(HiLo, HRef, LRef)

loss = ATRFactor * Wild_ma(trueRange, ATRPeriod)

Up = norm_c - loss
Dn = norm_c + loss

TrendUp = Up
TrendDown = Dn
Trend = 1

TrendUp := norm_c[1] > TrendUp[1] ? math.max(Up, TrendUp[1]) : Up


TrendDown := norm_c[1] < TrendDown[1] ? math.min(Dn, TrendDown[1]) : Dn

Trend := norm_c > TrendDown[1] ? 1 : norm_c < TrendUp[1] ? -1 : nz(Trend[1], 1)


trail = Trend == 1 ? TrendUp : TrendDown

ex = 0.0
ex := ta.crossover(Trend, 0) ? norm_h : ta.crossunder(Trend, 0) ? norm_l : Trend ==
1 ? math.max(ex[1], norm_h) : Trend == -1 ? math.min(ex[1], norm_l) : ex[1]

state = Trend == 1 ? 'long' : 'short'

fib1Level = 61.8
fib2Level = 78.6
fib3Level = 88.6

f1 = ex + (trail - ex) * fib1Level / 100


f2 = ex + (trail - ex) * fib2Level / 100
f3 = ex + (trail - ex) * fib3Level / 100
l100 = trail + 0

Fib1 = plot(f1, 'Fib 1', style=plot.style_line, color=color.new(color.gray, 0))


Fib2 = plot(f2, 'Fib 2', style=plot.style_line, color=color.new(color.gray, 0))
Fib3 = plot(f3, 'Fib 3', style=plot.style_line, color=color.new(color.lime, 0))
L100 = plot(l100, 'l100', style=plot.style_line, color=color.rgb(120, 123, 134))

fill(Fib3, L100, color=state == 'long' ? color.new(color.green, 12) : state ==


'short' ? color.new(color.red, 12) : na)

changcDir = ta.cross(f3,l100)
alertcondition(changcDir, title="Alert: FTS Direction Change", message="FTS has
changed direction!")

l1 = state[1] == "long" and ta.crossunder(norm_c, f1[1])


l2 = state[1] == "long" and ta.crossunder(norm_c, f2[1])
l3 = state[1] == "long" and ta.crossunder(norm_c, f3[1])
s1 = state[1] == "short" and ta.crossover(norm_c, f1[1])
s2 = state[1] == "short" and ta.crossover(norm_c, f2[1])
s3 = state[1] == "short" and ta.crossover(norm_c, f3[1])

atr = ta.sma(trueRange, 14)


//////////// FIB ALERTS /////////////////////

alertcondition(l1, title = "cross over Fib1", message = "Price crossed below Fib1
level in long trend")
alertcondition(l2, title = "cross over Fib2", message = "Price crossed below Fib2
level in long trend")
alertcondition(l3, title = "cross over Fib3", message = "Price crossed below Fib3
level in long trend")
alertcondition(s1, title = "cross under Fib1", message = "Price crossed above Fib1
level in short trend")
alertcondition(s2, title = "cross under Fib2", message = "Price crossed above Fib2
level in short trend")
alertcondition(s3, title = "cross under Fib3", message = "Price crossed above Fib3
level in short trend")

alertcondition(fixnan(f1)!=fixnan(f1[1]), title = "Stop Line Change", message =


"Stop Line Change")

//indicator(title='Market Bias (CEREBR)', shorttitle='Market Bias', overlay=true)

//#region -----> INPUTS, FUCNTIONS

// FUNCTIONS
//@function This function forces the current timeframe on inputs that shouldn't
take lower timeframes
FORCE_CTF(str_tf) =>
i_tf_sec = timeframe.in_seconds(str_tf)
ctf_sec = timeframe.in_seconds('')

// Returns the CTF if the passed timeframe is lower


i_tf_sec < ctf_sec ? '' : str_tf
//

// INPUTS
ha_htf = FORCE_CTF(input.timeframe('', 'Timeframe', tooltip="This timeframe must be
equal to or greater than the chart's timeframe", group="HA Market Bias"))
ha_len = input(100, 'Period', group="HA Market Bias")
ha_len2 = input(100, 'Smoothing', group="HA Market Bias")

show_ha = input.bool(true, "Show HA Candles", inline='ha/mb display',


group='Display Settings')
show_mb = input.bool(true, "Show Market Bias", inline='ha/mb display',
group='Display Settings')
col_bull = input.color(color.lime, 'Color: Bullish', inline='bull/bear color',
group='Display Settings', display=display.none)
col_bear = input.color(color.red, 'Bearish', inline='bull/bear color',
group='Display Settings', display=display.none)
// These add an offset during data importation to avoid lookahead bias
indexHighTF = timeframe.in_seconds(ha_htf) == timeframe.in_seconds('') ? 0 :
barstate.isrealtime ? 1 : 0
indexCurrTF = timeframe.in_seconds(ha_htf) == timeframe.in_seconds('') ? 0 :
barstate.isrealtime ? 0 : 1

//@function Handles the import of data from other timeframes, while preventing
repainting
//@param _resolution (str) : This is the timeframe to import data from.
//@param _expression (float | int) : This is the data to be imported
f_no_repaint_request(string _resolution, _expression) =>
request.security(syminfo.tickerid, _resolution, _expression[indexHighTF])
[indexCurrTF]
//#endregion

//#region -----> CALCULATIONS

// Smoothen the OHLC values


o = ta.ema(open, ha_len)
c = ta.ema(close, ha_len)
h = ta.ema(high, ha_len)
l =ta.ema(low, ha_len)

// Calculate the Heikin Ashi OHLC values from it


haclose = f_no_repaint_request(ha_htf, (o + h + l + c) / 4)
xhaopen = f_no_repaint_request(ha_htf, (o + c) / 2)
haopen = na(xhaopen[1]) ? (o + c) / 2 : (xhaopen[1] + haclose[1]) / 2
hahigh = math.max(h, math.max(haopen, haclose))
halow = math.min(l, math.min(haopen, haclose))

// Smoothen the Heiken Ashi Candles


o2 = f_no_repaint_request(ha_htf, ta.ema(haopen, ha_len2))
c2 = f_no_repaint_request(ha_htf, ta.ema(haclose, ha_len2))
h2 = f_no_repaint_request(ha_htf, ta.ema(hahigh, ha_len2))
l2_new = f_no_repaint_request(ha_htf, ta.ema(halow, ha_len2))

ha_avg = (h2 + l2_new) / 2

//TODO: Publish the Oscillator version of the indicator


// Oscillator {
osc_len = input.int(7, "Oscillator Period", group="HA Market Bias")

osc_bias = 100 * (c2 - o2)


osc_smooth = ta.ema(osc_bias, osc_len)

sigcolor = switch
(osc_bias > 0) and (osc_bias >= osc_smooth) => color.new(col_bull, 35)
(osc_bias > 0) and (osc_bias < osc_smooth) => color.new(col_bull, 75)
(osc_bias < 0) and (osc_bias <= osc_smooth) => color.new(col_bear, 35)
(osc_bias < 0) and (osc_bias > osc_smooth) => color.new(col_bear, 75)
=> color(na)
// }

//#endregion

//#region -----> PLOTS, ALERTS {


// Plots
p_h = plot(h2, "Bias High", color=color(na), display=display.data_window,
editable=false)
p_l = plot(l2_new, "Bias Low", color=color(na), display=display.data_window,
editable=false)
p_avg = plot(ha_avg, "Bias Avergae", color=color(na), display=display.data_window,
editable=false)
fill(p_l, p_h, show_mb ? sigcolor : na)

col = o2 > c2 ? col_bear : col_bull


plotcandle(o2, h2, l2_new, c2, title='heikin smoothed', color=col,
display=show_ha ? display.pane : display.data_window, editable=false)

// Alerts
// Bullish Trend Switch (Bearish -> Bullish)
alertcondition(ta.change(ta.change(math.sign(osc_bias)) > 0), 'Bullish Trend Switch
(Bearish -> Bullish)', '{{exchange}}:{{ticker}}: Trend is now Bullish.')

// Bullish Trend Strengthens


alertcondition(osc_bias > 0 and ta.change(math.sign(osc_bias - osc_smooth)) > 0,
'Bullish Trend Strengthens', '{{exchange}}:{{ticker}}: Bullish Trend is now
Stronger.')

// Bullish Trend Weakens


alertcondition(osc_bias > 0 and ta.change(math.sign(osc_bias - osc_smooth)) < 0,
'Bullish Trend Weakens', '{{exchange}}:{{ticker}}: Bullish Trend is now Weaker.')

// Bearish Trend Switch (Bullish -> Bearish)


alertcondition(ta.change(ta.change(math.sign(osc_bias)) < 0), 'Bearish Trend Switch
(Bullish -> Bearish)', '{{exchange}}:{{ticker}}: Trend is now Bearish.')

// Bearish Trend Strengthens


alertcondition(osc_bias < 0 and ta.change(math.sign(osc_bias - osc_smooth)) < 0,
'Bearish Trend Strengthens', '{{exchange}}:{{ticker}}: Bearish Trend is now
Stronger.')

// Bearish Trend Weakens


alertcondition(osc_bias < 0 and ta.change(math.sign(osc_bias - osc_smooth)) > 0,
'Bearish Trend Weakens', '{{exchange}}:{{ticker}}: Bearish Trend is now Weaker.')
//#endregion

// CUSTOM ALERTS : To enable this functionality, Select and uncomment (Cmd (or
Ctrl) + /) the following code block, starting from the next line.
// // {
// use_custom_alerts = input.bool(false, ‘Use Custom Alert Messages’, group=‘Alert
Messages’, display=display.none)
// i_alert_bull_trend_switch = input.text_area(‘New Bullish Trend’, ‘Bullish Trend
Switch’, group=‘Alert Messages’, display=display.none)
// i_alert_bull_trend_strengthen = input.text_area(‘New Strong Bullish Trend’,
‘Bullish Trend Strengthens’, group=‘Alert Messages’, display=display.none)
// i_alert_bull_trend_weaken = input.text_area(‘New Weak Bullish Trend’, ‘Bullish
Trend Weakens’, group=‘Alert Messages’, display=display.none)
// i_alert_bear_trend_switch = input.text_area(‘New Bearish Trend’, ‘Bearish Trend
Switch’, group=‘Alert Messages’, display=display.none)
// i_alert_bear_trend_strengthen = input.text_area(‘New Strong Bearish Trend’,
‘Bearish Trend Strengthens’, group=‘Alert Messages’, display=display.none)
// i_alert_bear_trend_weaken = input.text_area(‘New Weak Bearish Trend’, ‘Bearish
Trend Weakens’, group=‘Alert Messages’, display=display.none)
// // Bullish Trend Switch (Bearish -> Bullish)
// if (ta.change(ta.change(math.sign(osc_bias)) > 0))
// alert(i_alert_bull_trend_switch, alert.freq_once_per_bar)

// // Bullish Trend Strengthens


// if (osc_bias > 0 and ta.change(math.sign(osc_bias - osc_smooth)) > 0)
// alert(i_alert_bull_trend_strengthen, alert.freq_once_per_bar)

// // Bullish Trend Weakens


// if (osc_bias > 0 and ta.change(math.sign(osc_bias - osc_smooth)) < 0)
// alert(i_alert_bull_trend_weaken, alert.freq_once_per_bar)

// // Bearish Trend Switch (Bullish -> Bearish)


// if (ta.change(ta.change(math.sign(osc_bias)) < 0))
// alert(i_alert_bear_trend_switch, alert.freq_once_per_bar)

// // Bearish Trend Strengthens


// if (osc_bias < 0 and ta.change(math.sign(osc_bias - osc_smooth)) < 0)
// alert(i_alert_bear_trend_strengthen, alert.freq_once_per_bar)

// // Bearish Trend Weakens


// if (osc_bias < 0 and ta.change(math.sign(osc_bias - osc_smooth)) > 0)
// alert(i_alert_bear_trend_weaken, alert.freq_once_per_bar)

// // }

You might also like