IntelTrading

доборы в pine разными объемами

Đào tạo
IntelTrading Cập nhật   
BINANCE:ETHUSDT   Ethereum / TetherUS
Приветствую!

По многочисленным просьбам сделал видео о том, как реализовать на pine доборы позиций на разные объемы. В примере реализовано 3 входа в позицию с тремя дискретными долями от капитала, которые настраиваются в параметрах стратегии. Данное видео дополняет видео из позапрошлой идее (прикрепил его)

Bình luận:
strategy("Моя стратегия", overlay=true, calc_on_every_tick = true, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, slippage = 10, commission_type = strategy.commission.percent, commission_value = 0.1, initial_capital = 10000)


pS = input(12, title = 'period small')
pB = input(21, title = 'period big')


SS = ta.sma(close, pS)
SB = ta.sma(close, pB)

plot(SS, color = color.green)
plot(SB, color = color.red)


longCondition = ta.crossover(SS, SB)
shortCondition = ta.crossunder(SS, SB)


n1 = input(0.2, title = 'доля 1')
n2 = input(0.3, title = 'доля 2')
n3 = 1 - n1 - n2


var m1 = 0.0
var m2 = 0.0
var m3 = 0.0
if strategy.position_size == 0
m1 := n1*strategy.equity
m2 := n2*strategy.equity
m3 := n3*strategy.equity

var N = 0
if strategy.position_size > strategy.position_size
N := N + 1
if strategy.position_size == 0
N := 0

var pr1 = 0.0
if longCondition and N == 0
pr1 := close
v1 = m1/pr1

var pr2 = 0.0
if longCondition and N == 1 and close < strategy.position_avg_price
pr2 := close
v2 = m2/pr2

var pr3 = 0.0
if longCondition and N == 2 and close < strategy.position_avg_price
pr3 := close
v3 = m3/pr3


strategy.entry('buy', strategy.long, qty = v1, limit = pr1, when = longCondition and N == 0)
strategy.order('buy', strategy.long, qty = v2, limit = pr2, when = longCondition and N == 1 and close < strategy.position_avg_price)
strategy.order('buy', strategy.long, qty = v3, limit = pr3, when = longCondition and N == 2 and close < strategy.position_avg_price)
strategy.close_all(when = shortCondition and close > strategy.position_avg_price)

Thông báo miễn trừ trách nhiệm

Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.