该策略使用水平线作为支撑位和阻力位,当价格突破水平线时会产生交易信号。主要思路是:首先根据某些条件画出水平线,当价格向上突破水平线时做多,当价格向下突破水平线时平仓。同时水平线的产生也有相应的条件,如前一根K线的最低价大于当前收盘价。
该策略以水平线作为重要的支撑阻力位,通过突破水平线产生交易信号。优点是逻辑简单,容易实现,能较好地捕捉趋势。但是缺点是可能会过度交易,产生错误信号,并且只能做多不能做空。后续可以从结合其他指标、减少交易频率、加入做空机制和动态调整参数等方面进行优化和改进。
/*backtest
start: 2023-04-20 00:00:00
end: 2024-04-25 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/
// © Traderxprox
//@version=5
strategy("Alarm Trader_ALL", overlay=true)
// Yatay çizgi oluşum
yatayc = low[1] > close[0]
if yatayc
if strategy.opentrades > 0
strategy.close("AL", comment = "Fiyat:" + str.tostring(low[1], "#.##") + "\n" + timeframe.period +"\n Yatay Direnç Oluştu")
else
strategy.entry("AL", strategy.long, comment = "Fiyat:" + str.tostring(low[1], "#.##") + "\n" + timeframe.period +"\n Yatay Direnç Oluştu")
//YATAY ÇİZGİ
int cizgilen = input.int(20, "Çizgi uzunluğu?", group = "Yatay Çizgi Ayarları")
var array<line> lines = array.new<line>()
int numberOfLines = input.int(10, "Son Kaç Çizgi?", 0, group = "Yatay Çizgi Ayarları")
kural22 = low[1] > close[0]
// if kural22
// newLine = line.new(bar_index-2, low[1], bar_index+cizgilen, low[1] ,color=color.red, width=1, style=line.style_solid)
// // Push the `newLine` into the `lines` array.
// lines.push(newLine)
// // Delete the oldest line when the size of the array exceeds the specified `numberOfLines`.
// if array.size(lines) > numberOfLines
// line.delete(lines.shift())
// Alarm kırılım için koşul
var float lastLinePrice = na
if not na(close) and array.size(lines) > 0
lastLinePrice := line.get_price(array.get(lines, array.size(lines) - 1), bar_index)
if open < lastLinePrice and close > lastLinePrice
if strategy.opentrades > 0
strategy.close("AL", comment = "Fiyat:" + str.tostring(lastLinePrice, "#.##") + "\n" + timeframe.period +" \n Yatay çizgi yukarı kırılımı")
else
strategy.entry("AL", strategy.long, comment = "Fiyat:" + str.tostring(lastLinePrice, "#.##") + "\n" + timeframe.period +" \n Yatay çizgi yukarı kırılımı")