首页 > 解决方案 > 以点数为单位设置策略的 TP 和 SL

问题描述

新手问题:我想尝试的策略有多头和空头条件,我想将我的 TP 和 SL 都设置为 40 点,但我还没有弄清楚如何做到这一点,因为 pine 策略没有似乎对点子太友好了。我希望我的起始余额为 1000 美元,每笔交易使用我的净值余额的 90%。这可能吗?先感谢您!

标签: pine-script

解决方案


给你:

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

//@version=4
strategy("My Strategy", overlay=true, margin_long=100, margin_short=100, default_qty_type=strategy.percent_of_equity, default_qty_value=90)

longCondition = crossover(sma(close, 14), sma(close, 28)) and strategy.position_size == 0
if (longCondition)
    strategy.entry("My Long Entry Id", strategy.long)

shortCondition = crossunder(sma(close, 14), sma(close, 28)) and strategy.position_size == 0
if (shortCondition)
    strategy.entry("My Short Entry Id", strategy.short)
    
strategy.exit("x", loss = 40, profit = 40)

推荐阅读