我一直在编辑我在TradingView上遇到的策略(称为Slingshot策略,其链接为here),并且我一直在尝试为绿色箭头创建“购买”条件屏幕底部出现的图标首先出现在当前蜡烛的关闭位置。 我没有太大的进步,我是第一次使用PineScript进行编码。
strategy("UCS_Momentum Oscillator Upper", overlay=true, initial_capital=10000, currency='GBP')
sae = input(true, title="Show Aggressive Entry?, Or Use as Alert To Potential Conservative Entry?")
sce = input(true, title="Show Conservative Entry?")
st = input(true, title="Show Trend Arrows at Top and Bottom of Screen?")
def = input(false, title="Only Choose 1 - Either Conservative Entry Arrows or 'B'-'S' Letters")
pa = input(true, title="Show Conservative Entry Arrows?")
sl = input(false, title="Show '↑'-'↓' Letters?")
ma1 = ema(close, 13)
ma2 = ema(close, 21)
ma3 = ema(close, 34)
ma = ema(close, 89)
range = tr
rangema = ema(range, 89)
upper = ma + rangema * 0.5
lower = ma - rangema * 0.5
midChan = (upper + lower)/2
//Trend Definition
tr_up = ma1 > upper and ma2 > upper and ma3 > upper
tr_down = ma1 < lower and ma2 < lower and ma3 < lower
//Aggressive Entry
pullbackUpT() => tr_up and close < upper
pullbackDnT() => tr_down and close > lower
//Conservative Entry
entryUpT() => tr_up and close[1] < upper and close > upper
entryDnT() => tr_down and close[1] > lower and close < lower
//Conservative Entry True/False Condition
entryUpTrend = ma1 > upper and ma2 > upper and ma3 > upper and close[1] < upper and close > upper ? 1 : 0
entryDnTrend = ma1 < lower and ma2 < lower and ma3 < lower and close[1] > lower and close < lower ? 1 : 0
//Define Up and Down Trend for Trend Arrows at Top and Bottom of Screen
upTrend = ma1 > upper and ma2 > upper and ma3 > upper
downTrend = ma1 < lower and ma2 < lower and ma3 < lower
//Definition for Conservative Entry Up and Down PlotArrows
codiff = entryUpTrend == 1 ? entryUpTrend : 0
codiff2 = entryDnTrend == 1 ? entryDnTrend : 0
//Trend Color Definition for Moving Averages and Channel
scolor = tr_up ? green : tr_down ? red : blue
barcolor(sae and pullbackUpT() ? yellow : sae and pullbackDnT() ? yellow : na)
barcolor(sce and entryUpT() ? aqua : sce and entryDnT() ? aqua : na)
//Plot 3 MA's
plot(ma1, title="Fast MA", color=scolor, style=circles, linewidth=1)
plot(ma2, title="Medium MA",color=scolor, style=circles, linewidth=2)
plot(ma3, title="Slow MA", color=scolor, style=circles, linewidth=3)
//Channel Plots
p1 = plot(upper, title="Upper Channel", color=scolor, style=line, linewidth=3)
p2 = plot(midChan, title="Upper Channel", color=silver, style=line, linewidth=1)
p3 = plot(lower, title="Lower Channel", color=scolor, style=line, linewidth=3)
fill(p1, p2, color=lime, transp=70)
fill(p2, p3, color=red, transp=70)
//Trend Triangles at Top and Bottom of Screen
plotshape(st and upTrend ? upTrend : na, title="Conservative Buy Entry Triangle",style=shape.triangleup, location=location.bottom, color=lime, transp=0, offset=0)
plotshape(st and downTrend ? downTrend : na, title="Conservative Short Entry Triangle",style=shape.triangledown, location=location.top, color=red, transp=0, offset=0)
//Plot Arrows OR Letters ↑ and ↓ for Buy Sell Signals
plotarrow(pa and codiff ? codiff : na, title="Up Entry Arrow", colorup=lime, maxheight=60, minheight=50, transp=0)
plotarrow(pa and codiff2*-1 ? codiff2*-1 : na, title="Down Entry Arrow", colordown=red, maxheight=60, minheight=50, transp=0)
plotchar(sl and codiff ? low - tr : na, title="Buy Entry", offset=0, char='↑', location=location.absolute, color=lime, transp=0)
plotchar(sl and codiff2 ? high + tr : na, title="Short Entry", offset=0, char='↓', location=location.absolute, color=red, transp=0)
//Entry and Exit Conditions
BuyCondition = ma1 > upper and ma2 > upper and ma3 > upper and ((ma1[1] < upper) or (ma2[1] < upper) or (ma3[1] < upper)) ? 1 : 0
if (BuyCondition) == 1
strategy.entry("Main Buy", true, stop=350)
if (BuyCondition) == 0
strategy.close("Main Buy")
为庞大的代码块表示歉意,这主要是我自己实现的最后一部分编码,但我想将其余部分包括在内,因为我要实现的逻辑与编码有关。它上面。由于我专注于出现在给定绿色箭头组中的第一个绿色箭头,因此我认为以下内容
BuyCondition = ma1 > upper and ma2 > upper and ma3 > upper and ((ma1[1] < upper) or (ma2[1] < upper) or (ma3[1] < upper)) ? 1 : 0
应该是有条件的运算符,但是在主图表上没有任何买入交易,并且策略测试器在“概述”部分显示“无数据”。我不确定自己在做什么错。
任何帮助或建议将不胜感激。