创建脚本
image-20220805090419433
image-20220805090419433
这是初始样子
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rum7126
//@version=5
indicator("我的脚本");
plot(close); // 收盘价绘图
version pine 版本
plot 绘图(点连线)
右侧添加到图标就可以执行了,上面那段简单的测试代码,意为创建一个指标以收盘价进行绘图,效果如下
image-20220805091405924
image-20220805091405924
代码提示
鼠标移动至函数名, Ctrl+鼠标左键image-20220805093337659
image-20220805093337659
Pine 编程
脚本模式
模式 说明
indicator 指标
strategy 策略(可以回测)
library 库的声明
价格调用
如果要调用前面第3跟K线,那么就要用下标标注如: close[3]
价格模式 说明
close 收盘价
open 开盘价
high 最高价
low 最低价
atr = ta.atr(14) // 如果要调用往前数第 10 跟蜡烛图的 ATR 值
plot(art[10], color=color.white) // 根据往前数第10跟蜡烛图的atr值划线,白色
数据类型
类型 写法
整数 integer
浮点小数 float
布尔 boolean
颜色 color
字符 string
用户输入设置
inputvalue=input.bool(title="On/Off", defval=true, tooltip="提示语", group="设置分区1", inline="x", confirm=true)
关键词 说明
title 设置名称
defval 默认值:minival-最小值, maxval-最大值,step-输入值每次最小增减值
options 限制用户只能在列表中选择输入值 option=[1,2,3,4]
tooltip 提示语
group 设置分区
inline 当需要将参数在同一行现实时试用
confirm 定义为 true 则在调用程序前强制用户设置参数
在设置不同类型的输入值时,其参数也会不同,下面的示例展示了很多可能性
//@version=5
indicator("array.new_line example")
inputvalue=input.bool(title="On/Off", defval=true, tooltip="Turn on/off this setting", group="General Setting", inline="x", confirm=true)
inputColor = input.color(title="Color", defval=color.black)
inputInteger = input.int(title="Whole Number", defval=5, options=[1, 2, 3, 4, 5])
inputFloat = input.float(title="Decimal Number", defval=-0.5, minval=-3.14, maxval=3.14, step=0.01)
inputSymbol = input.symbol(title="Symbol", defval="SPY")
inputPrice = input.price(title="Price", defval=0.0)
inputSource = input.source(title="Source", defval=close)
inputString = input.string(title="String", defval="A", options=["A", "B", "C"], tooltip="Select an option")
// --- GET TIME INPUTS --- //
var G_TIME = "Time Settings"
inputTime = input.time(title="Time", defval=timestamp("01 Jan 2000 13:30 +0000"), group=G_TIME)
inputResolution = input.timeframe(title="Timeframe", defval="D", group=G_TIME)
inputSession = input.session(title="Session", defval="0300-1300", group=G_TIME)
plot(close)
image-20220816231512238
image-20220816231512238
工具箱
类型 快捷输入
技术分析 Technical Analysis ta.xxx
文本处理 String / Text str.xxx
财务信息调用 request.xxx
自定义工具类 Libraries
绘图选择
绘图模式 说明
默认 添加到下方
indicator(name, overlay=true) 添加在图标中
绘制均线
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rum7126
//@version=5
indicator("我的脚本", (overlay = true));
// technical analysis 技术分析库
ma20 = ta.sma(close, 20); // simple moving average : 简单 ma 均线
plot(ma20, (color = color.red), (linewidth = 2)); // 加粗 + 变色
变色均线
当前均线值 > 上一个均线, 改变颜色
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rum7126
//@version=5
indicator("我的脚本", overlay=true)
// technical analysis 技术分析库
ma14 = ta.sma(close, 14)
_color = if ma14 > ma14[1] // 当前均线值 > 上一个均线 ma14[1]
color.green
else
color.red
plot(ma14, color=_color, linewidth=3)
image-20220805103448591
image-20220805103448591
均线填充
给 ema 区块进行颜色填充
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © rum7126
//@version=5
indicator("金叉死叉均线区域填充", overlay=true)
// technical analysis 技术分析库
// 取均线
maA = ta.ema(close, 32)
maB = ta.ema(close, 64)
// 画均线
line1 = plot(maA, color=color.red)
line2 = plot(maB, color=color.blue)
// 获取金叉死叉
gold = ta.crossover(maA, maB) // 金叉
dead = ta.crossunder(maA, maB) // 死叉
// 金叉死叉信号绘制
plotchar(gold, char="买", location=location.belowbar, color=color.green, size=size.tiny) // location: 位置上方
plotchar(gold, char="卖", location=location.abovebar, color=color.red, size=size.tiny)
// 填充背景 fill 填充
_color = maA>maB ? color.new(#ff0000, 80) : color.new(#00ff00, 80) // 三元运算,颜色变化, 80 的透明度
fill(line1, line2, color=_color)
image-20220805111000181
image-20220805111000181
警报通知
- alert 用于触发报警事件,可以在图标上创建报警对话框中调用,可以在if中嵌套,并且可以引用动态数值
- alertcondition 创建警报条件,在创建警报话框中可用。 请注意,alertcondition不会创建警报,它只会在创建警报对话框中为您提供更多选项。 此外,alertcondition效果在图表上是看不见的。
//@version=5
indicator("example")
hc=close>high[1] // hc=high close
lc=close<low[1] // lc=low close
if hc
alert("当前蜡烛比前一个高: " + str.tostring(close), alert.freq_once_per_bar_close)
if lc
alert("当前蜡烛比前一个底: " + str.tostring(close), alert.freq_once_per_bar_close)
alertcondition(hc,"测试:提示", "出发:当前蜡烛比前一个高") //禁止调用动态的信息
plot(close)
image-20220816232404891
image-20220816232404891
常见指标开发
震荡指标
趋势指标
MACD
//@version=5
indicator("MACD")
[macdLine, signalLine, histLine] = ta.macd(close, 12, 26, 9)
plot(macdLine, color=color.blue) // macd 线
plot(signalLine, color=color.orange) // 信号线
plot(histLine, color=color.red, style=plot.style_histogram) // 柱子
image-20220805141007049
image-20220805141007049
上面是调用 ta 中现成的 macd 函数,如果我们自己写的话如下
//@version=5
indicator("MACD")
macd(src, fastLen, slowLen, signaLen) => // 定义函数
fastMA = ta.ema(src, fastLen) // 快线
slowMA = ta.ema(src, slowLen) // 慢线
macd = fastMA - slowMA // macd 线(蓝线)
signal = ta.ema(macd, signaLen) // 橙线 信号线
hist = macd - signal // 柱子
[macd, signal, hist] // 返回三个参数
[macdLine, signalLine, histLine] = macd(close, 12, 26, 9)
plot(macdLine, color=color.blue) // macd 线
plot(signalLine, color=color.orange) // 信号线
// 变色上涨绿色,下跌红色
plot(histLine, color=histLine>histLine[1]?color.green:color.red, style=plot.style_histogram)
image-20220805141710280
image-20220805141710280
趋势指标
均线
MACD线
DMI趋向系统
OBV能量潮
震荡指标
MACD 柱子
RSI
CCI
KD
KDJ
William
%R
shower 游客 2022-10-30 18:21 回复
Slut twink, Assfucking, Stepfather. Horny chick
with red hair twists her juicy ass in front of a webcam and
masturbates a wet hole with a pink dildo. Videos: https://bit.ly/3CQIsjT / https://bit.ly/3AHfMXV / https://bit.ly/3cGuhn0 / Dirty, Hot chicks fucking, Fucked hard.
1 游客 2023-04-12 14:03 回复
555
1 游客 2023-04-12 14:21 回复
555