Построение на основе 3 значений - PullRequest
0 голосов
/ 29 января 2020

Я нашел скрипт и хотел бы настроить его так, чтобы на основном графике отображались оповещения и графики, но я застрял в том, как это сделать.

Я рассчитываю построить сигнал, когда все 3 столбца гистограммы имеют светлый цвет, а затем снова, когда все они переключаются на темный сигнал

Буду признателен за любую помощь или направление.

Спасибо,

'''
study(title="3 Linear Regression Curve", shorttitle="Triple LRC", overlay=false)
src = close
len1 = input(10)
len2 = input(14)
len3 = input(30)
offset = 0
reg1 = linreg(src, len1, offset)
reg2 = linreg(src, len2, offset)
reg3 = linreg(src, len3, offset)

hist1 = 3
hist2 = 2
hist3 = 1

plot(hist1,style=histogram,color=reg1>reg1[1]?aqua:blue,transp=0,linewidth=3)
plot(hist2,style=histogram,color=reg2>reg2[1]?yellow:orange,transp=0,linewidth=3)
plot(hist3,style=histogram,color=reg3>reg3[1]?lime:green,transp=0,linewidth=3)
'''

1 Ответ

3 голосов
/ 29 января 2020

В подобных случаях, когда вы используете overlay=false, было бы неплохо иметь другой скрипт для просмотра ваших возможных сигналов покупки и продажи с функцией plotshape().

Вы должны быть осторожны с покупкой и сигналы на продажу. Вы будете получать оповещения для каждого бара, где один из ваших сигналов TRUE. В идеале вы хотите иметь один сигнал ПОКУПКИ, а затем один сигнал ПРОДАЖИ.

Посмотрите на следующий сценарий:

//@version=4
study(title="3 Linear Regression Curve Overlay", shorttitle="Triple LRC", overlay=true)
src = close
len1 = input(10)
len2 = input(14)
len3 = input(30)

var isLong = false      // Flag to see if you are already long
var isShort = false     // Flag to see if you are already short

offset = 0
reg1 = linreg(src, len1, offset)
reg2 = linreg(src, len2, offset)
reg3 = linreg(src, len3, offset)

hist1 = 3
hist2 = 2
hist3 = 1

buyCondition = not isLong and (reg1 > reg1[1]) and (reg2 > reg2[1]) and (reg3 > reg3[1])        // Go long only if you are not already long
sellCondition = not isShort and (reg1 <= reg1[1]) and (reg2 <= reg2[1]) and (reg3 <= reg3[1])   // Go short only if you are not already short

if (buyCondition)       // Set flags
    isLong := true
    isShort := false

if (sellCondition)      // Set flags
    isLong := false
    isShort := true
plotshape(series=buyCondition, text="BUY", style=shape.triangleup, color=color.green, location=location.belowbar, size=size.small)
plotshape(series=sellCondition, text="SELL", style=shape.triangledown, color=color.red, location=location.abovebar, size=size.small)

Это построит график ПОКУПКИ только тогда, когда у вас короткая позиция, и ПРОДАЖА только когда вы длинны.

Как только вы установите sh, вы просто конвертируете свое условие покупки и продажи в оповещения.

//@version=4
study(title="3 Linear Regression Curve", shorttitle="Triple LRC", overlay=false)
src = close
len1 = input(10)
len2 = input(14)
len3 = input(30)

var isLong = false
var isShort = false

offset = 0
reg1 = linreg(src, len1, offset)
reg2 = linreg(src, len2, offset)
reg3 = linreg(src, len3, offset)

hist1 = 3
hist2 = 2
hist3 = 1

buyCondition = not isLong and (reg1 > reg1[1]) and (reg2 > reg2[1]) and (reg3 > reg3[1])        // Go long only if you are not already long
sellCondition = not isShort and (reg1 <= reg1[1]) and (reg2 <= reg2[1]) and (reg3 <= reg3[1])   // Go short only if you are not already short

if (buyCondition)       // Set flags
    isLong := true
    isShort := false

if (sellCondition)      // Set flags
    isLong := false
    isShort := true

alertcondition(condition=buyCondition, title="Alert: All light colors", message="BUY")
alertcondition(condition=sellCondition, title="Alert: All dark colors", message="SELL")

plot(hist1, style=plot.style_histogram, color= reg1 > reg1[1] ? color.aqua:color.blue, transp=0,linewidth=3)
plot(hist2, style=plot.style_histogram, color= reg2 > reg2[1] ? color.yellow:color.orange, transp=0,linewidth=3)
plot(hist3, style=plot.style_histogram, color= reg3 > reg3[1] ? color.lime:color.green, transp=0,linewidth=3)

Пожалуйста, помните, что вы должны установить оповещения вручную как описано здесь и здесь .

enter image description here

...