簡體   English   中英

如何使我的腳本同時適用於 Macd 和 ema 的買入和賣出指標作為 pine 腳本中的條件

[英]How do I make my script work for both buy and sell indicators for Macd and ema as conditions in pine scripting

所以我的 pine 腳本有問題,我剛開始使用 pine 腳本,所以在瀏覽了一些相關問題的答案后,我想出了一個修改后的腳本,但我遇到了一些問題,因為我的腳本做了我想要的當談到賣出指標時,它並沒有給我我想要的買入指標。

基本上,我希望它在我的 macd 穿過我在腳本上繪制的 ema 下方時顯示賣出指標,並且只有當 macd 穿過 ema 時它才應該向我顯示買入信號。 請參閱下面的腳本。

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © okonfortunesam

//@version=4
study("Fortune sell script", overlay=true, resolution="")

//input
emaLength = input(200, minval=1, title ="Length")
srce = input(close, title="Source")
offset = input(title="Offset", type=input.integer,  defval=0, minval=-500, maxval=500)
out = ema(srce,emaLength)
macd_default = input(title="macd length", type=input.integer, defval=9, minval=1)
fast_l = input(title="Fast length", type= input.integer, defval=12)
slow_l = input(title="Slow length", type= input.integer, defval=26)

//calculations
fast_ma= ema(close, fast_l)
slow_ma= ema(close, slow_l)
macd = fast_ma - slow_ma
amacd = ema(macd, macd_default)
d_macd = macd - amacd

// Deternine if we are currently LONG
isLong = false
isLong := nz(isLong[1], false)

// Determine if we are currently SHORT
isShort = false
isShort := nz(isShort[1], false)


halfMod =  out % 2

d_macdUp = crossover(d_macd, 0)

d_macdDwn = crossunder(d_macd, 0)


//creating conditions for crosses above ema and below ema for both buy and sell indicators
buySig = not isLong and (d_macdUp) and (close > out)
sellSig = not isShort and (d_macdDwn) and (close < out)

if (buySig)
    isLong := true
    isShort := false

if (sellSig)
    isLong := false
    isShort := true
    

//plot the shape of the indicators and colors
//plotshape(series=buySig, text="BUY", style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)

plotshape(series=sellSig, text="SELL", style=shape.triangledown, location=location.abovebar, color= color.red, size= size.small)

//plot the ema to visualise the process
plot(out, title="EMA", color= color.blue, offset = offset)

plot(close)

當我現在取出帶有buySig = not isLong and (d_macdUp) and (close > out)的部分並將其替換為buySig = not isLong and (d_macdUp)時,賣出信號根據我想要的方式顯示,但不是在代碼時buySig的代碼與sellSig的代碼相反。

我需要的是一個腳本,當我取出那段代碼並注釋掉購買信號的plotshape時,該腳本的工作方式與賣出指標的工作方式相同。 我需要根據指定的條件顯示買入和賣出指標。

最終找到了解決這個問題的方法。

我添加了 a and (d_macd >0)用於購買,反之亦然用於出售,分別添加到行

buySig = not isLong and (d_macdUp) and (close > out)
sellSig = not isShort and (d_macdDwn) and (close < out)

Buy = close > ema and LONG Sell = close < ema and SHORT

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM