-
https://tr.tradingview.com/script/n4...nvelope-ATRTS/
PHP Code:
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Misu
//@version=5
strategy(title='Moving Average Displaced Envelope & ATRTS', shorttitle='MADE+ATR', overlay=true, max_lines_count = 100, max_labels_count = 100)
tradeDirection = input.string('Both', title='Trade Direction', options=['Both', 'Long', 'Short'])
import Fontiramisu/fontilab/12 as fontilab
// ] —————— Input Vars —————— [
timeframe = input.timeframe(defval = '60', group="Pivot Settings")
leftBars = input.int(defval = 2, title = "Left Bars", minval = 1, group="Pivot Settings")
rightBars = input.int(defval = 2, title = "Right Bars", minval = 1, group="Pivot Settings")
// Fibo.
isColorAll = input.bool(true, "", group="UI Settings", inline="color")
colorAll = input.color(color.white, "Color All Lines ----", group="UI Settings", inline="color")
rightOffset = input.int(20, "Label Offset Right", group="UI Settings", inline="offset")
isfib0000 = input.bool(true, "", group="UI Settings", inline="0")
nFib0000 = input.float(0, "", step=0.01, group="UI Settings", inline="0")
colorFib0000 = input.color(color.white, "", group="UI Settings", inline="0")
isfib0206 = input.bool(false, "", group="UI Settings", inline="0")
nFib0206 = input.float(0.206, "", step=0.01, group="UI Settings", inline="0")
colorFib0206 = input.color(color.white, "", group="UI Settings", inline="0")
isfib0382 = input.bool(false, "", group="UI Settings", inline="0.382")
nFib0382 = input.float(0.382, "", step=0.01, group="UI Settings", inline="0.382")
colorFib0382 = input.color(color.white, "", group="UI Settings", inline="0.382")
isfib0500 = input.bool(true, "", group="UI Settings", inline="0.382")
nFib0500 = input.float(0.5, "", step=0.01, group="UI Settings", inline="0.382")
colorFib0500 = input.color(color.white, "", group="UI Settings", inline="0.382")
isfib0618 = input.bool(false, "", group="UI Settings", inline="0.618")
nFib0618 = input.float(0.618, "", step=0.01, group="UI Settings", inline="0.618")
colorFib0618 = input.color(color.white, "", group="UI Settings", inline="0.618")
isfib0786 = input.bool(false, "", group="UI Settings", inline="0.618")
nFib0786 = input.float(0.718, "", step=0.01, group="UI Settings", inline="0.618")
colorFib0786 = input.color(color.white, "", group="UI Settings", inline="0.618")
isfib1000 = input.bool(true, "", group="UI Settings", inline="1")
nFib1000 = input.float(1, "", step=0.01, group="UI Settings", inline="1")
colorFib1000 = input.color(color.white, "", group="UI Settings", inline="1")
isfib1414 = input.bool(false, "", group="UI Settings", inline="1")
nFib1414 = input.float(1.414, "", step=0.01, group="UI Settings", inline="1")
colorFib1414 = input.color(color.white, "", group="UI Settings", inline="1")
isfib1618 = input.bool(false, "", group="UI Settings", inline="1.618")
nFib1618 = input.float(1.618, "", step=0.01, group="UI Settings", inline="1.618")
colorFib1618 = input.color(color.white, "", group="UI Settings", inline="1.618")
isfib2000 = input.bool(false, "", group="UI Settings", inline="1.618")
nFib2000 = input.float(2, "", step=0.01, group="UI Settings", inline="1.618")
colorFib2000 = input.color(color.white, "", group="UI Settings", inline="1.618")
isfib2618 = input.bool(false, "", group="UI Settings", inline="2.618")
nFib2618 = input.float(2.618, "", step=0.01, group="UI Settings", inline="2.618")
colorFib2618 = input.color(color.white, "", group="UI Settings", inline="2.618")
// ] —————— Vars —————— [
var fib0000 = close
var fib0206 = close
var fib0382 = close
var fib0500 = close
var fib0618 = close
var fib0786 = close
var fib1000 = close
var fib1414 = close
var fib1618 = close
var fib2000 = close
var fib2618 = close
// ] —————— Find Dev Pivots —————— [
getMultiTfPivots()=>
float ph = ta.pivothigh(leftBars, rightBars)
float pl = ta.pivotlow(leftBars, rightBars)
phBIndexS = ph ? time[rightBars] : na
plBIndexS = pl ? time[rightBars] : na
[ph, phBIndexS, pl, plBIndexS]
// get if there if Pivot High/low and their start/end times
[ph, phBIndexS, pl, plBIndexS] = request.security(syminfo.tickerid, timeframe, getMultiTfPivots(), lookahead = barmerge.lookahead_on)
// ] —————— Fibs Handles —————— [
// Get last highs/lows.
pivothigh = na(ph[1]) and ph ? ph : na
pivotlow = na(pl[1]) and pl ? pl : na
var isHighLast = true
var curPivotP = 0.
var lastPivotP = 0.
var curPivotBi = 0
var lastPivotBi = 0
// Special case: where high & low detected at the same time.
if not na(pivothigh) and not na(pivotlow)
lastPivotP := isHighLast ? pl : ph
curPivotP := isHighLast ? ph : pl
lastPivotBi := isHighLast ? plBIndexS : phBIndexS
curPivotBi := isHighLast ? phBIndexS : plBIndexS
// All cases
else
isHighLast := not na(pivothigh) ? true : not na(pivotlow) ? false : isHighLast
lastPivotP := not na(pivothigh) and not isHighLast[1] or not na(pivotlow) and isHighLast[1] ? curPivotP : lastPivotP
curPivotP := not na(pivothigh) ? ph : not na(pivotlow) ? pl : curPivotP
lastPivotBi := not na(pivothigh) and not isHighLast[1] or not na(pivotlow) and isHighLast[1] ? curPivotBi : lastPivotBi
curPivotBi := not na(pivothigh) ? phBIndexS : not na(pivotlow) ? plBIndexS : curPivotBi
// Logic fibo direction.
fiboDirUp = isHighLast
// Last Update Barindex.
var barLastUpdate = 0
barLastUpdate := lastPivotBi
// Calculate fibs levels.
rangeD = isHighLast ? curPivotP - lastPivotP : lastPivotP - curPivotP
fib0000 := fiboDirUp ? curPivotP - nFib0000 * rangeD : curPivotP + nFib0000 * rangeD
fib0206 := fiboDirUp ? curPivotP - nFib0206 * rangeD : curPivotP + nFib0206 * rangeD
fib0382 := fiboDirUp ? curPivotP - nFib0382 * rangeD : curPivotP + nFib0382 * rangeD
fib0500 := fiboDirUp ? curPivotP - nFib0500 * rangeD : curPivotP + nFib0500 * rangeD
fib0618 := fiboDirUp ? curPivotP - nFib0618 * rangeD : curPivotP + nFib0618 * rangeD
fib0786 := fiboDirUp ? curPivotP - nFib0786 * rangeD : curPivotP + nFib0786 * rangeD
fib1000 := fiboDirUp ? curPivotP - nFib1000 * rangeD : curPivotP + nFib1000 * rangeD
fib1414 := fiboDirUp ? curPivotP - nFib1414 * rangeD : curPivotP + nFib1414 * rangeD
fib1618 := fiboDirUp ? curPivotP - nFib1618 * rangeD : curPivotP + nFib1618 * rangeD
fib2000 := fiboDirUp ? curPivotP - nFib2000 * rangeD : curPivotP + nFib2000 * rangeD
fib2618 := fiboDirUp ? curPivotP - nFib2618 * rangeD : curPivotP + nFib2618 * rangeD
// ] —————— Plot —————— [
var fib0000Line = line.new(0, low, bar_index, high)
var fib0000Label = label.new(bar_index, low, text="Init")
var fib0206Line = line.new(0, low, bar_index, high)
var fib0206Label = label.new(bar_index, low, text="Init")
var fib0382Line = line.new(0, low, bar_index, high)
var fib0382Label = label.new(bar_index, low, text="Init")
var fib0500Line = line.new(0, low, bar_index, high)
var fib0500Label = label.new(bar_index, low, text="Init")
var fib0618Line = line.new(0, low, bar_index, high)
var fib0618Label = label.new(bar_index, low, text="Init")
var fib0786Line = line.new(0, low, bar_index, high)
var fib0786Label = label.new(bar_index, low, text="Init")
var fib1000Line = line.new(0, low, bar_index, high)
var fib1000Label = label.new(bar_index, low, text="Init")
var fib1414Line = line.new(0, low, bar_index, high)
var fib1414Label = label.new(bar_index, low, text="Init")
var fib1618Line = line.new(0, low, bar_index, high)
var fib1618Label = label.new(bar_index, low, text="Init")
var fib2000Line = line.new(0, low, bar_index, high)
var fib2000Label = label.new(bar_index, low, text="Init")
var fib2618Line = line.new(0, low, bar_index, high)
var fib2618Label = label.new(bar_index, low, text="Init")
labelOffset = rightOffset
if isfib0000
line.delete(fib0000Line)
label.delete(fib0000Label)
fib0000Line := line.new(barLastUpdate, fib0000, time, fib0000, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib0000, width=1)
fib0000Label := label.new(x=bar_index + labelOffset, y = fib0000, xloc=xloc.bar_index, text=str.tostring(nFib0000), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib0000, textalign=text.align_center)
if isfib0206
line.delete(fib0206Line)
label.delete(fib0206Label)
fib0206Line := line.new(barLastUpdate, fib0206, time, fib0206, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib0206, width=1)
fib0206Label := label.new(x=bar_index + labelOffset, y = fib0206, xloc=xloc.bar_index, text=str.tostring(nFib0206), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib0206, textalign=text.align_center)
if isfib0382
line.delete(fib0382Line)
label.delete(fib0382Label)
fib0382Line := line.new(barLastUpdate, fib0382, time, fib0382, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib0382, width=1)
fib0382Label := label.new(x=bar_index + labelOffset, y = fib0382, xloc=xloc.bar_index, text=str.tostring(nFib0382), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib0382, textalign=text.align_center)
if isfib0500
line.delete(fib0500Line)
label.delete(fib0500Label)
fib0500Line := line.new(barLastUpdate, fib0500, time, fib0500, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib0500, width=1)
fib0500Label := label.new(x=bar_index + labelOffset, y = fib0500, xloc=xloc.bar_index, text=str.tostring(nFib0500), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib0500, textalign=text.align_center)
if isfib0618
line.delete(fib0618Line)
label.delete(fib0618Label)
fib0618Line := line.new(barLastUpdate, fib0618, time, fib0618, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib0618, width=1)
fib0618Label := label.new(x=bar_index + labelOffset, y = fib0618, xloc=xloc.bar_index, text=str.tostring(nFib0618), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib0618, textalign=text.align_center)
if isfib0786
line.delete(fib0786Line)
label.delete(fib0786Label)
fib0786Line := line.new(barLastUpdate, fib0786, time, fib0786, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib0786, width=1)
fib0786Label := label.new(x=bar_index + labelOffset, y = fib0786, xloc=xloc.bar_index, text=str.tostring(nFib0786), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib0786, textalign=text.align_center)
if isfib1000
line.delete(fib1000Line)
label.delete(fib1000Label)
fib1000Line := line.new(barLastUpdate, fib1000, time, fib1000, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib1000, width=1)
fib1000Label := label.new(x=bar_index + labelOffset, y = fib1000, xloc=xloc.bar_index, text=str.tostring(nFib1000), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib1000, textalign=text.align_center)
if isfib1414
line.delete(fib1414Line)
label.delete(fib1414Label)
fib1414Line := line.new(barLastUpdate, fib1414, time, fib1414, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib1414, width=1)
fib1414Label := label.new(x=bar_index + labelOffset, y = fib1414, xloc=xloc.bar_index, text=str.tostring(nFib1414), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib1414, textalign=text.align_center)
if isfib1618
line.delete(fib1618Line)
label.delete(fib1618Label)
fib1618Line := line.new(barLastUpdate, fib1618, time, fib1618, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib1618, width=1)
fib1618Label := label.new(x=bar_index + labelOffset, y = fib1618, xloc=xloc.bar_index, text=str.tostring(nFib1618), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib1618, textalign=text.align_center)
if isfib2000
line.delete(fib2000Line)
label.delete(fib2000Label)
fib2000Line := line.new(barLastUpdate, fib2000, time, fib2000, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib2000, width=1)
fib2000Label := label.new(x=bar_index + labelOffset, y = fib2000, xloc=xloc.bar_index, text=str.tostring(nFib2000), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib2000, textalign=text.align_center)
if isfib2618
line.delete(fib2618Line)
label.delete(fib2618Label)
fib2618Line := line.new(barLastUpdate, fib2618, time, fib2618, xloc=xloc.bar_time, color=isColorAll ? colorAll : colorFib2618, width=1)
fib2618Label := label.new(x=bar_index + labelOffset, y = fib2618, xloc=xloc.bar_index, text=str.tostring(nFib2618), style=label.style_none, size=size.small, textcolor=isColorAll ? colorAll : colorFib2618, textalign=text.align_center)
// linefill.new(fib0786Line, fib1000Line, color.blue)
// ]
Price = input(title='Source', defval=close)
Period = input.int(defval=9, minval=1)
perAb = input.float(title='Percent above', defval=.5, minval=0.01, step=0.1)
perBl = input.float(title='Percent below', defval=.5, minval=0.01, step=0.1)
disp = input.int(title='Displacement', defval=13, minval=1)
nATRPeriod = input(15)
nATRMultip = input(2)
useATR = input(true, title='ATR Filter')
reverse = input(true, title='Trade reverse')
longAllowed = tradeDirection == 'Long' or tradeDirection == 'Both'
shortAllowed = tradeDirection == 'Short' or tradeDirection == 'Both'
pos = 0
sEMA = ta.ema(Price, Period)
top = sEMA[disp] * ((100 + perAb) / 100)
bott = sEMA[disp] * ((100 - perBl) / 100)
xATR = ta.atr(nATRPeriod)
xHHs =ta.sma(ta.highest(nATRPeriod), nATRPeriod)
xLLs =ta.sma(ta.lowest(nATRPeriod),nATRPeriod)
nSpread = (xHHs - xLLs) / 2
nLoss = nATRMultip * xATR
var xATRTrailingStop = 0.0
xATRTrailingStop := close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0) ? math.max(nz(xATRTrailingStop[1]), close - nLoss) :
close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0) ? math.min(nz(xATRTrailingStop[1]), close + nLoss) :
close > nz(xATRTrailingStop[1], 0) ? close - nLoss : close + nLoss
ATRLong = close > xATRTrailingStop ? true : false
ATRShort = close < xATRTrailingStop ? true : false
iff_1 = close > top ? 1 : pos[1]
pos := close < bott ? -1 : iff_1
iff_2 = reverse and pos == -1 ? 1 : pos
possig = reverse and pos == 1 ? -1 : iff_2
clr = strategy.position_size
if possig == 1
if longAllowed and ATRLong
strategy.entry('Long', strategy.long)
else
if ATRLong or strategy.position_size > 0
strategy.close_all()
if possig == -1
if shortAllowed and ATRShort
strategy.entry('Short', strategy.short)
else
if ATRShort or strategy.position_size < 0
strategy.close_all()
if possig == 0
strategy.close_all()
//plot(xATRTrailingStop[1], color=color.blue, title='ATR Trailing Stop')
barcolor(clr < 0 ? #b50404 : clr > 0 ? #079605 : #0536b3)
-
https://tr.tradingview.com/v/CEyNpwaS/
aklınıza gelebilecek tüm ortalama çeşitlerini.....
kütüphane yapıp...çağıran çok çok güzel bir kod.......
-
deneme...
strateji eklenmedi....
PHP Code:
//@version=5
indicator("*", overlay = true, max_lines_count = 500, max_labels_count = 500, max_bars_back=3000)
timeframe = input.timeframe(defval = 'D', title="Source", tooltip="Must be higher than your chart timeframe\nThis chooses the most recent candle of that timeframe for the olhc levels\nIf the levels look wrong, check the last candle in that timeframe!")
p = input.int(0, 'Display nth Candle', minval=0, maxval = 100, tooltip = "Number of the candle to use, counting backwards, 0 is the current candle, 1 is the previous, etc")
display = input.string("Lines", "Display Style", options=["Lines", "Boxes","None"])
high_level = input.color(defval = color.new(color.green, 25), title="High to Open/Close")
oc_level = input.color(defval = color.new(#d7da4c, 25), title="Open to Close")
low_level = input.color(defval = color.new(color.maroon, 25), title="Open/Close to Low")
markhl = input.bool(defval = true, title="Mark High and Low with â–¼ â–²")
markoc = input.bool(defval = true, title="Mark Open Close with O C")
open_border_style = input.string(line.style_solid, 'Line Style', options=[line.style_solid, line.style_dotted, line.style_dashed])
open_border_width = input.int(1, 'Line Width', minval=0)
extend = input.bool(defval = false, title = "Extend?")
template = input.bool(defval = true, title="Draw Separate OxxC Template")
alerthigh = input.bool(defval = false, title="Alerts when high is crossed?")
alertlow = input.bool(defval = false, title="Alerts when low is crossed?")
alertopen = input.bool(defval = false, title="Alerts when new open price is created?")
extd = (extend == true ? extend.right : extend.none)
ResolutionToSec(res)=>
mins = res == "1" ? 1 :
res == "3" ? 3 :
res == "5" ? 5 :
res == "10" ? 10 :
res == "15" ? 15 :
res == "30" ? 30 :
res == "45" ? 45 :
res == "60" ? 60 :
res == "120" ? 120 :
res == "180" ? 180 :
res == "240" ? 240 :
res == "D" or res == "1D" ? 1440 :
res == "W" or res == "1W" ? 10080 :
res == "M" or res == "1M" ? 43200 :
res == "" ? int(str.tonumber(timeframe.period)) :
str.substring(timeframe.period, 2, 3) == "S" ? int(str.tonumber(str.substring(timeframe.period, 0, 2)))/60 : int(str.tonumber(res))
ms = mins * 60 * 1000
bar = ResolutionToSec(timeframe.period)
get_OHLC_day()=>
highs= high[p]
lows= low[p]
opens= open[p]
closes= close[p]
bartimes= time[p]
[highs, lows, opens, closes, bartimes]
[dhighs, dlows, dopens, dcloses, dbartimes] = request.security(syminfo.tickerid, timeframe, get_OHLC_day(), lookahead = barmerge.lookahead_on)
[dayhighs, daylows, dayopens, daycloses, daybartimes] = request.security(syminfo.tickerid, "1D", get_OHLC_day(), lookahead = barmerge.lookahead_on)
[whighs, wlows, wopens, wcloses, wbartimes] = request.security(syminfo.tickerid, "1W", get_OHLC_day(), lookahead = barmerge.lookahead_on)
ext = 0
if (bar_index == last_bar_index)
sesshigh = 0.0
sesslow = high*10
sesshighx = 0
sesslowx = 0
above = 0.0
below = 0.0
// sess = "0000-0000"
// s = time(timeframe.period, sess, zone)
var bool isTime = false
var label sessionopenlabel = na
var label sessioncloselabel = na
var line template_oc_line = na
var line template_high_line = na
var line template_low_line = na
for x = 0 to 2880
isTime := time[x] >= dbartimes
if (isTime)
if (high[x] > sesshigh)
sesshigh := high[x]
sesshighx := x
if (low[x] < sesslow)
sesslow := low[x]
sesslowx := x
if (markhl == true)
sessionhighlabel = label.new(time[sesshighx], sesshigh, text="â–¼", color=color.white, xloc=xloc.bar_time, style=label.style_none, textcolor=high_level, size=size.small, textalign=text.align_center)
sessionlowlabel = label.new(time[sesslowx], sesslow*0.9999, text="â–²", color=color.white, xloc=xloc.bar_time, style=label.style_none, textcolor=low_level, size=size.small, textalign=text.align_center)
label.delete(sessionhighlabel[1])
label.delete(sessionlowlabel[1])
if (markoc == true)
sessionopenlabel = label.new(time+(bar*2), dopens, text="O", color=color.white, xloc=xloc.bar_time, style=label.style_none, textcolor=oc_level, size=size.small, textalign=text.align_center)
sessioncloselabel = label.new(time+(bar*2), close, text="C", color=color.white, xloc=xloc.bar_time, style=label.style_none, textcolor=oc_level, size=size.small, textalign=text.align_center)
label.delete(sessionopenlabel[1])
label.delete(sessioncloselabel[1])
ext := time
if (display == "Boxes")
open_close_box = box.new(dbartimes, dopens > close ? dopens : close, ext, dopens > close ? close : dopens, color.new(oc_level, 65), extend=extd, xloc=xloc.bar_time, border_width=open_border_width, border_style=open_border_style, bgcolor=oc_level)
high_box = box.new(dbartimes, sesshigh, ext, dopens > close ? dopens : close, color.new(high_level, 65), extend=extd, xloc=xloc.bar_time, border_width=open_border_width, border_style=open_border_style, bgcolor=high_level)
low_box = box.new(dbartimes, dopens > close ? close : dopens, ext, sesslow, color.new(low_level, 65), extend=extd, xloc=xloc.bar_time, border_width=open_border_width, border_style=open_border_style, bgcolor=low_level)
box.delete(open_close_box[1])
box.delete(high_box[1])
box.delete(low_box[1])
else if (display == "Lines")
open_line = line.new(dbartimes, dopens, ext, dopens, extend=extd, xloc=xloc.bar_time, color=oc_level, width=open_border_width, style=open_border_style)
high_line = line.new(dbartimes, sesshigh, ext, sesshigh, extend=extd, xloc=xloc.bar_time, color=high_level, width=open_border_width, style=open_border_style)
low_line = line.new(dbartimes, sesslow, ext, sesslow, extend=extd, xloc=xloc.bar_time, color=low_level, width=open_border_width, style=open_border_style)
close_line = line.new(dbartimes, close, ext, close, extend=extd, xloc=xloc.bar_time, color=oc_level, width=open_border_width, style=open_border_style)
// debug label.new(bar_index, high, text=str.tostring(int(str.tonumber(str.substring(timeframe.period, 0, 2)))))
line.delete(open_line[1])
line.delete(close_line[1])
line.delete(high_line[1])
line.delete(low_line[1])
if (template == true)
mid = 10
template_open_line = line.new(time + (bar * (mid-3)), dopens, time+(bar*mid), dopens, xloc=xloc.bar_time, color=oc_level, width=open_border_width*2, style=line.style_solid)
template_close_line = line.new(time + (bar * mid), close, time+(bar*(mid+3)), close, xloc=xloc.bar_time, color=oc_level, width=open_border_width*2, style=line.style_solid)
template_oc_line = line.new(time + (bar * mid), dopens, time+(bar*mid), close, xloc=xloc.bar_time, color=oc_level, width=open_border_width*2, style=line.style_solid)
template_high_line = line.new(time + (bar * mid), dopens > close ? dopens : close, time+(bar*mid), sesshigh, xloc=xloc.bar_time, color=high_level, width=open_border_width*2, style=line.style_solid)
template_low_line = line.new(time + (bar * mid), dopens > close ? close : dopens, time+(bar*mid), sesslow, xloc=xloc.bar_time, color=low_level, width=open_border_width*2, style=line.style_solid)
line.delete(template_oc_line[1])
line.delete(template_high_line[1])
line.delete(template_low_line[1])
line.delete(template_close_line[1])
line.delete(template_open_line[1])
if (high == sesshigh and alerthigh)
alert("OHLC Price made new High of "+str.tostring(sesshigh), alert.freq_once_per_bar)
if (low == sesslow and alertlow)
alert("OHLC Price made new Low of "+str.tostring(sesslow), alert.freq_once_per_bar)
if (time == dbartimes and alertopen)
alert("New OHLC has been created with Open price "+str.tostring(open), alert.freq_once_per_bar)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © loxx
//@version=5
import loxx/loxxexpandedsourcetypes/4
greencolor = #2DD204
redcolor = #D2042D
fdip(float src, int per, int speedin)=>
float fmax = ta.highest(src, per)
float fmin = ta.lowest(src, per)
float length = 0
float diff = 0
for i = 1 to per - 1
diff := (nz(src[i]) - fmin) / (fmax - fmin)
if i > 0
length += math.sqrt( math.pow(nz(diff[i]) - nz(diff[i + 1]), 2) + (1 / math.pow(per, 2)))
float fdi = 1 + (math.log(length) + math.log(2)) / math.log(2 * per)
float traildim = 1 / (2 - fdi)
float alpha = traildim / 2
int speed = math.round(speedin * alpha)
speed
nonlagma(float src, float len)=>
float cycle = 4.0
float coeff = 3.0 * math.pi
float phase = len - 1.0
int _len = int(len * cycle + phase)
float weight = 0., float alfa = 0., float out = 0.
float[] alphas = array.new_float(_len, 0.)
for k = 0 to _len - 1
float t = 0.
t := k <= phase - 1 ? 1.0 * k / (phase - 1) : 1.0 + (k - phase + 1) * (2.0 * cycle - 1.0) / (cycle * len -1.0)
float beta = math.cos(math.pi * t)
float g = 1.0/(coeff * t + 1)
g := t <= 0.5 ? 1 : g
array.set(alphas, k, g * beta)
weight += array.get(alphas, k)
if (weight > 0)
float sum = 0.
for k = 0 to _len - 1
sum += array.get(alphas, k) * nz(src[k])
out := (sum / weight)
out
smthtype = input.string("Kaufman", "Heikin-Ashi Better Caculation Type", options = ["AMA", "T3", "Kaufman"], group = "Source Settings")
srcin = input.string("Median", "Source", group= "Source Settings",
options =
["Close", "Open", "High", "Low", "Median", "Typical", "Weighted", "Average", "Average Median Body", "Trend Biased", "Trend Biased (Extreme)",
"HA Close", "HA Open", "HA High", "HA Low", "HA Median", "HA Typical", "HA Weighted", "HA Average", "HA Average Median Body", "HA Trend Biased", "HA Trend Biased (Extreme)",
"HAB Close", "HAB Open", "HAB High", "HAB Low", "HAB Median", "HAB Typical", "HAB Weighted", "HAB Average", "HAB Average Median Body", "HAB Trend Biased", "HAB Trend Biased (Extreme)"])
per = input.int(30, "Fractal Period Ingest", group = "Adaptive Settings")
speed = input.int(20, "Speed", group = "Adaptive Settings")
ColorSteps = input.int(50, "Color Period", group = "Adaptive Settings")
colorbars = input.bool(true, "Color bars?", group = "UI Options")
kfl=input.float(0.666, title="* Kaufman's Adaptive MA (KAMA) Only - Fast End", group = "Moving Average Inputs")
ksl=input.float(0.0645, title="* Kaufman's Adaptive MA (KAMA) Only - Slow End", group = "Moving Average Inputs")
amafl = input.int(2, title="* Adaptive Moving Average (AMA) Only - Fast", group = "Moving Average Inputs")
amasl = input.int(30, title="* Adaptive Moving Average (AMA) Only - Slow", group = "Moving Average Inputs")
haclose = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, close)
haopen = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, open)
hahigh = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, high)
halow = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, low)
hamedian = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hl2)
hatypical = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hlc3)
haweighted = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, hlcc4)
haaverage = request.security(ticker.heikinashi(syminfo.tickerid), timeframe.period, ohlc4)
src = switch srcin
"Close" => loxxexpandedsourcetypes.rclose()
"Open" => loxxexpandedsourcetypes.ropen()
"High" => loxxexpandedsourcetypes.rhigh()
"Low" => loxxexpandedsourcetypes.rlow()
"Median" => loxxexpandedsourcetypes.rmedian()
"Typical" => loxxexpandedsourcetypes.rtypical()
"Weighted" => loxxexpandedsourcetypes.rweighted()
"Average" => loxxexpandedsourcetypes.raverage()
"Average Median Body" => loxxexpandedsourcetypes.ravemedbody()
"Trend Biased" => loxxexpandedsourcetypes.rtrendb()
"Trend Biased (Extreme)" => loxxexpandedsourcetypes.rtrendbext()
"HA Close" => loxxexpandedsourcetypes.haclose(haclose)
"HA Open" => loxxexpandedsourcetypes.haopen(haopen)
"HA High" => loxxexpandedsourcetypes.hahigh(hahigh)
"HA Low" => loxxexpandedsourcetypes.halow(halow)
"HA Median" => loxxexpandedsourcetypes.hamedian(hamedian)
"HA Typical" => loxxexpandedsourcetypes.hatypical(hatypical)
"HA Weighted" => loxxexpandedsourcetypes.haweighted(haweighted)
"HA Average" => loxxexpandedsourcetypes.haaverage(haaverage)
"HA Average Median Body" => loxxexpandedsourcetypes.haavemedbody(haclose, haopen)
"HA Trend Biased" => loxxexpandedsourcetypes.hatrendb(haclose, haopen, hahigh, halow)
"HA Trend Biased (Extreme)" => loxxexpandedsourcetypes.hatrendbext(haclose, haopen, hahigh, halow)
"HAB Close" => loxxexpandedsourcetypes.habclose(smthtype, amafl, amasl, kfl, ksl)
"HAB Open" => loxxexpandedsourcetypes.habopen(smthtype, amafl, amasl, kfl, ksl)
"HAB High" => loxxexpandedsourcetypes.habhigh(smthtype, amafl, amasl, kfl, ksl)
"HAB Low" => loxxexpandedsourcetypes.hablow(smthtype, amafl, amasl, kfl, ksl)
"HAB Median" => loxxexpandedsourcetypes.habmedian(smthtype, amafl, amasl, kfl, ksl)
"HAB Typical" => loxxexpandedsourcetypes.habtypical(smthtype, amafl, amasl, kfl, ksl)
"HAB Weighted" => loxxexpandedsourcetypes.habweighted(smthtype, amafl, amasl, kfl, ksl)
"HAB Average" => loxxexpandedsourcetypes.habaverage(smthtype, amafl, amasl, kfl, ksl)
"HAB Average Median Body" => loxxexpandedsourcetypes.habavemedbody(smthtype, amafl, amasl, kfl, ksl)
"HAB Trend Biased" => loxxexpandedsourcetypes.habtrendb(smthtype, amafl, amasl, kfl, ksl)
"HAB Trend Biased (Extreme)" => loxxexpandedsourcetypes.habtrendbext(smthtype, amafl, amasl, kfl, ksl)
=> haclose
len = fdip(src, per, speed)
nonlag = nonlagma(src, len)
min = ta.lowest(nonlag, ColorSteps)
max = ta.highest(nonlag, ColorSteps)
mid = (max + min) / 2
colorBuffer = color.from_gradient(nonlag, min, mid, redcolor, greencolor)
//plot(nonlag, "Adaptive Non-Lag MA", color = colorBuffer, linewidth = 3)
barcolor(colorbars ? colorBuffer : na)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © HasanRifat
//@version=5
look_back = input.int(defval = 20, title = "Candle Lookback")
confirm_in = input.int(defval = 3, title = "Confirm Within")
bull_candle = 0
bear_candle = 0
v_up = false
v_dn = false
var bull_active_candle = false
var bull_active_candle_low = 0.0
var bull_active_candle_high = 0.0
var bull_signal_active = false
var bull_candle_count = 0
var bear_active_candle = false
var bear_active_candle_low = 0.0
var bear_active_candle_high = 0.0
var bear_signal_active = false
var bear_candle_count = 0
for i = 0 to (look_back - 1)
if close < low[i]
bull_candle := bull_candle + 1
if close > high[i]
bear_candle := bear_candle + 1
if bull_candle == (look_back - 1)
bull_active_candle := true
bull_active_candle_low := low
bull_active_candle_high := high
bull_signal_active := false
bull_candle_count := 0
if bull_active_candle == true
bull_candle_count := bull_candle_count + 1
if bear_candle == (look_back - 1)
bear_active_candle := true
bear_active_candle_low := low
bear_active_candle_high := high
bear_signal_active := false
bear_candle_count := 0
if bear_active_candle == true
bear_candle_count := bear_candle_count + 1
if close < bull_active_candle_low
bull_active_candle := false
if close > bear_active_candle_high
bear_active_candle := false
if bull_active_candle == true and close > bull_active_candle_high and bull_signal_active == false and bull_candle_count <= (confirm_in+1) and barstate.isconfirmed
bull_signal_active := true
v_up := true
if bear_active_candle == true and close < bear_active_candle_low and bear_signal_active == false and bear_candle_count <= (confirm_in+1) and barstate.isconfirmed
bear_signal_active := true
v_dn := true
plotshape(v_up, title = "V Up", style = shape.triangleup, location = location.belowbar, color = color.green, size = size.small)
plotshape(v_dn, title = "V Dn", style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small)
alertcondition(v_up, "Bullish Revarsal", "Bullish Revarsal")
alertcondition(v_dn, "Bearish Revarsal", "Bearish Revarsal")
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © jdehorty
// @version=5
// A non-repainting implementation of Nadaraya–Watson Regression using a Rational Quadratic Kernel.
// Settings
src66 = input.source(close, 'Source')
h = input.float(8., 'Lookback Window', minval=3., tooltip='The number of bars used for the estimation. This is a sliding value that represents the most recent historical bars. Recommended range: 3-50')
r = input.float(8., 'Relative Weighting', step=0.25, tooltip='Relative weighting of time frames. As this value approaches zero, the longer time frames will exert more influence on the estimation. As this value approaches infinity, the behavior of the Rational Quadratic Kernel will become identical to the Gaussian kernel. Recommended range: 0.25-25')
x_0 = input.int(25, "Start Regression at Bar", tooltip='Bar index on which to start regression. The first bars of a chart are often highly volatile, and omission of these initial bars often leads to a better overall fit. Recommended range: 5-25')
smoothColors = input.bool(false, "Smooth Colors", tooltip="Uses a crossover based mechanism to determine colors. This often results in less color transitions overall.", inline='1', group='Colors')
lag = input.int(2, "Lag", tooltip="Lag for crossover detection. Lower values result in earlier crossovers. Recommended range: 1-2", inline='1', group='Colors')
size = array.size(array.from(src66)) // size of the data series
// Further Reading:
// The Kernel Cookbook: Advice on Covariance functions. David Duvenaud. Published June 2014.
// Estimation of the bandwidth parameter in Nadaraya-Watson kernel non-parametric regression based on universal threshold level. Ali T, Heyam Abd Al-Majeed Hayawi, Botani I. Published February 26, 2021.
kernel_regression(_src66, _size, _h) =>
float _currentWeight = 0.
float _cumulativeWeight = 0.
for i = 0 to _size + x_0
y = _src66[i]
w = math.pow(1 + (math.pow(i, 2) / ((math.pow(_h, 2) * 2 * r))), -r)
_currentWeight += y*w
_cumulativeWeight += w
_currentWeight / _cumulativeWeight
// Estimations
yhat1 = kernel_regression(src66, size, h)
yhat2 = kernel_regression(src66, size, h-lag)
// Rates of Change
bool wasBearish = yhat1[2] > yhat1[1]
bool wasBullish = yhat1[2] < yhat1[1]
bool isBearish = yhat1[1] > yhat1
bool isBullish = yhat1[1] < yhat1
bool isBearishChange = isBearish and wasBullish
bool isBullishChange = isBullish and wasBearish
// Crossovers
bool isBullishCross = ta.crossover(yhat2, yhat1)
bool isBearishCross = ta.crossunder(yhat2, yhat1)
bool isBullishSmooth = yhat2 > yhat1
bool isBearishSmooth = yhat2 < yhat1
// Colors
color c_bullish = input.color(#3AFF17, 'Bullish Color', group='Colors')
color c_bearish = input.color(#FD1707, 'Bearish Color', group='Colors')
color colorByCross = isBullishSmooth ? c_bullish : c_bearish
color colorByRate = isBullish ? c_bullish : c_bearish
color plotColor = smoothColors ? colorByCross : colorByRate
// Plot
plot(yhat1, "RQKE", color=plotColor, linewidth=1)
// Alert Variables
bool alertBullish = smoothColors ? isBearishCross : isBearishChange
bool alertBearish = smoothColors ? isBullishCross : isBullishChange
// Alerts for Color Changes
alertcondition(condition=alertBullish, title='Bearish Color Change', message='Nadaraya-Watson: {{ticker}} ({{interval}}) turned Bearish â–¼')
alertcondition(condition=alertBearish, title='Bullish Color Change', message='Nadaraya-Watson: {{ticker}} ({{interval}}) turned Bullish â–²')
// Non-Displayed Plot Outputs (i.e., for use in other indicators)
plot(alertBearish ? -1 : alertBullish ? 1 : 0, "Alert Stream", display=display.none)
https://www.tradingview.com/x/r3g7pgu7/
https://www.tradingview.com/x/EdtcumM0/
https://www.tradingview.com/x/b2mjFBYQ/
-
https://www.tradingview.com/x/KJdtiks3/ düzeltme tamam dersek...
https://www.tradingview.com/x/F8WWaC6t/ 1482 üzeri kapanış....
1583 kanalını devreye sokar...
kanalı test etmesi için...tavan olması gerekir gibi....olasılık yüzde 54
1508 kesin stop şartıyla.....
https://www.tradingview.com/x/oJQBHpzl/ şu an için konsildasyonda....
teknik olarak avlanmak için....1502 ye pin bar gerekir...ki sistem oyun dışı olur...
https://www.tradingview.com/x/2NjCSgT1/
https://www.tradingview.com/x/8zyS1p57/ 1512 ile konsildasyon dibi belirlenmiş oldu....
son durum...https://www.tradingview.com/x/GlcKZiLg/
teknikçi... stopla avlanır....1508 stopla oyundan atılan sitem....
son durum....https://www.tradingview.com/x/JJnxcJN9/
-
https://www.tradingview.com/x/q1K6SqaN/
hızlı bir 640 atağı gelebilir gibi....
-
https://www.tradingview.com/x/P7lgW52e/
bu çanak çömlekle...70 e gider mi?
acaba...
-
deneme...
farklı bir 20-50-200 çalışması bar renklendirmeli...
strateji yazmadım.....
https://www.tradingview.com/x/SEUxSyUe/
https://www.tradingview.com/x/1sg881ga/
https://www.tradingview.com/x/BvkKruvo/
agresif tasarım oldu...1-5-15 periyotlar için...
-
deneme
PHP Code:
//@version=5
strategy(title='Moonhub Cycle Index', shorttitle='*', overlay=true,max_lines_count = 100)
// Input parameters
len_DIema = input.int(1, minval=1, title='COEMA Length')
len_DIsma = input.int(50, minval=1, title='COSMA Length')
start1 = input(0.1)
increment1 = input(0.1)
maximum1 = input(0.1, "Max Value")
out1 = ta.sar(start1, increment1, maximum1)
start2 = input(0.1)
increment2 = input(0.1)
maximum2 = input(0.1, "Max Value")
out2 = ta.sar(start2, increment2, maximum2)
start3 = input(0.1)
increment3 = input(0.1)
maximum3 = input(0.1, "Max Value")
out3 = ta.sar(start3, increment3, maximum3)
// Create a custom index
index = (out1 + out2 + out3) / 3
// Calculate COEMA and COSMA for the Custom Index
DI_index_Co_E = ta.ema(index, len_DIema)
DI_Co_indexS = ta.sma(index, len_DIsma)
// Plot the index
plot(index, title='ORT', color=color.new(#ff5252, 100), linewidth=2)
plot(DI_index_Co_E, title='EMA', color=color.new(#2195f3, 100), linewidth=2)
plot(DI_Co_indexS, title='SMA', color=color.new(#4caf4f, 100), linewidth=2)
changebarcol = input.bool(true, title='Change Bar Color', inline='bcol')
bcolup = input.color(color.rgb(103, 243, 76), title='', inline='bcol')
bcoldn = input.color(color.rgb(248, 78, 78), title='', inline='bcol')
var color lastBarColor = na
BullishColor = input.color(color.rgb(125, 247, 77))
BearishColor = input.color(color.rgb(245, 76, 76))
barColorBasedOnDEMATrend = close > out1 and close > out2 and close > out3 ? BullishColor : close < out1 and close < out2 and close < out3 ? BearishColor : nz(lastBarColor[1])
lastBarColor := barColorBasedOnDEMATrend
//barcolor(color=changebarcol ? barColorBasedOnDEMATrend : na)
xa = ta.crossover(close,out1) and ta.crossover(close,out2) and ta.crossover(close,out3)
ys = ta.crossunder(close,out1) and ta.crossunder(close,out2) and ta.crossunder(close,out3)
in_b = ta.barssince(xa)[1] < ta.barssince(ys)[1]
in_s = ta.barssince(ys)[1] < ta.barssince(xa)[1]
if xa
strategy.entry("Long",strategy.long)
if ys
strategy.close("Long")