该策略的主要思路是通过监测价格的下跌幅度来进行买入操作。当价格较前一个周期下跌超过5%时,就会触发买入信号,以当前收盘价买入一定数量的仓位。当价格高于买入价格时,就平仓获利了结。该策略利用了市场的波动性,试图抓住价格的短期反弹机会来获利。
该策略以价格短期下跌超过特定幅度作为买入信号,抓住价格的反弹机会来获利,逻辑简单易懂。策略的优势在于对趋势的捕捉和风险的控制,但是频繁交易、深度回撤、价格波动等风险也需要注意。未来可以从止损优化、信号过滤、仓位管理、多品种协同等方面对策略进行进一步的优化和改进,以期获得更稳健的效果。
/*backtest start: 2023-06-01 00:00:00 end: 2024-06-06 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © Thgoodtrader //@version=5 strategy("TGT Falling Buy", overlay=true, margin_long=100, margin_short=100) var float buy_price = na var float open_price = na var float open_weekend = na var float close_weekend = na var bool trade=false var float balance = 1000 // Definir el precio de compra inicial y la cantidad inicial var float qty = na // Verificar si el día de la semana es sábado (6) o domingo (0) es_sabado = dayofweek == 1 es_domingo = dayofweek == 7 es_viernes = dayofweek == 6 // Calcular el valor del saldo inicial balance_initial = balance change_percent = ((close - close[1]) / close[1]) * 100 is_last_candle_negative = close < open is_change_above_threshold = change_percent < -5 // Cambiar el color de la última vela si cumple las condiciones barcolor(is_last_candle_negative and is_change_above_threshold ? color.yellow : na) bgcolor(is_last_candle_negative and is_change_above_threshold ? color.yellow : na, transp=80) // Guardar el precio de compra cuando se cumpla la condición del 5% if is_change_above_threshold // Calcular la cantidad basada en el precio de compra y el saldo qty := balance / close // Guardar el precio de compra buy_price := close open_price := open strategy.entry("Buy Trading",strategy.long,qty) alert("Comprar BTC", alert.freq_once_per_bar_close) trade :=true //if (((close - strategy.position_avg_price) / strategy.position_avg_price) * 100 ) > 2 if close > strategy.position_avg_price // Calcular el valor de ganancia o pérdida pnl = (close - strategy.position_avg_price) * qty // Actualizar el saldo balance := balance_initial + pnl strategy.close("Buy Trading") alertcondition(is_change_above_threshold, title = "Buy 5% Discount", message = "Buy Position") alertcondition(close > strategy.position_avg_price, title = "Close Trade", message = "Close Buy Position")