Buy Long and Sell Short

Long op:

first ‘buy’ and ‘sell’ cost myself money

A stock now price is 100RMB ,and a year late is 200RMB ,buy Long is(vol=100):
cost is :100 × \times × 100=10000RMB → \rightarrow now is ‘buy Long’
sell is :200 × \times × 100=20000RMB → \rightarrow now is ‘sell Long’

-10000RMB cost basis+20000RMB sale proceeds =10000RMB profit

Short op:

first ‘sell’ and ‘buy’ by borrow stocks

A stock now price is 200RMB ,and a year late is 100RMB ,sell Short is(vol=100):
sell is :200 × \times × 100=10000RMB → \rightarrow now is ‘sell Short’(borrow stocks to sell)
buy is :200 × \times × 100=20000RMB → \rightarrow now is ‘sell Long’(buy stocks to replay)

profit is : 20000RMB sale proceeds-10000RMB cost basis -100RMB interest=9900RMB
//@version=4 strategy("策略测试V1.0 ", overlay = true) // UT BOOT 部分 LONG a = input(1, title = "Long_Key Vaule. 'This changes the sensitivity'") c = input(22, title = "Long_ATR Period") h = input(false, title = "Long_Signals from Heikin Ashi Candles") xATR = atr(c) nLoss = a * xATR src = h ? security(heikinashi(syminfo.tickerid), timeframe.period, close, lookahead = false) : close xATRTrailingStop = 0.0 xATRTrailingStop := iff(src > nz(xATRTrailingStop[1], 0) and src[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), src - nLoss), iff(src < nz(xATRTrailingStop[1], 0) and src[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), src + nLoss), iff(src > nz(xATRTrailingStop[1], 0), src - nLoss, src + nLoss))) pos = 0 pos := iff(src[1] < nz(xATRTrailingStop[1], 0) and src > nz(xATRTrailingStop[1], 0), 1, iff(src[1] > nz(xATRTrailingStop[1], 0) and src < nz(xATRTrailingStop[1], 0), -1, nz(pos[1], 0))) xcolor = pos == -1 ? color.red: pos == 1 ? color.green : color.blue ema = ema(src,1) above = crossover(ema, xATRTrailingStop) below = crossover(xATRTrailingStop, ema) buy = src > xATRTrailingStop and above barbuy = src > xATRTrailingStop plotshape(buy, title = "Buy", text = 'Buy', style = shape.labelup, location = location.belowbar, color= color.green, textcolor = color.white, transp = 0, size = size.tiny) barcolor(barbuy ? color.green : na) alertcondition(buy, "UT Long", "UT Long") // UT BOOT 部分 // UT BOOT 部分 SHORT a_1 = input(1, title = "Short_Key Vaule. 'This changes the sensitivity'") c_1 = input(22, title = "Short_ATR Period") h_1 = input(false, title = "Short_Signals from Heikin Ashi Candles") xATR_1 = atr(c_1) nLoss_1 = a_1 * xATR_1 src_1 = h_1 ? security(heikinashi(syminfo.tickerid), timeframe.period, close, lookahead = false) : close xATRTrailingStop_1 = 0.0 xATRTrailingStop_1 := iff(src_1 > nz(xATRTrailingStop_1[1], 0) and src_1[1] > nz(xATRTrailingStop_1[1修复代修到直接能用的
03-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值