pine-script - 以点数为单位设置策略的 TP 和 SL
问题描述
新手问题:我想尝试的策略有多头和空头条件,我想将我的 TP 和 SL 都设置为 40 点,但我还没有弄清楚如何做到这一点,因为 pine 策略没有似乎对点子太友好了。我希望我的起始余额为 1000 美元,每笔交易使用我的净值余额的 90%。这可能吗?先感谢您!
解决方案
给你:
// 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)
推荐阅读
- java - 如何在java中模拟TCP(流量控制和拥塞控制)?
- sql - 由于字段长度限制,将总和值分成多行
- python - 有没有办法解决连接两个以上的窗口而不会使pyqt5中的程序崩溃的问题?
- c - POSIX 中 sem_getvalue() 的语义
- javascript - 我无法在最终警报中获得甜蜜警报变量的值
- python - 下载文件时如何向下滚动页面以避免错误
- ruby-on-rails - BCrypt InvalidHash 清除密码重置
- python - 有没有办法打印在 __init__ 方法中创建的对象的所有参数?
- java - 转换不带双括号的引用变量
- javascript - 摩纳哥编辑器 AddComment 事件触发两次