如何切换买入和卖出

问题描述 投票:0回答:1

如何将条件从“买入”(当前脚本)更改为同时支持“卖出”

enter code here
//@version=5
indicator("Fix % Stop Loss Take Profit", overlay=true)

Price = input.price(defval = 0,confirm = true)
slF = input.float(title="Short % Below Price", defval=0.5, minval=0, step=0.001) * 0.01
tpF = input.float(title="Long  % Above Price", defval=1.0, minval=0, step=0.001) * 0.01
h = Price
short = (h * (1 - slF)) 
long  = (h * (1 + tpF))

Buy = input.bool(true)
Sell = input.bool(false)

//Condition

plot(h,color=color.white,linewidth = 5)
plot(short,color=color.red,linewidth = 5)
plot(long,color=color.lime,linewidth = 5)
pine-script-v5
1个回答
0
投票
//@version=5
indicator("Long & Short Position", "L & S",overlay=true,precision = 4)

Price = input.price(defval = 0,confirm = true, title = "Entry Price")
sl    = input.price(defval = 0,confirm = true, title = "Stop Loss") 

rr = input.float(title="Risk Reward Ratio", defval=1.5, minval = 1.00, 
step=0.10)

diff   = Price - sl
target = (diff * rr) + Price

plot(Price,color=color.white,linewidth = 1)
plot(sl,color=color.red,linewidth = 1)
plot(target,color=color.lime,linewidth = 1)

var label label1 = na
var label label2 = na
var label label3 = na

if barstate.islast
tabel1 = label.new(bar_index + 1, Price, text = "Entry Price", xloc = 
xloc.bar_index, yloc = yloc.price,style = label.style_label_left,textcolor 
= color.black,color=color.orange)
tabel2 = label.new(bar_index + 1, sl, text = "Stop Loss", xloc = 
xloc.bar_index, yloc = yloc.price,style = label.style_label_left,textcolor 
= color.black,color=color.red)
tabel3 = label.new(bar_index + 1, target, text = "Take Profit", xloc = 
xloc.bar_index, yloc = yloc.price,style = label.style_label_left,textcolor 
= color.black,color=color.lime)
© www.soinside.com 2019 - 2024. All rights reserved.