TMA + OSMA

skyline-trader · study · 106 行 · 点赞 1,484 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © yorgwarez
 
//@version=4
// TMA Bands by author Daveatt
 
study("TMA + OSMA", shorttitle="TMA + OSMA", overlay=true)
 
////////////////
// TMA Bands //
//////////////
 
TMAPeriodBack = input(defval=33, title="TMA number of bars back")
ATRPeriodBack = input(defval=20, title="ATR number of bars back")
ATRMultiplier = input(defval=2.5, title="ATR Multiplier")
src = input(close, title="Source")
 
ssi=wma(src,TMAPeriodBack)
tma = swma(ssi)
range = atr(ATRPeriodBack)*ATRMultiplier
tmah = tma+range
tmal = tma-range 
 
tmahWhen = barssince(crossunder(close, tmah))
tmalWhen = barssince(crossover(close, tmal))
lastCrossTMA = 0
if (tmahWhen < tmalWhen)
    lastCrossTMA := -1
else
    lastCrossTMA := 1
 
plot(tmah, color=color.red, linewidth=2, transp = 40, title = "Upper")
//plot(tma, color=color.maroon, linewidth=2, transp = 40, title = "Middle")
plot(tmal, color=color.green, linewidth=2, transp = 40, title = "Lower")
 
///////////
// OSMA //
/////////
 
// Getting inputs
fast_length = input(title="Fast Length", type=input.integer, defval=12)
slow_length = input(title="Slow Length", type=input.integer, defval=26)
//src = input(title="Source", type=input.source, defval=close)
signal_length = input(title="Signal Smoothing", type=input.integer, minval = 1, maxval = 50, defval = 9)
 
// Plot colors
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350
col_macd = #0094ff
col_signal = #ff6a00
 
// Calculating
fast_ma = ema(src, fast_length)
slow_ma = ema(src, slow_length)
macd = fast_ma - slow_ma
signal = ema(macd, signal_length)
hist = macd - signal
 
// plot(hist, title="Histogram", style=plot.style_columns, color=(hist>=0 ? (hist[1] < hist ? col_grow_above : col_fall_above) : (hist[1] < hist ? col_grow_below : col_fall_below) ), transp=0 )
 
///////////////////
// EMA + OFFSET //
/////////////////
 
length = input(title='EMA Length', type=input.integer, defval = 20, minval=10, maxval = 200, step = 10)
offset = input(title='EMA Vertical Offset', type=input.float, defval = 1, minval=0.1, step = 0.1)
 
ema_to_plot = ema(close,length)
 
emaHigh = ema_to_plot+offset
emaLow = ema_to_plot-offset
 
// Plot EMA
plot(ema_to_plot, color = color.blue, linewidth=2)
 
// Plot vertical
plot(ema_to_plot+offset, offset=0, color=color.gray, linewidth=1)
plot(ema_to_plot-offset, offset=0, color=color.gray, linewidth=1)
 
 
//////////////
// SIGNALS //
////////////
 
long = hist > 0 and crossover(close, emaHigh) and lastCrossTMA == 1
short = hist < 0 and crossunder(close, emaLow) and lastCrossTMA == -1
 
// signalUpWhen = barssince(long)
// signalDownWhen = barssince(short)
// lastSignal = 0
// if (signalUpWhen < signalDownWhen)
//     lastSignal := -1
// else
//     lastSignal := 1
    
// if (lastCrossTMA == 1 and lastSignal == 1)
    
 
//bgcolor(long ? color.green : short ? color.red : na)
plotshape(long, style=shape.circle, color=color.green, location=location.belowbar, size=size.tiny)
plotshape(short, style=shape.circle, color=color.red, location=location.abovebar, size=size.tiny)
 
alertcondition(long, title="Signal Long!", message="Signal Long!")
alertcondition(short, title="Signal Short!", message="Signal Short!")

← 返回列表