0% found this document useful (0 votes)
242 views5 pages

Gold Trading Indicator Script

Jason Main Gold indicator

Uploaded by

surendracommon
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)
242 views5 pages

Gold Trading Indicator Script

Jason Main Gold indicator

Uploaded by

surendracommon
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
  • Indicator Initialization
  • RSI Calculation
  • Conditions and Signals
  • Function Plots
  • Alert Conditions

//@version=5

indicator(title="JASON XAUUSD 15mins 2/2", overlay=true)

len = [Link](60, "VWAP Length", minval=1)


width = [Link](0.01, "Zone Width", step=0.001, minval=0)

vwap = [Link](hlc3)
plot(vwap, "VWAP", color=[Link], transp=100)

upcross = [Link](close, vwap)


downcross = [Link](close, vwap)

prev_close = [Link](upcross or downcross, close, 1)


prev_vwap = [Link](upcross or downcross, vwap, 1)

supply_zone = prev_close > prev_vwap and close < prev_vwap


demand_zone = prev_close < prev_vwap and close > prev_vwap

// Colored zones
bgcolor(supply_zone ? [Link] : demand_zone ? [Link] : na, transp=100)

// Alert when price enters a supply or demand zone


alertcondition(supply_zone, title="Supply Zone", message="Price has entered a
supply zone")
alertcondition(demand_zone, title="Demand Zone", message="Price has entered a
demand zone")

//////////////////////////////
////////////////////////////////

length1 = [Link](20,'CCI length', minval=1, group="CCI Settings")


src1 = input(hlc3, title="Source" , group="CCI Settings")
ma = [Link](src1, length1)
cci = (src1 - ma) / (0.015 * [Link](src1, length1))

band0 = [Link](-100, "Lower Band" , group="CCI Settings")


band1 = [Link](100, "Upper Band" , group="CCI Settings")
band2= [Link](-150, "Lower Low Band" , group="CCI Settings")
band3= [Link](150, "Upper up Band" , group="CCI Settings")

ma(source1, length1, type) =>


switch type
"SMA" => [Link](source1, length1)
"EMA" => [Link](source1, length1)
"SMMA (RMA)" => [Link](source1, length1)
"WMA" => [Link](source1, length1)
"VWMA" => [Link](source1, length1)
timeframe1= [Link]('15','First CCI timeframe' , group="CCI Timeframe
Settings")
timeframe2= [Link]('60','second CCI timeframe' , group="CCI Timeframe
Settings")

CCI1= [Link]([Link], timeframe1 ,cci,gaps = barmerge.gaps_off)


plot(CCI1, join= true,display= [Link])
CCI2= [Link]([Link], timeframe2,cci,gaps = barmerge.gaps_off)
plot(CCI2, join= true,display= [Link])

///RSI

rsiLengthInput = [Link](14, minval=1, title="RSI Length", group="RSI Settings")


rsiSourceInput = [Link](close, "Source", group="RSI Settings")
maTypeInput = [Link]("SMA", title="MA Type", options=["SMA", "Bollinger
Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="RSI MA Settings")
maLengthInput = [Link](14, title="MA Length", group="RSI MA Settings")
bbMultInput = [Link](2.0, minval=0.001, maxval=50, title="BB StdDev",
group="RSI MA Settings")

up = [Link]([Link]([Link](rsiSourceInput), 0), rsiLengthInput)


down = [Link](-[Link]([Link](rsiSourceInput), 0), rsiLengthInput)
rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
rsiMA = ma(rsi, maLengthInput, maTypeInput)
isBB = maTypeInput == "Bollinger Bands"

timeframe=[Link]('15', "RSI timeframe", group="RSI Settings")


rsi15= [Link]([Link], timeframe,rsi)

plot(rsi, "RSI", color=#7E57C2, display = [Link])


plot(rsiMA, "RSI-based MA", color=[Link], display = [Link])
rsiUpperBand = [Link](65, "RSI Upper Band", group="OverBought/OverSold
Settings")
midline=[Link](50, "RSI Middle Band", group="OverBought/OverSold Settings")
rsiLowerBand = [Link](35, "RSI Lower Band", group="OverBought/OverSold
Settings")
bbUpperBand = plot(isBB ? rsiMA + [Link](rsi, maLengthInput) * bbMultInput : na,
title = "Upper Bollinger Band", color=[Link], display = [Link])
bbLowerBand = plot(isBB ? rsiMA - [Link](rsi, maLengthInput) * bbMultInput : na,
title = "Lower Bollinger Band", color=[Link], display = [Link])
fill(bbUpperBand, bbLowerBand, color= isBB ? [Link]([Link], 90) : na,
title="Bollinger Bands Background Fill", display = [Link])

cross= [Link](cci,band0)

// Condition
signal_buy = false
signal_sell = false
if CCI1 < band0 and CCI2 < band2 and rsiMA < rsiLowerBand and rsi15 < midline
signal_buy := true

if CCI1 > band1 and CCI2 > band3 and rsiMA > rsiUpperBand and rsi15 > midline
signal_sell := true

// Plotshapes
plotshape(signal_sell, title="Sell", style=[Link], color=[Link](255,
0, 0, 50), size=[Link], location=[Link], text="Take Profit",
textcolor=[Link](56, 90, 202))
plotshape(signal_buy, title="Buy", style=[Link], color=[Link](0, 255,
0, 50), size=[Link], location=[Link], text="Take Profit",
textcolor=[Link])

//------------------------------------------------------------------------------
// Indicator, Library Import & User Inputs
//------------------------------------------------------------------------------

// Time Zone notation :


// IANA time zone database name (e.g., "continent/city")
// UTC/GMT notation (e.g., "UTC-5", "GMT+0530"), were +- are the STD offsets from
UTC time

time_NY = [Link](true, title = "plot NEW YORK session")


time_GMT = [Link](false, title = "plot LONDON session")
// custom session
time_ctm = [Link](true, title = "plot CUSTOM session")
// to change time , edit the "1200-1201,1500-1501:1234567" session argument
ctm_session = [Link]("1200-1201,1500-1501:1234567", title = "User defined
Sesssion",
tooltip = "This is idealy used to identify you custom trading session more
clearly on the chart, rather than manually ploting vertical lines from the drawing
pannel." + "\n" +
"Note To change this defualt custom trading session you must edit the defualt
trading session in the script",
options = ["1200-1201,1500-1501:1234567", "1100-1101,1400-
1401:1234567" ,"1300-1301,1600-1601:1234567"])

//------------------------------------------------------------------------------
// Function construction / definitions
//------------------------------------------------------------------------------
string IANA_NY = "America/New_York" // UTC offset DST - 4:00
string IANA_GMT = "Europe/London" // UTC offset DST + 1:00

ctm_time_session(chart_tfm, ses_ ,IANA_) =>


not na(time(chart_tfm, ses_, IANA_)) ? true : false

// NY
NY = ctm_time_session([Link], "0730-1200", IANA_NY)
bool NY_new_ses = time_NY == true and NY
//------------------------------------------------------------------------------
// Function plots
//------------------------------------------------------------------------------
bgcolor(NY_new_ses ? [Link](#dad9d2, 44) : na, title = "NY", editable = true)

// ATR Trailing Stop Loss Indicator

atr_p_inp = [Link](5, 'ATR length', 1, 1000000, 1)


atr_m_inp = [Link](3.5, 'ATR mult.', 0.01, 1000000, 0.05)
gold_ent = [Link](true, 'Gold Entry Directional Confluence', tooltip = 'Requirs
Gold Sell Signals To Be On A Red Bar And Gold Buy Signal To Be On A Green Bar')
atr = [Link](atr_p_inp)
ts = atr_m_inp * atr

float atr_ts = na
if (close > nz(atr_ts[1], 0)) and (close[1] > nz(atr_ts[1], 0))
atr_ts := ([Link](nz(atr_ts[1]), close - ts))
else
if (close < nz(atr_ts[1], 0)) and (close[1] < nz(atr_ts[1], 0))
atr_ts := ([Link](nz(atr_ts[1]), close + ts))
else
if (close > nz(atr_ts[1], 0))
atr_ts := (close - ts)
else
atr_ts := (close + ts)

float pos = na
if (close[1] < nz(atr_ts[1], 0)) and (close > nz(atr_ts[1], 0))
pos := (1)
else
if (close[1] > nz(atr_ts[1], 0)) and (close < nz(atr_ts[1], 0))
pos := (-1)
else
pos := (nz(pos[1], 0))

color _color = na
if (pos == -1)
_color := ([Link])
else
if (pos == 1)
_color := ([Link])
else
_color := ([Link])

plot (atr_ts, color=_color, title="ATR Trailing Stop")


plotshape (pos, 'UP/DOWN', location = [Link], color = _color)

long_trig = (close < atr_ts)[1] and (close > atr_ts)


shrt_trig = (close > atr_ts)[1] and (close < atr_ts)
long_gold = (close > atr_ts) and (low < atr_ts) and not ((close > atr_ts) and
(low < atr_ts))[1] and (gold_ent == true ? (close > open) : true)
shrt_gold = (close < atr_ts) and (high > atr_ts) and not ((close < atr_ts) and
(high > atr_ts))[1] and (gold_ent == true ? (close < open) : true)
plotshape (long_trig, 'Long', [Link], [Link],
[Link], size = [Link])
plotshape (shrt_trig, 'Short', [Link], [Link],
[Link], size = [Link])
plotshape (long_gold, 'Gold Long', [Link], [Link],
[Link], size = [Link])
plotshape (shrt_gold, 'Gold Short', [Link], [Link],
[Link], size = [Link])

alertcondition (long_trig, 'Long', 'Green Triangles Below Price')


alertcondition (shrt_trig, 'Short', 'Red Triangles Above Price')
alertcondition ( (pos == 1), 'Long Condition', 'Moving In The Bullish Direction')
alertcondition ( (pos == -1), 'Short Condition', 'Moving In The Bearish Direction')
alertcondition (long_gold, 'Gold Long', 'Gold Triangles Below Price')
alertcondition (shrt_gold, 'Gold Short', 'Gold Triangles Above Price')

Common questions

Powered by AI

Dynamic adjustment of trailing stop loss positions is crucial to adapt to real-time market volatility, securing profits while minimizing exposure to sudden adverse price movements. In the script, this is achieved by revising the trailing stop levels based on ATR-derived calculations every time a new bar is formed. If the price movement is favorable and crosses beyond the trailing stop level, the stop is adjusted to a new price point, thus locking in profits or minimizing losses by capturing real-time price momentum changes .

Alert conditions in the trading script automate the monitoring process by notifying traders when specific criteria are met, such as entering supply or demand zones, or crossing key technical levels. This allows traders to act swiftly on trading opportunities without constantly monitoring the charts, thereby enhancing efficiency. Alerts can signal potential long or short entries, notifying the trader to possibly execute a trade, thus integrating automated triggers into manual decision-making .

Customized trading sessions allow traders to focus on specific market hours that align with their strategies or significant market events. In the script, users can define custom trading sessions, such as specific hours in the New York or London session, which are then visibly marked on the charts. This visual aid helps traders concentrate on periods with higher liquidity or volatility that may present more trading opportunities, as opposed to using a one-size-fits-all approach across different market conditions .

The VWAP (Volume Weighted Average Price) serves as a benchmark for determining price trends and potential entry points for trades. In the script, trading signals for supply and demand zones are generated based on whether the closing price crosses above or below the VWAP. This indicates a shift in market sentiment, suggesting a potential entry point for traders as the VWAP reflects the average price a security has traded at throughout the day, considering both volume and price .

The script utilizes multiple time frames by calculating the Commodity Channel Index (CCI) for different intervals, such as 15-min and 60-min time frames, and combines their signals to enhance accuracy. For instance, a buy signal is conditioned on CCI1 being below a lower band on a shorter time frame and CCI2 being below another lower band on a longer time frame. Similarly, sell signals require CCI1 and CCI2 to exceed their respective upper bands on both time frames. This multi-time frame analysis helps confirm market trends and strength, reducing false signals .

The script offers the option to apply different moving average types, such as SMA, EMA, SMMA, WMA, and VWMA, to the RSI, which allows for tailored sensitivity and responsiveness to price changes. Each moving average type has its own characteristic that could influence how quickly it smooths out price data, impacting the RSI calculation. Traders can select the most suitable moving average type for their strategy, optimizing the RSI's balance between sensitivity and noise filtering based on market conditions .

The "Gold Entry Directional Confluence" feature adds another layer of validation to trading signals by providing directional bias. It requires that gold sell signals align with red bars (indicating negative sentiment) and gold buy signals align with green bars (indicating positive sentiment). This feature ensures that trading decisions are not only based on technical signals but also that they align with broader price movement trends, providing more robust entry signals and potentially increasing profitability .

The integration of RSI (Relative Strength Index) and CCI (Commodity Channel Index) provides a complex signal generation mechanism. Buy signals are generated when both CCI1 and CCI2 values fall below their respective lower bands and RSI values are below the specified middle band and lower band moving averages. Conversely, sell signals are initiated when CCI1 and CCI2 exceed their upper bands and RSI values breach upper threshold levels. By combining momentum (RSI) with trend strength (CCI), the script minimizes false signals by ensuring trades are initiated only when both momentum and trend align, thus improving reliability .

The ATR Trailing Stop Loss Indicator uses the Average True Range (ATR) to set trailing stop positions. It is calculated by multiplying the ATR value by a predefined multiplier and adjusting the stop level depending on whether the market is in an uptrend or downtrend. As price movements occur, the trailing stop adjusts to lock in profits or minimize losses. In the script, various conditions are used to trigger buying or selling signals depending on whether the closing price crosses the ATR trailing stop level, thus aiding in dynamic management of trade positions and risks .

In trading, a "Supply Zone" is identified when the previous closing price was higher than the previous VWAP (Volume Weighted Average Price) and the current price is below the current VWAP. Conversely, a "Demand Zone" is identified when the previous closing price was lower than the previous VWAP and the current price is above the current VWAP. These zones help traders identify potential areas of price reversal where demand exceeds supply (demand zone) or supply exceeds demand (supply zone), potentially indicating opportunities to buy or sell .

//@version=5
indicator(title="JASON XAUUSD 15mins 2/2", overlay=true)
len = input.int(60, "VWAP Length", minval=1)
width = in
timeframe1= input.timeframe('15','First CCI timeframe' , group="CCI Timeframe 
Settings")
timeframe2= input.timeframe('60','s
if  CCI1 < band0 and CCI2 < band2 and rsiMA < rsiLowerBand and rsi15 < midline
    signal_buy := true
if  CCI1 > band1 and CC
//------------------------------------------------------------------------------
// Function plots
//------------------------
shrt_gold = (close < atr_ts)    and (high  > atr_ts) and not ((close < atr_ts) and 
(high  > atr_ts))[1] and (gold_ent == tru

You might also like