1

我一直在编辑我在 TradingView 上遇到的策略(它被称为 Slingshot 策略,链接在此处),并且我一直在尝试创建一个条件来购买,当绿色箭头出现在底部时屏幕首先出现在当前蜡烛收盘时。我没有取得太大进展,我是使用 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

应该作为条件运算符工作,但在主图表上没有放置买入交易,并且策略测试器在概览部分显示“无数据”。我不确定我做错了什么。

任何帮助或建议将不胜感激。

4

0 回答 0