답변완료
재문의 드립니다.
//@version=5
indicator(
"Fourier For Loop [BackQuant]",
shorttitle="",
overlay=false,timeframe="",
timeframe_gaps=true
)
const string ui = "UI Settings"
const string inputs = "Calculation Settings"
const string scoring = "Signals"
xval = input.source(hlc3, "Calculation Source", group = inputs, inline = "2222")
N = input.int(1, minval=1, title="Calculation Period", group = inputs, inline = "2222")
start = input.int(1, "Calculation Start", group = inputs,inline = "1s")
end = input.int(45, maxval = 50, title = "Calculation End", group = inputs,inline = "1s")
upper = input.int(40, "Long Threshold",group = scoring)
lower = input.int(-10, "Short Threshold",group = scoring)
simple bool showthres = input.bool(true, "Show Threshold Lines?", group = ui)
simple bool paintCandles = input.bool(false, "Color Bars According to Trend?", group = ui)
simple bool bgcol_ = input.bool(false, "Background Colour", group = ui)
int linew = input.int(3, "Signal Line Width", 1,4,1, group = ui)
color longcol = input.color(#00ff00, "Long Colour", group = ui, inline = "xxxx")
color shortcol = input.color(#ff0000, "Short Colour", group = ui, inline = "xxxx")
DFT(x, y, Nx, _dir) =>
float _arg = 0.0
float _cos = 0.0
float _sin = 0.0
float xArr_i = 0.0
float yArr_i = 0.0
xArr = array.new_float(array.size(x))
yArr = array.new_float(array.size(y))
for i = 0 to Nx - 1 by 1
xArr_i := 0.0
yArr_i := 0.0
kx = float(i) / float(Nx)
_arg := -_dir * 2 * math.pi * kx
for k = 0 to Nx - 1 by 1
_cos := math.cos(k * _arg)
_sin := math.sin(k * _arg)
xArr_i += array.get(x, k) * _cos - array.get(y, k) * _sin
yArr_i += array.get(x, k) * _sin + array.get(y, k) * _cos
yArr_i
array.set(xArr, i, xArr_i)
array.set(yArr, i, yArr_i)
if _dir == 1
for i = 0 to Nx - 1 by 1
array.set(x, i, array.get(xArr, i) / float(Nx))
array.set(y, i, array.get(yArr, i) / float(Nx))
else
for i = 0 to Nx - 1 by 1
array.set(x, i, array.get(xArr, i))
array.set(y, i, array.get(yArr, i))
x = array.new_float(N, 0.0)
y = array.new_float(N, 0.0)
for i = 0 to N - 1
array.set(x, i, xval[i])
array.set(y, i, 0.0)
DFT(x, y, N, 1)
mag = array.new_float(N, 0.0)
for i = 0 to N - 1
mag_i = math.sqrt(math.pow(array.get(x, i), 2) + math.pow(array.get(y, i), 2))
array.set(mag, i, mag_i)
subject = array.get(mag,0)
forloop(start, end) =>
return_val = 0.0
for i = start to end by 1
return_val += (subject > subject[i] ? 1 : -1)
return_val
return_val
score = forloop(start, end)
L = score > upper
S = ta.crossunder(score, lower)
var out = 0
if L and not S
out := 1
if S
out := -1
plot(score, "FFL", color = out == 1 ? longcol : out == -1 ? shortcol : color.gray, linewidth = linew)
barcolor(paintCandles ? (out == 1 ? longcol : out == -1 ? shortcol : color.gray) : na)
plot(showthres?upper:na, "Long Threshold", longcol)
plot(showthres?lower:na, "Short Threshold", shortcol)
bgcolor(bgcol_?(out == 1 ? color.new(longcol,90) : out == -1 ? color.new(shortcol,90) : color.gray):na)
alertcondition(L and not S, title="Fourier FL Long", message="Fourier FL Long - {{ticker}} - {{interval}}")
alertcondition(S, title="Fourier FL Short", message="Fourier FL Short - {{ticker}} - {{interval}}")
트레이딩뷰 수식인데 예스로 좀 바꿔주세요.
선만 필요한데 선만 작성 좀 해주세요.
뒤에 배경은 필요 없습니다.
2024-10-31
928
글번호 184832
지표
답변완료
추세 돌파
input : Period(150);
Var:j(0),T(0),txx(0);
Var: date11(0),date12(0),time11(0),time12(0),TL1(0),TL(0),
date21(0),date22(0),time21(0),time22(0),
date31(0),date32(0),time31(0),time32(0),tx(0);
Array:HiVal[20](0),LoVal[20](0),HiBar[20](0),LoBar[20](0);
Plot1(value12);
For j = 0 To 19
{
HiBar[j] = HiBar[j] + 1;
LoBar[j] = LoBar[j] + 1;
}
if crossup(H,highest(H,Period)[1]) and (T == 0 or (T==-1 and H >= Loval[0]+0.5)) Then
T = 1;
if CrossDown(L,Lowest(L,Period)[1]) and (T == 0 or (T==1 and L <= Hival[0]-0.5)) Then
T = -1;
If T == -1 Then
{
If T[1] != -1 Then
{
For j = 18 DownTo 0
{
LoVal[j+1] = LoVal[j];
LoBar[j+1] = LoBar[j];
}
LoVal[0] = L;
LoBar[0] = 0;
date11 = date[HiBar[0]];
time11 = stime[HiBar[0]];
Value11 = HiVal[0];
date12 = date[LoBar[0]];
time12 = stime[LoBar[0]];
Value12 = LoVal[0];
TL_Delete(TL);
TL = TL_New(sdate,stime,Value12,NextBarSdate,NextBarStime,NextBarOpen);
TL1 = TL_New(date11,time11,Value11,date12,time12,Value12);
TL_SetColor(TL1,Blue);
date21 = date[HiBar[0]];
time21 = stime[HiBar[0]];
date22 = date[0];
time22 = stime[0];
if abs(value12[1]-value11[1]) < 0.5 Then
Text_Delete(tx);
tx = Text_New(sDate,stime,value12,NumToStr(value11-value12,2));
Text_SetColor(Tx,Blue);
Text_SetStyle(tx,1,0);
Text_SetSize(tx,25);
Text_SetBold(tx,1);
}
If LoVal[0] > L Then
{
LoVal[0] = L;
LoBar[0] = 0;
date12 = date[LoBar[0]];
time12 = stime[LoBar[0]];
Value12 = LoVal[0];
TL_SetEnd(TL1, date12,time12,Value12);
date22 = date[0];
time22 = stime[0];
Text_SetString(tx,NumToStr(value11-value12,2));
Text_SetLocation(tx,sDate,sTime,value12);
}
}
If T == 1 Then
{
If T[1] != 1 Then
{
For j = 18 DownTo 0
{
HiVal[j+1] = HiVal[j];
HiBar[j+1] = HiBar[j];
}
HiVal[0] = H;
HiBar[0] = 0;
date11 = date[LoBar[0]];
time11 = stime[LoBar[0]];
Value11 = LoVal[0];
date12 = date[HiBar[0]];
time12 = stime[HiBar[0]];
Value12 = HiVal[0];
TL_Delete(TL);
TL = TL_New(sdate,stime,Value12,NextBarSdate,NextBarStime,NextBarOpen);
TL1 = TL_New(date11,time11,Value11,date12,time12,Value12);
TL_SetColor(TL1,Red);
date31 = date[LoBar[0]];
time31 = stime[LoBar[0]];
date32 = date[0];
time32 = stime[0];
if abs(value12[1]-value11[1]) < 0.5 Then
Text_Delete(tx);
tx = Text_New(sDate,stime,value12,NumToStr(value12-value11,2));
Text_SetColor(Tx,Red);
Text_SetStyle(tx,1,1);
Text_SetSize(tx,25);
Text_SetBold(tx,1);
}
If HiVal[0] < H Then
{
HiVal[0] = H;
HiBar[0] = 0;
date12 = date[HiBar[0]];
time12 = stime[HiBar[0]];
Value12 = HiVal[0];
TL_SetEnd(TL1, date12,time12,Value12);
date32 = date[0];
time32 = stime[0];
Text_SetString(tx,NumToStr(value12-value11,2));
Text_SetLocation(tx,sDate,sTime,value12);
}
}
TL_SetSize(TL1,1);
새 추세선이 직전추세고점,직전추세저점 돌파시 세로선. 감사합니다.
2024-10-31
785
글번호 184822
지표
답변완료
질문 몇가지 입니다.
input : P(20),mm(50000);
var : R(0),AA(0);
R = RSI(P);
if MarketPosition == 0 and CrossUp(R,20) Then
{
Buy("b",OnClose,Def,mm/C);
AA = mm*1.20;
}
if MarketPosition == 1 Then
{
if CrossUp(R,20) and MaxEntries < 7 Then
{
Buy("bb",OnClose,Def,aa/c);
AA = AA*1.20;
}
if R >= 70 Then
Condition1 = true;
if Condition1 == true Then
{
ExitLong("bx1",AtLimit,AvgEntryPrice*1.01);
}
}
Else
Condition1 = False;
코인이고 피라미딩을 사용합니다.
원래는 이코드를 기초로 이래저래 수정해서 쓰고 있는데 무슨문제 인지 코드가 안올라 갑니다.
그래도 질문엔 크게 문제가 없을꺼 같아. 그냥 올려주신 이전 코드를 올려요.
q1. 원하는 코드 수정안은... 구매시 구매출력문이 ①②③④⑤⑥ 이렇게 나왔으면 합니다. 이게 너무 어려우면 b1,b2,b3,b4 이렇게 나왔으면 합니다.
if문을 구매횟수많큼 쓰면 가능할것도 같은데.. 배우고 있는 만큼 좀더 세련된 코드였음 합니다.
하강율(0.5) 퍼센트를 입력받아. 신호가 나왔을때 이전구매가격 보다 하강율 퍼센트 보다 낮으면 구매를 하게 하고 싶습니다. (제가 뭘 잘못했는지 몰라도 이전구매가격 = c; 이런식으로 코드를 만드니 안되더라구요)
그리고 구매시 구매횟수 배열의 순번 (1,3,5,7,9,12,14,16,19,20)의 순서에만 구매를 했으면 합니다.
q2. 현재 수익율을 알수 있는 방법은 뭘까요?
q3. 코드의 피라미딩 횟수는 현재 12인데 자동 실행시 피라미딩 횟수와 어떻게 영향을 받는지 궁금하고, 또 설정의 구매액도 영향을 받는지 궁금 합니다.
q4. 실제 구매액이 5000원 이렇게 정확히 안되던데.. 원래 그런건가요?
(5번 항목 글만 쓰면... 500 - 서버오류... 찾고 있는 리소스에 문제가 있어 표시할 수 없습니다.라는 메세지가 나오면서 글이 수정이 안되네요. 코드 문제인줄 알았더니 5번 항목 글이 문제네요...뭔가 금칙어가 있나 싶어 글을 별으별수단으로 바꿔도 안올라 갑니다.)
q6. 구매신호가 나왔는데 계좌에 돈이 모자르면 어떻게 되는거죠???
q7. 자동매매가 실행중 코드를 수정하게 되면 어떻게 되죠?
시스템하고 상관없는 질문이 많네요. 죄송합니다. ㅎㅎ
코인은 주식과 또 다른것 같네요...
2024-10-31
725
글번호 184820
시스템
답변완료
수식 부탁드립니다
지표식 부탁드립니다.
1.
study(title="Range", shorttitle="Range", overlay=true)
up30on = input(true, title="30 Minute Range High")
down30on = input(true, title="30 Minute Range Low")
is_newbar(res) => change(time(res)) != 0
adopt(r, s) => security(tickerid, r, s)
high_range = valuewhen(is_newbar('D'),high,0)
low_range = valuewhen(is_newbar('D'),low,0)
up = plot(up30on ? adopt('30', high_range):na, color = lime, style=circles, linewidth=4)
down = plot(down30on ? adopt('30', low_range): na, color = #DC143C, style=circles, linewidth=4)
2.
//@version=4
study("Oikawa Ema", overlay=true)
oikawa0 = security(syminfo.tickerid, "15", ema(close, 15))
plot(oikawa0, color=color.lime, offset=0, linewidth=2)
oikawa1 = security(syminfo.tickerid, "60", ema(close, 15))
plot(oikawa1, color=color.blue, offset=0, linewidth=2)
oikawa2 = security(syminfo.tickerid, "240", ema(close, 15))
plot(oikawa2, color=color.white, offset=0, linewidth=4)
oikawa3 = security(syminfo.tickerid, "15", ema(close, 85))
plot(oikawa3, color=color.gray, offset=0, linewidth=4)
2024-10-31
864
글번호 184819
지표
답변완료
수고하십니다
항상 노고에 감사하며
변환 부탁드립니다
indicator("Zero-Lag MA Trend Levels [ChartPrime]", overlay = true)
// --------------------------------------------------------------------------------------------------------------------}
// 𝙐𝙎𝙀𝙍 𝙄𝙉𝙋𝙐𝙏𝙎
// --------------------------------------------------------------------------------------------------------------------{
int length = input.int(15, title="Length") // Length for the moving average calculations
bool show_levl = input.bool(true, "Trend Levels") // Toggle to show trend levels
// Colors for the trend levels
color up = input.color(#30d453, "+", group = "Colors", inline = "i")
color dn = input.color(#4043f1, "-", group = "Colors", inline = "i")
var box1 = box(na) // Variable to store the box
series float atr = ta.atr(200) // Average True Range (ATR) for trend levels
// --------------------------------------------------------------------------------------------------------------------}
// 𝙄𝙉𝘿𝙄𝘾𝘼𝙏𝙊𝙍 𝘾𝘼𝙇𝘾𝙐𝙇𝘼𝙏𝙄𝙊𝙉𝙎
// --------------------------------------------------------------------------------------------------------------------{
series float emaValue = ta.ema(close, length) // EMA of the closing price
series float correction = close + (close - emaValue) // Correction factor for zero-lag calculation
series float zlma = ta.ema(correction, length) // Zero-Lag Moving Average (ZLMA)
bool signalUp = ta.crossover(zlma, emaValue) // Signal for bullish crossover
bool signalDn = ta.crossunder(zlma, emaValue) // Signal for bearish crossunder
// Determine the color of ZLMA based on its direction
color zlma_color = zlma > zlma[3] ? up : zlma < zlma[3] ? dn : na
color ema_col = emaValue < zlma ? up : dn // Determine the EMA color
// --------------------------------------------------------------------------------------------------------------------}
// 𝙑𝙄𝙎𝙐𝘼𝙇𝙄𝙕𝘼𝙏𝙄𝙊𝙉
// --------------------------------------------------------------------------------------------------------------------{
// Plot the Zero-Lag Moving Average
p1 = plot(zlma, color = zlma_color, linewidth = 1) // Plot ZLMA
p2 = plot(emaValue, color = ema_col, linewidth = 1) // Plot EMA
fill(p1, p2, zlma, emaValue, color.new(zlma_color, 80), color.new(ema_col, 80)) // Fill between ZLMA and EMA
// Method to draw a box on the chart
method draw_box(color col, top, bot, price)=>
box.new(
bar_index, top, bar_index, bot, col, 1,
bgcolor = color.new(col, 90),
text = str.tostring(math.round(price, 2)),
text_size = size.tiny,
text_color = chart.fg_color,
text_halign = text.align_right
)
// Logic to draw trend levels as boxes on the chart
if show_levl
bool check_signals = signalUp or signalDn // Check if there is an up or down signal
switch
// Draw a box when a bullish signal is detected
signalUp => box1 := up.draw_box(zlma, zlma - atr, close)
// Draw a box when a bearish signal is detected
signalDn => box1 := dn.draw_box(zlma + atr, zlma, close)
switch
// Extend the right side of the box if no new signal is detected
not signalUp or not signalDn => box1.set_right(bar_index + 4)
=> box1 := box(na) // Otherwise, reset the box
switch
// Add a downward label when price crosses below the bottom of the box
ta.crossunder(high, box1.get_bottom()) and not check_signals[1] and not check_signals and emaValue > zlma=>
label.new(bar_index - 1, high[1], "▼", color = color(na), textcolor = dn, style = label.style_label_down)
// Add an upward label when price crosses above the top of the box
ta.crossover(low, box1.get_top()) and not check_signals and not check_signals[1] and emaValue < zlma=>
label.new(bar_index - 1, low[1], "▲", color = color(na), textcolor = up, style = label.style_label_up)
// Plot shapes for up and down signals
plotshape(signalUp ? zlma : na, "", shape.diamond, location.absolute, color = up, size = size.tiny)
plotshape(signalDn ? zlma : na, "", shape.diamond, location.absolute, color = dn, size = size.tiny)
// --------------------------------------------------------------------------------------------------------------------}
2024-10-30
871
글번호 184815
지표