策略
手动买卖警报策略Manual-Buy-Sell-Alerts-Strategy
ChaoZhang · PineScript · 风控与仓位 · 2024-02-21 11:02:02
概述
该策略是一个手动买卖警报工具,可以设置买入价格、卖出价格等参数,当价格触发条件时,会发出买入或卖出的警报提醒。 本策略是一个非自动化的手动买卖工具。它可以生成“警报”,以便用户在预先设置的价格点买入和卖出。用户可以设置以下内容:
- 时间周期
- 入场价格和入场类型(止损或限价)
- 目标价格
- 止损价格
通过改变周期值和设置值,可以轻松测试该策略。
策略原理
- 用户首先设置时间周期,在该时间周期内策略生效。
- 然后设置买入类型是止损或限价,以及具体的买入价格。
- 再设置目标价格和止损价格。
- 当价格触发买入条件时,会发出买入警报。比如选择止损,当价格低于设置的买入价时,会发出买入警报。
- 在持仓期间,如果触发目标价格,会发出卖出警报。如果触发止损价,也会发出卖出警报。
通过这种方式,用户可以手动根据警报信息来决定交易时机,无需自动下单,更加灵活。
优势
- 该策略最大的优势在于操作灵活,用户可以根据自己的判断来决定是否买入或卖出,而不是自动交易,控制力更强。
- 设置止损和目标价位后,可以有效控制风险,防止大幅亏损。
- 可以通过调整买入条件和参数测试不同的交易策略,对策略进行优化。
- 作为一个工具来辅助手动交易,可以发挥很好的作用,提高交易效率。
风险
- 该策略依赖于用户的操作判断,如果判断失误,仍然可能造成损失。
- 在快速变动的市场中,警报消息可能会落后,导致交易决策失误。
- 如果没有及时关注和操作,可能错过最佳的交易时机。
- 参数设置不当也会影响策略效果,需要反复测试优化。
为降低风险,建议采用止损来限制亏损; 在关键时刻要密切关注市场,及时操作;进取多轮测试,优化参数。
优化方向
- 可以设置更复杂的止损机制,如移动止损、振荡止损等方式。
- 可以加入更多类型的交易条件,如突破买入等。
- 可以增加仓位管理机制,如加仓或减仓。
- 可以加入更多过滤条件,避免错交易。
- 可以连接telegram或微信,使用消息推送的方式发出警报。
- 可以保存参数设置成模板,快速调整测试。
通过这些优化,可以使该工具对用户更加友好和智能,提高手动交易的效率。
总结
本策略作为一个辅助手动交易的工具,最大优势在于操作灵活,可以完全根据用户判断确定交易时机。相比自动交易策略,具有更大的控制力。同时,也提供了参数设置功能,可以方便用户测试不同的交易策略,对交易理念进行验证,可谓一箭多雕。当然,作为一个工具,也需要用户不断优化与改进,使其可以适应更复杂的交易需要,发挥更大的作用。
参数
| 参数 | 默认值 | 说明 |
|---|---|---|
| v_input_1 | timestamp(2020-01-01) | (?Period)Start |
| v_input_2 | timestamp(2030-01-01) | End |
| v_input_string_1 | 0 | (?Buy&Sell)Buy Type: stop |
| v_input_float_1 | 49000 | Buy Price |
| v_input_float_2 | 51000 | Target Price |
| v_input_float_3 | 47000 | Stop Price |
| v_input_string_2 | Buy message | (?Alert set-up)Buy Alert Message |
| v_input_string_3 | Sell message | Sell Alert Message |
源码(51 行)
/*backtest
start: 2024-01-21 00:00:00
end: 2024-02-20 00:00:00
period: 1h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © MGTG
title_name = 'Manual Buy & Sell Alerts'
//@version=5
strategy(
title=title_name, overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100,
pyramiding=1, commission_type=strategy.commission.percent, commission_value=0.1)
// Period
sTime = input(timestamp("2020-01-01"), "Start", group="Period", inline='1')
eTime = input(timestamp("2030-01-01"), "End", group="Period", inline='2')
inDateRange = true
// Bot Set-up
buy_type = input.string('stop', 'Buy Type', group='Buy&Sell', inline='1', options=['stop', 'limit'])
buy_price = input.float(49000, 'Buy Price', group='Buy&Sell', inline='1')
target_price = input.float(51000, 'Target Price', group='Buy&Sell', inline='2')
stop_price = input.float(47000, 'Stop Price', group='Buy&Sell', inline='2')
avg_price = strategy.position_avg_price
division = 1
// Alert message
AlertLong=input.string("Buy message", "Buy Alert Message", group='Alert set-up', inline='1')
AlertExit=input.string("Sell message", "Sell Alert Message", group='Alert set-up', inline='1')
plot(buy_price, 'Buy Price', color=color.new(#009688, 0), style=plot.style_linebr, offset=1)
plot(target_price, 'Take Profit', color=color.new(color.orange, 0), style=plot.style_linebr, offset=1)
plot(stop_price, 'Safety', color=color.new(color.aqua, 0), style=plot.style_linebr, offset=1)
posSize =
strategy.equity / close
strategy.exit("sell", "buy", limit=target_price, stop=stop_price, alert_message=AlertExit)
longCondition = inDateRange and strategy.position_size == 0
if longCondition and buy_type == 'stop'
strategy.entry("buy", strategy.long, qty=posSize, stop=buy_price, when=close < buy_price, comment="buy_STOP", alert_message=AlertLong)
if longCondition and buy_type == 'limit'
strategy.entry("buy", strategy.long, qty=posSize, limit=buy_price, when=close > buy_price, comment="buy_LIMIT", alert_message=AlertLong)