답변완료
주석요청
안녕하세요?
아래 스크립트에 주석 부탁드립니다.
감사합니다.
var1 = ma(c,3);
var2 = ma(c,9);
var3 = ma(c,81);
Condition1 = var1 < Var3 and Var2 > Var3;
Condition2 = var1 > Var3 and Var2 < var3;
if NextBarSdate != sDate Then
{
if DayClose(1) < DayOpen(1) and DayClose(0) > DayOpen(0) Then
{
if max(DayClose(1),DayOpen(1)) > max(DayClose(0),DayOpen(0)) and
min(DayClose(1),DayOpen(1)) < min(DayClose(0),DayOpen(0)) and
condition2 == true
Then
Buy("b1",AtMarket);
if max(DayClose(1),DayOpen(1)) < max(DayClose(0),DayOpen(0)) and
min(DayClose(1),DayOpen(1)) > min(DayClose(0),DayOpen(0)) and
condition2 == true then
Buy("b2",AtMarket);
}
if DayClose(1) > DayOpen(1) and DayClose(0) < DayOpen(0) Then
{
if max(DayClose(1),DayOpen(1)) > max(DayClose(0),DayOpen(0)) and
min(DayClose(1),DayOpen(1)) < min(DayClose(0),DayOpen(0)) and
condition1 == true Then
Sell("s1",AtMarket);
if max(DayClose(1),DayOpen(1)) < max(DayClose(0),DayOpen(0)) and
min(DayClose(1),DayOpen(1)) > min(DayClose(0),DayOpen(0))and
condition1 == true Then
Sell("s2",AtMarket);
}
}
if MarketPosition == 1 Then
{
if IsEntryName("b1",0) == true and BarsSinceEntry == 7 Then
{
if NextBarOpen >= EntryPrice Then
ExitLong("bx1",AtMarket);
Else
Sell("s3",AtMarket);
}
if IsEntryName("b2",0) == true and BarsSinceEntry == 7 Then
{
if NextBarOpen >= EntryPrice Then
ExitLong("bx2",AtMarket);
Else
Sell("s4",AtMarket);
}
if IsEntryName("b3",0) == true and BarsSinceEntry == 7 Then
{
ExitLong("bx3",AtMarket);
}
if IsEntryName("b4",0) == true and BarsSinceEntry == 7 Then
{
ExitLong("bx4",AtMarket);
}
}
if MarketPosition == -1 Then
{
if IsEntryName("s1",0) == true and BarsSinceEntry == 7 Then
{
if NextBarOpen <= EntryPrice Then
ExitShort("sx1",AtMarket);
Else
Buy("b3",AtMarket);
}
if IsEntryName("s2",0) == true and BarsSinceEntry == 7 Then
{
if NextBarOpen <= EntryPrice Then
ExitShort("sx2",AtMarket);
Else
Buy("b4",AtMarket);
}
if IsEntryName("s3",0) == true and BarsSinceEntry == 7 Then
{
ExitShort("sx3",AtMarket);
}
if IsEntryName("s4",0) == true and BarsSinceEntry == 7 Then
{
ExitShort("sx4",AtMarket);
}
}
2025-04-10
203
글번호 190020
시스템
답변완료
수식변환 부탁드립니다.
안녕하세요
indicator("Power Root SuperTrend [AlgoAlpha]", "AlgoAlpha - Power Root", true, max_lines_count = 500)
import TradingView/ta/8
atrMult = input.float(4.5, "Factor")
atrlen = input.int(12, "ATR Length")
rsmlen = input.int(3, "Root-Mean-Square Length")
tplen = input.int(14, "RSI Take-Profit Length")
green = input.color(#00ffbb, "Bullish Color", group = "Appearance")
red = input.color(#ff1100, "Bearish Color", group = "Appearance")
// SuperTrend Function
superTrendCalc(multiplier, atrLength, source) =>
atrValue1 = ta.atr(atrLength)
upperLevel = source + multiplier * atrValue1
lowerLevel = source - multiplier * atrValue1
previousLowerLevel = nz(lowerLevel[1])
previousUpperLevel = nz(upperLevel[1])
// Ensure continuity of lower and upper bands
lowerLevel := lowerLevel > previousLowerLevel or source[1] < previousLowerLevel ? lowerLevel : previousLowerLevel
upperLevel := upperLevel < previousUpperLevel or source[1] > previousUpperLevel ? upperLevel : previousUpperLevel
// Determine direction and SuperTrend
int trendDirection = na
float trendValue = na
previousTrend = trendValue[1]
// Initialize direction
if na(atrValue1[1])
trendDirection := 1
else if previousTrend == previousUpperLevel
trendDirection := source > upperLevel ? -1 : 1
else
trendDirection := source < lowerLevel ? 1 : -1
// Set SuperTrend value based on direction
trendValue := trendDirection == -1 ? lowerLevel : upperLevel
[trendValue, trendDirection]
[superTrendValue, trendDirection] = superTrendCalc(atrMult, atrlen, ta.rms(close, rsmlen))
dist = math.abs(close-superTrendValue)
var chg = 0.0
var tp1 = 0.0
var tp2 = 0.0
var tp3 = 0.0
var tp4 = 0.0
var tp5 = 0.0
var tp6 = 0.0
var tp7 = 0.0
lvlCol = trendDirection > 0 ? red : green
var keys = array.new_line()
var printedtp1 = 0
var printedtp2 = 0
var printedtp3 = 0
var printedtp4 = 0
var printedtp5 = 0
var printedtp6 = 0
var printedtp7 = 0
if ta.cross(trendDirection, 0)
keys.clear()
printedtp1 := 0
printedtp2 := 0
printedtp3 := 0
printedtp4 := 0
printedtp5 := 0
printedtp6 := 0
printedtp7 := 0
chg := math.abs(superTrendValue-superTrendValue[1])
tp1 := superTrendValue[1] + (trendDirection > 0 ? -chg : chg)
tp2 := superTrendValue[1] + (trendDirection > 0 ? -chg * 2 : chg * 2)
tp3 := superTrendValue[1] + (trendDirection > 0 ? -chg * 3 : chg * 3)
tp4 := superTrendValue[1] + (trendDirection > 0 ? -chg * 4 : chg * 4)
tp5 := superTrendValue[1] + (trendDirection > 0 ? -chg * 5 : chg * 5)
tp6 := superTrendValue[1] + (trendDirection > 0 ? -chg * 6 : chg * 6)
tp7 := superTrendValue[1] + (trendDirection > 0 ? -chg * 7 : chg * 7)
keys.push(line.new(bar_index[1], tp1, bar_index, tp1, color = lvlCol, width = 2))
printedtp1 := 1
tp = ta.crossunder(ta.rsi(dist, tplen), 60)
extreme = trendDirection > 0 ? low : high
extreme_tp1_dist = math.abs(extreme - tp1)
extreme_tp2_dist = math.abs(extreme - tp2)
extreme_tp3_dist = math.abs(extreme - tp3)
extreme_tp4_dist = math.abs(extreme - tp4)
extreme_tp5_dist = math.abs(extreme - tp5)
extreme_tp6_dist = math.abs(extreme - tp6)
extreme_tp7_dist = math.abs(extreme - tp7)
p = plot(superTrendValue, color = trendDirection > 0 ? color.new(red, 70) : color.new(green, 70))
upTrend = plot(close > superTrendValue ? superTrendValue : na, color = color.new(green, 70), style = plot.style_linebr) //, force_overlay = true
downTrend = plot(close < superTrendValue ? superTrendValue : na, color = color.new(red, 70), style = plot.style_linebr, force_overlay = false) //, force_overlay = true
bodyMiddle = plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle",display = display.none)
fill(bodyMiddle, upTrend, (open + close) / 2, superTrendValue, color.new(green, 95), color.new(green, 70))
fill(bodyMiddle, downTrend, superTrendValue, (open + close) / 2, color.new(red, 70), color.new(red, 95))
plotchar(tp and trendDirection > 0, "RSI-Based Shorts TP", "X", location.belowbar, red, size = size.tiny)
plotchar(tp and trendDirection < 0, "RSI-Based Longs TP", "X", location.abovebar, green, size = size.tiny)
if printedtp2 == 0 and extreme_tp2_dist < extreme_tp1_dist
keys.push(line.new(bar_index[1], tp2, bar_index, tp2, color = lvlCol, width = 2))
printedtp2 := 1
if printedtp3 == 0 and extreme_tp3_dist < extreme_tp2_dist
keys.push(line.new(bar_index[1], tp3, bar_index, tp3, color = lvlCol, width = 2))
printedtp3 := 1
if printedtp4 == 0 and extreme_tp4_dist < extreme_tp3_dist
keys.push(line.new(bar_index[1], tp4, bar_index, tp4, color = lvlCol, width = 2))
printedtp4 := 1
if printedtp5 == 0 and extreme_tp5_dist < extreme_tp4_dist
keys.push(line.new(bar_index[1], tp5, bar_index, tp5, color = lvlCol, width = 2))
printedtp5 := 1
if printedtp6 == 0 and extreme_tp6_dist < extreme_tp5_dist
keys.push(line.new(bar_index[1], tp6, bar_index, tp6, color = lvlCol, width = 2))
printedtp6 := 1
if printedtp7 == 0 and extreme_tp7_dist < extreme_tp6_dist
keys.push(line.new(bar_index[1], tp7, bar_index, tp7, color = lvlCol, width = 2))
printedtp7 := 1
if keys.size() > 0
aSZ = keys.size()
for i = aSZ - 1 to 0
keys.get(i).set_x2(bar_index)
// Alert when SuperTrend changes direction
alertcondition(ta.cross(trendDirection, 0), title="SuperTrend Direction Change", message="SuperTrend has changed direction")
// Alert when each TP line is drawn
alertcondition(printedtp1 == 1, title="TP1 Line Drawn", message="TP1 line has been drawn")
alertcondition(printedtp2 == 1, title="TP2 Line Drawn", message="TP2 line has been drawn")
alertcondition(printedtp3 == 1, title="TP3 Line Drawn", message="TP3 line has been drawn")
alertcondition(printedtp4 == 1, title="TP4 Line Drawn", message="TP4 line has been drawn")
alertcondition(printedtp5 == 1, title="TP5 Line Drawn", message="TP5 line has been drawn")
alertcondition(printedtp6 == 1, title="TP6 Line Drawn", message="TP6 line has been drawn")
alertcondition(printedtp7 == 1, title="TP7 Line Drawn", message="TP7 line has been drawn")
// Alert for crossing under RSI
alertcondition(tp, title="Take-Profit Condition", message="Take-Profit condition met")
2025-04-10
381
글번호 190019
지표