简体   繁体   English

如何添加预先确定的止损和止盈?

[英]How do I add a pre determined stop loss and take profit?

This is my first post.这是我的第一篇文章。 I am a prop trader and really trying hard to learn how to code as it would take my trading to another level.我是一名自营交易员,我真的很努力地学习如何编码,因为这会让我的交易更上一层楼。 It is quite overwhelming at the beginning, but working on things that have use to me is motivating.一开始是相当压倒性的,但是做对我有用的事情是有动力的。

I have a script for trading view that I would like to edit.我有一个我想编辑的交易视图脚本。 I have tried myself but I am obviously doing something wrong.我已经尝试过自己,但我显然做错了什么。 Any help would be very much appreciated.任何帮助将不胜感激。

I just want to add my own pre determined stop loss and take profit for the strategy, The code is below:我只想为策略添加我自己预先确定的止损和获利,代码如下:

strategy(title="Z-Score Strategy", shorttitle="Z-Score Strategy")
Period = input(20, minval=1)
Trigger = input(0)
reverse = input(false, title="Trade reverse")
hline(Trigger, color=purple, linestyle=line)
xStdDev = stdev(close, Period)
xMA = sma(close, Period)
nRes = (close - xMA) / xStdDev
pos = iff(nRes > Trigger, 1,
       iff(nRes < Trigger, -1, nz(pos[1], 0))) 
possig = iff(reverse and pos == 1, -1,
          iff(reverse and pos == -1, 1, pos))      
if (possig == 1) 
    strategy.entry("Long", strategy.long)
if (possig == -1)
    strategy.entry("Short", strategy.short)         
barcolor(possig == -1 ? red: possig == 1 ? green : blue )
plot(nRes, color=blue, title="Z-Score")

You should close the position via strategy.exit : https://www.tradingview.com/pine-script-reference/v4/#fun_strategy {dot}exit您应该通过strategy.exit平仓: https : //www.tradingview.com/pine-script-reference/v4/#fun_strategy {dot}exit

//@version=4
strategy("strategy")
strategy.entry("entryId", strategy.long)
strategy.exit("exitId", "entryId", profit = 5, stop=7)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM