strat

strat


// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

// © huytebe


//@version=3

strategy("Моя стратегия", overlay=true)

//TSP 

// @author LazyBear

//

// If you use this code in its original/modified form, do drop me a note. 

//


n1 = input(10, "Channel Length")

n2 = input(21, "Average Length")

obLevel1 = input(60, "Over Bought Level 1")

obLevel2 = input(53, "Over Bought Level 2")

osLevel1 = input(-60, "Over Sold Level 1")

osLevel2 = input(-53, "Over Sold Level 2")

 

ap = hlc3 

esa = ema(ap, n1)

d = ema(abs(ap - esa), n1)

ci = (ap - esa) / (0.015 * d)

tci = ema(ci, n2)

 

wt1 = tci

wt2 = sma(wt1,4)


plot(0, color=gray)

plot(obLevel1, color=red)

plot(osLevel1, color=green)

plot(obLevel2, color=red)

plot(osLevel2, color=green)


plot(wt1, color=green)

plot(wt2, color=red)

plot(wt1-wt2, color=blue, style=area, transp=80)

plot(cross(wt1, wt2) ? wt2 : na, color = black , style = circles, linewidth = 3)

plot(cross(wt1, wt2) ? wt2 : na, color = (wt2 - wt1 > 0 ? red : lime) , style = circles, linewidth = 2)

//barcolor(cross(wt1, wt2) ? (wt2 - wt1 > 0 ? color(green,80) : color(red,80)) : na)



// adding cycle

// cycles are from 0 to 100

//study(title="Cycles", shorttitle="Cycles")

periodK = input(5, minval=1), periodD = input(3, minval=1), smooth = input(2, minval=1)

ck = sma(stoch(close, high, low, periodK), smooth)-50

cd = sma(ck, periodD)

cck = plot(ck, color=#666666)

ccd = plot(cd, color=#aaaaaa, linewidth=1)

fill(cck,ccd,color=#666666)

//h0 = hline(80)

//h1 = hline(20)

//h2 = hline(50, linestyle=solid)


length = input(50)

//----

A = barssince(rising(high,length))

B = barssince(falling(low,length))

upper = (A > length ? length : A)/length - 0.5

lower = (B > length ? length : B)/length - 0.5

//----


//----

Length = input(50,title="Period of Evaluation")

Smooth = input(25,title="Period of Smoothing")

//----

src = input(close,title="Source")

Resolution = input(defval = "1",type=resolution)

Mode = input(title="Indicator Method", defval="RSI", options=["RSI", "STOCHASTIC","ADX"])

Ma = input(title="Moving Average Method", defval="SMA", options=["SMA", "EMA","LSMA"])

//----

Price = security(tickerid,Resolution,close)

f(x,Length) => Ma == "SMA" ? sma(x,Length) : Ma == "EMA" ? ema(x,Length) : linreg(x,Length,0)

//----

Price1 = f(Price,Length)

Price2 = f(Price[1],Length)

Bulls0 = 0.5*(abs(Price1-Price2)+(Price1-Price2))

Bears0 = 0.5*(abs(Price1-Price2)-(Price1-Price2))

//----      

Bulls1 = Price1 - lowest(Price1,Length)

Bears1 = highest(Price1,Length) - Price1

Bulls2 = 0.5*(abs(high-high[1])+(high-high[1]))

Bears2 = 0.5*(abs(low[1]-low)+(low[1]-low))

//----

Bulls = Mode == "RSI" ? Bulls0 : Mode == "STOCHASTIC" ? Bulls1 : Bulls2

Bears = Mode == "RSI" ? Bears0 : Mode == "STOCHASTIC" ? Bears1 : Bears2

AvgBulls=f(Bulls,Length)   

AvgBears=f(Bears,Length)

//----

SmthBulls=f(AvgBulls,Smooth)  

SmthBears=f(AvgBears,Smooth)

trend = SmthBulls>SmthBears ? 1 : -1

//----


longCondition = crossover(wt1,wt2) and upper and SmthBulls

if (longCondition)

  strategy.entry("My Long Entry Id", strategy.long)


shortCondition = crossunder(wt1,wt2) and lower and SmthBears

if (shortCondition)

  strategy.entry("My Short Entry Id", strategy.short)

Report Page