derleme örneği....
önce strateji belirleyip, stratejiye uygun sistem derleme...
açık kaynak kodlarda düzenlemeler yapıldığı için değerler, stil v.b kısımlarda değişiklikler yapıldığı için....
örnekleri kendinize göre düzenleyebilirsiniz....
strateji örneği https://www.tradingview.com/x/1UFsi93l/
kod örneği
//@version=4
//
// Title: [STRATEGY][UL]Price Divergence Strategy V1.1
// Author: JustUncleL
// Date: 23-Oct-2016
// Version: v1.1
//
// Description:
// A trend trading strategy the uses Price Divergence detection signals, that
// are confirmed by the "Murrey's Math Oscillator" (Donchanin Channel based).
//
// *** USE AT YOUR OWN RISK ***
//
// Mofidifications:
// 1.0 - original
// 1.1 - Pinescript V4 update 21-Aug-2021
//
// References:
// Strategy Based on:
// - [RS]Price Divergence Detector V2 by RicardoSantos
// - UCS_Murrey's Math Oscillator by Ucsgears
// Some Code borrowed from:
// - "Strategy Code Example by JayRogers"
// Information on Divergence Trading:
// - http://www.babypips.com/school/high-...ng-divergences
//
strategy(title='&', pyramiding=0, overlay=true, initial_capital=10000, calc_on_every_tick=false, currency=currency.TRY,
default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// || General Input:
method = input(title='Method (0=rsi, 1=macd, 2=stoch, 3=volume, 4=acc/dist, 5=fisher, 6=cci):', type=input.integer, defval=2, minval=0, maxval=6)
SHOW_LABEL = input(title='Show Labels', type=input.bool, defval=true)
SHOW_CHANNEL = input(title='Show Channel', type=input.bool, defval=false)
uHid = input(true, title="Use Hidden Divergence in Strategy")
uReg = input(true, title="Use Regular Divergence in Strategy")
// || RSI / STOCH / VOLUME / ACC/DIST Input:
rsi_smooth = input(title='RSI/STOCH/Volume/ACC-DIST/Fisher/cci Smooth:', type=input.integer, defval=5)
// || MACD Input:
macd_src = input(title='MACD Source:', type=input.source, defval=close)
macd_fast = input(title='MACD Fast:', type=input.integer, defval=11)
macd_slow = input(title='MACD Slow:', type=input.integer, defval=16)
macd_smooth = input(title='MACD Smooth Signal:', type=input.integer, defval=8)
// || Functions:
f_top_fractal(_src) =>
_src[4] < _src[2] and _src[3] < _src[2] and _src[2] > _src[1] and
_src[2] > _src[0]
f_bot_fractal(_src) =>
_src[4] > _src[2] and _src[3] > _src[2] and _src[2] < _src[1] and
_src[2] < _src[0]
f_fractalize(_src) =>
f_bot_fractal__1 = f_bot_fractal(_src)
f_top_fractal(_src) ? 1 : f_bot_fractal__1 ? -1 : 0
// ||••> START MACD FUNCTION
f_macd(_src, _fast, _slow, _smooth) =>
_fast_ma = sma(_src, _fast)
_slow_ma = sma(_src, _slow)
_macd = _fast_ma - _slow_ma
_signal = ema(_macd, _smooth)
_hist = _macd - _signal
_hist
// ||<•• END MACD FUNCTION
// ||••> START ACC/DIST FUNCTION
f_accdist(_smooth) =>
_return = sma(cum(close == high and close == low or high == low ? 0 : (2 * close - low - high) / (high - low) * volume), _smooth)
_return
// ||<•• END ACC/DIST FUNCTION
// ||••> START FISHER FUNCTION
f_fisher(_src, _window) =>
_h = highest(_src, _window)
_l = lowest(_src, _window)
_value0 = 0.0
_fisher = 0.0
_value0 := .66 * ((_src - _l) / max(_h - _l, .001) - .5) + .67 * nz(_value0[1])
_value1 = _value0 > .99 ? .999 : _value0 < -.99 ? -.999 : _value0
_fisher := .5 * log((1 + _value1) / max(1 - _value1, .001)) + .5 * nz(_fisher[1])
_fisher
// ||<•• END FISHER FUNCTION
rsi_1 = rsi(high, rsi_smooth)
f_macd__1 = f_macd(macd_src, macd_fast, macd_slow, macd_smooth)
stoch_1 = stoch(close, high, low, rsi_smooth)
sma_1 = sma(volume, rsi_smooth)
f_accdist__1 = f_accdist(rsi_smooth)
f_fisher__1 = f_fisher(high, rsi_smooth)
cci_1 = cci(high, rsi_smooth)
method_high = method == 0 ? rsi_1 : method == 1 ? f_macd__1 :
method == 2 ? stoch_1 : method == 3 ? sma_1 : method == 4 ? f_accdist__1 :
method == 5 ? f_fisher__1 : method == 6 ? cci_1 : na
rsi_2 = rsi(low, rsi_smooth)
f_macd__2 = f_macd(macd_src, macd_fast, macd_slow, macd_smooth)
stoch_2 = stoch(close, high, low, rsi_smooth)
sma_2 = sma(volume, rsi_smooth)
f_accdist__2 = f_accdist(rsi_smooth)
f_fisher__2 = f_fisher(low, rsi_smooth)
cci_2 = cci(low, rsi_smooth)
method_low = method == 0 ? rsi_2 : method == 1 ? f_macd__2 :
method == 2 ? stoch_2 : method == 3 ? sma_2 : method == 4 ? f_accdist__2 :
method == 5 ? f_fisher__2 : method == 6 ? cci_2 : na
fractal_top = f_fractalize(method_high) > 0 ? method_high[2] : na
fractal_bot = f_fractalize(method_low) < 0 ? method_low[2] : na
high_prev = valuewhen(fractal_top, method_high[2], 1)
high_price = valuewhen(fractal_top, high[2], 1)
low_prev = valuewhen(fractal_bot, method_low[2], 1)
low_price = valuewhen(fractal_bot, low[2], 1)
regular_bearish_div = fractal_top and high[2] > high_price and method_high[2] < high_prev
hidden_bearish_div = fractal_top and high[2] < high_price and method_high[2] > high_prev
regular_bullish_div = fractal_bot and low[2] < low_price and method_low[2] > low_prev
hidden_bullish_div = fractal_bot and low[2] > low_price and method_low[2] < low_prev
plot(title='HF', series=fractal_top ? high[2] : na, color=regular_bearish_div or hidden_bearish_div ? color.maroon : not SHOW_CHANNEL ? na : color.silver, offset=-2)
plot(title='LF', series=fractal_bot ? low[2] : na, color=regular_bullish_div or hidden_bullish_div ? color.green : not SHOW_CHANNEL ? na : color.silver, offset=-2)
plotshape(title='+RBD', series=not SHOW_LABEL ? na : regular_bearish_div ? high[2] : na, text='R', style=shape.labeldown, location=location.absolute, color=color.maroon, textcolor=color.white, offset=-2)
plotshape(title='-RBD', series=not SHOW_LABEL ? na : regular_bullish_div ? low[2] : na, text='R', style=shape.labelup, location=location.absolute, color=color.green, textcolor=color.white, offset=-2)
// Code borrowed from UCS_Murrey's Math Oscillator by Ucsgears
// - UCS_MMLO
// Inputs
length = input(20, minval=10, title="MMLO Look back Length")
quad = input(1, minval=1, maxval=4, step=1, title="Mininum Quadrant for MMLO Support")
mult = 0.125
// Donchanin Channel
hi = highest(high, length)
lo = lowest(low, length)
range = hi - lo
multiplier = range * mult
midline = lo + multiplier * 4
oscillator = (close - midline) / (range / 2)
a = oscillator > 0
b = oscillator > 0 and oscillator > mult * 2
c = oscillator > 0 and oscillator > mult * 4
d = oscillator > 0 and oscillator > mult * 6
z = oscillator < 0
y = oscillator < 0 and oscillator < -mult * 2
x = oscillator < 0 and oscillator < -mult * 4
w = oscillator < 0 and oscillator < -mult * 6
// Strategy: (Thanks to JayRogers)
// === STRATEGY RELATED INPUTS ===
//tradeInvert = input(defval = false, title = "Invert Trade Direction?")
// the risk management inputs
inpTakeProfit = input(defval=0, title="Take Profit Points", minval=0)
inpStopLoss = input(defval=0, title="Stop Loss Points", minval=0)
inpTrailStop = input(defval=20, title="Trailing Stop Loss Points", minval=0)
inpTrailOffset = input(defval=0, title="Trailing Stop Loss Offset Points", minval=0)
// === RISK MANAGEMENT VALUE PREP ===
// if an input is less than 1, assuming not wanted so we assign 'na' value to disable it.
useTakeProfit = inpTakeProfit >= 1 ? inpTakeProfit : na
useStopLoss = inpStopLoss >= 1 ? inpStopLoss : na
useTrailStop = inpTrailStop >= 1 ? inpTrailStop : na
useTrailOffset = inpTrailOffset >= 1 ? inpTrailOffset : na
// === STRATEGY - LONG POSITION EXECUTION ===
enterLong() => // functions can be used to wrap up and work out complex conditions
(uReg and regular_bullish_div or uHid and hidden_bullish_div) and
(quad == 1 ? a[1] :
quad == 2 ? b[1] : quad == 3 ? c[1] : quad == 4 ? d[1] : false)
exitLong() =>
oscillator <= 0
strategy.entry(id="A", long=true, when=enterLong()) // use function or simple condition to decide when to get in
strategy.close(id="A", when=exitLong()) // ...and when to get out
// === STRATEGY - SHORT POSITION EXECUTION ===
enterShort() =>
(uReg and regular_bearish_div or uHid and hidden_bearish_div) and
(quad == 1 ? z[1] :
quad == 2 ? y[1] : quad == 3 ? x[1] : quad == 4 ? w[1] : false)
exitShort() =>
oscillator >= 0
strategy.entry(id="S", long=false, when=enterShort())
strategy.close(id="S", when=exitShort())
// === STRATEGY RISK MANAGEMENT EXECUTION ===
// finally, make use of all the earlier values we got prepped
strategy.exit("S", from_entry="A", profit=useTakeProfit, loss=useStopLoss, trail_points=useTrailStop, trail_offset=useTrailOffset)
strategy.exit("A", from_entry="S", profit=useTakeProfit, loss=useStopLoss, trail_points=useTrailStop, trail_offset=useTrailOffset)
//EOF
strateji örneği https://www.tradingview.com/x/iEfYI0L3/
kod örneği
//@version=3
//
strategy(title = "ak", shorttitle = "$", overlay = true,
pyramiding = 0, default_qty_type = strategy.percent_of_equity, default_qty_value = 10, calc_on_every_tick=false)
//
// Revision: 5
// Original Author: @JayRogers
// Revision Author: JustUncleL revisions 3, 4, 5
//
// *** USE AT YOUR OWN RISK ***
// - There are drawing/painting issues in pinescript when working across resolutions/timeframes that I simply
// cannot fix here.. I will not be putting any further effort into developing this until such a time when
// workarounds become available.
// NOTE: Re-painting has been observed infrequently with default settings and seems OK up to Alternate
// multiplier of 5.
// Non-repainting mode is available by setting "Delay Open/Close MA" to 1 or more, but the reported
// performance will drop dramatically.
//
// R5.1 Changes by JustUncleL
// - Upgraded to Version 3 Pinescript.
// - Added option to select Trade type (Long, Short, Both or None)
// - Added bar colouring work around patch.
// - Small code changes to improve efficiency.
// - NOTE: To enable non-Repainting mode set "Delay Open/Close MA" to 1 or more.
// 9-Aug-2017
// - Correction on SuperSmooth MA calculation.
//
// R5 Changes by JustUncleL
// - Corrected cross over calculations, sometimes gave false signals.
// - Corrected Alternate Time calculation to allow for Daily,Weekly and Monthly charts.
// - Open Public release.
// R4 Changes By JustUncleL
// - Change the way the Alternate resolution in selected, use a Multiplier of the base Time Frame instead,
// this makes it easy to switch between base time frames.
// - Added TMA and SSMA moving average options. But DEMA is still giving the best results.
// - Using "calc_on_every_tick=false" ensures results between backtesting and real time are similar.
// - Added Option to Disable the coloring of the bars.
// - Updated default settings.
//
// R3 Changes by JustUncleL:
// - Returned a simplified version of the open/close channel, it shows strength of current trend.
// - Added Target Profit Option.
// - Added option to reduce the number of historical bars, overcomes the too many trades limit error.
// - Simplified the strategy code.
// - Removed Trailing Stop option, not required and in my opion does not work well in Trading View,
// it also gives false and unrealistic performance results in backtesting.
//
// R2 Changes:
// - Simplified and cleaned up plotting, now just shows a Moving Average derived from the average of open/close.
// - Tried very hard to alleviate painting issues caused by referencing alternate resolution..
//
// Description:
// - Strategy based around Open-Close Crossovers.
// Setup:
// - I have generally found that setting the strategy resolution to 3-4x that of the chart you are viewing
// tends to yield the best results, regardless of which MA option you may choose (if any) BUT can cause
// a lot of false positives - be aware of this
// - Don't aim for perfection. Just aim to get a reasonably snug fit with the O-C band, with good runs of
// green and red.
// - Option to either use basic open and close series data, or pick your poison with a wide array of MA types.
// - Optional trailing stop for damage mitigation if desired (can be toggled on/off)
// - Positions get taken automagically following a crossover - which is why it's better to set the resolution
// of the script greater than that of your chart, so that the trades get taken sooner rather than later.
// - If you make use of the stops, be sure to take your time tweaking the values. Cutting it too fine
// will cost you profits but keep you safer, while letting them loose could lead to more drawdown than you
// can handle.
// - To enable non-Repainting mode set "Delay Open/Close MA" to 1 or more.
//
// === INPUTS ===
useRes = input(defval = true, title = "Use Alternate Resolution?")
intRes = input(defval = 3, title = "Multiplier for Alernate Resolution")
stratRes = ismonthly? tostring(interval*intRes,"###M") : isweekly? tostring(interval*intRes,"###W") : isdaily? tostring(interval*intRes,"###D") : isintraday ? tostring(interval*intRes,"####") : '60'
basisType = input(defval = "DEMA", title = "MA Type: ", options=["SMA", "EMA", "DEMA", "TEMA", "WMA", "VWMA", "SMMA", "HullMA", "LSMA", "ALMA", "SSMA", "TMA"])
basisLen = input(defval = 3, title = "MA Period", minval = 1)
offsetSigma = input(defval = 6, title = "Offset for LSMA / Sigma for ALMA", minval = 0)
offsetALMA = input(defval = 0.85, title = "Offset for ALMA", minval = 0, step = 0.01)
scolor = input(false, title="Show coloured Bars to indicate Trend?")
delayOffset = input(defval = 0, title = "Delay Open/Close MA (Forces Non-Repainting)", minval = 0, step = 1)
tradeType = input("BOTH", title="What trades should be taken : ", options=["LONG", "SHORT", "BOTH", "NONE"])
// === /INPUTS ===
// Constants colours that include fully non-transparent option.
green100 = #008000FF
lime100 = #00FF00FF
red100 = #FF0000FF
blue100 = #0000FFFF
**ua100 = #00FFFFFF
darkred100 = #8B0000FF
gray100 = #808080FF
// === BASE FUNCTIONS ===
// Returns MA input selection variant, default to SMA if blank or typo.
variant(type, src, len, offSig, offALMA) =>
v1 = sma(src, len) // Simple
v2 = ema(src, len) // Exponential
v3 = 2 * v2 - ema(v2, len) // Double Exponential
v4 = 3 * (v2 - ema(v2, len)) + ema(ema(v2, len), len) // Triple Exponential
v5 = wma(src, len) // Weighted
v6 = vwma(src, len) // Volume Weighted
v7 = 0.0
v7 := na(v7[1]) ? sma(src, len) : (v7[1] * (len - 1) + src) / len // Smoothed
v8 = wma(2 * wma(src, len / 2) - wma(src, len), round(sqrt(len))) // Hull
v9 = linreg(src, len, offSig) // Least Squares
v10 = alma(src, len, offALMA, offSig) // Arnaud Legoux
v11 = sma(v1,len) // Triangular (extreme smooth)
// SuperSmoother filter
// © 2013 John F. Ehlers
a1 = exp(-1.414*3.14159 / len)
b1 = 2*a1*cos(1.414*3.14159 / len)
c2 = b1
c3 = (-a1)*a1
c1 = 1 - c2 - c3
v12 = 0.0
v12 := c1*(src + nz(src[1])) / 2 + c2*nz(v12[1]) + c3*nz(v12[2])
type=="EMA"?v2 : type=="DEMA"?v3 : type=="TEMA"?v4 : type=="WMA"?v5 : type=="VWMA"?v6 : type=="SMMA"?v7 : type=="HullMA"?v8 : type=="LSMA"?v9 : type=="ALMA"?v10 : type=="TMA"?v11: type=="SSMA"?v12: v1
// security wrapper for repeat calls
reso(exp, use, res) => use ? security(tickerid, res, exp, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on) : exp
// === /BASE FUNCTIONS ===
// === SERIES SETUP ===
closeSeries = variant(basisType, close[delayOffset], basisLen, offsetSigma, offsetALMA)
openSeries = variant(basisType, open[delayOffset], basisLen, offsetSigma, offsetALMA)
// === /SERIES ===
// === PLOTTING ===
// Get Alternate resolution Series if selected.
closeSeriesAlt = reso(closeSeries, useRes, stratRes)
openSeriesAlt = reso(openSeries, useRes, stratRes)
//
trendColour = (closeSeriesAlt > openSeriesAlt) ? green : red
bcolour = (closeSeries > openSeriesAlt) ? lime100 : red100
closeP=plot(closeSeriesAlt, title = "kapanış", color = trendColour, linewidth = 1, style = line, transp = 100)
openP=plot(openSeriesAlt, title = "açılış", color = trendColour, linewidth = 1, style = line, transp = 100)
// === /PLOTTING ===
//
//
// === ALERT conditions
xlong = crossover(closeSeriesAlt, openSeriesAlt)
xshort = crossunder(closeSeriesAlt, openSeriesAlt)
longCond = xlong // alternative: longCond[1]? false : (xlong or xlong[1]) and close>closeSeriesAlt and close>=open
shortCond = xshort // alternative: shortCond[1]? false : (xshort or xshort[1]) and close<closeSeriesAlt and close<=open
// === /ALERT conditions.
// === STRATEGY ===
// stop loss
slPoints = input(defval = 0, title = "Initial Stop Loss Points (zero to disable)", minval = 0)
tpPoints = input(defval = 0, title = "Initial Target Profit Points (zero for disable)", minval = 0)
// Include bar limiting algorithm
ebar = input(defval = 10000, title="Number of Bars for Back Testing", minval=0)
dummy = input(false, title="- SET to ZERO for Daily or Longer Timeframes" )
//
// Calculate how many mars since last bar
tdays = (timenow-time)/60000.0 // number of minutes since last bar
tdays := ismonthly? tdays/1440.0/5.0/4.3/interval : isweekly? tdays/1440.0/5.0/interval : isdaily? tdays/1440.0/interval : tdays/interval // number of bars since last bar
//
//set up exit parameters
TP = tpPoints>0?tpPoints:na
SL = slPoints>0?slPoints:na
// Make sure we are within the bar range, Set up entries and exit conditions
if ((ebar==0 or tdays<=ebar) and tradeType!="NONE")
strategy.entry("long", strategy.long, when=longCond==true and tradeType!="SHORT")
strategy.entry("short", strategy.short, when=shortCond==true and tradeType!="LONG")
strategy.close("long", when = shortCond==true and tradeType=="LONG")
strategy.close("short", when = longCond==true and tradeType=="SHORT")
strategy.exit("XL", from_entry = "long", profit = TP, loss = SL)
strategy.exit("XS", from_entry = "short", profit = TP, loss = SL)
// === /STRATEGY ===
// eof
Yer İmleri