
자기 적응 다 시간 프레임 피보나치 파동 거래 전략은 자기 적응 평균선, 스토카스틱 RSI 지표 및 피보나치 회수 지역의 트렌드 추적 전략이다. 이 전략은 여러 지표를 사용하여 다양한 수준의 시세 움직임을 분석하고, 동적으로 포지션을 조정한다.
다중 시간 프레임에 적응하는 피보나치 파운드 거래 전략은 다음과 같은 기술 지표와 메커니즘을 사용한다:
적응형 평균선 ((SMA와 WMA): 다른 주기 ((분, 시간, 일선 등) 의 가격의 적응형 이동 평균을 계산한다. 평균선 빈 상태에 따라 트렌드 방향을 판단한다.
Stochastic RSI: RSI 지표의 Stochastic 값을 계산하여 RSI가 과매매되고 있는지 여부를 판단한다. RSI 곡선의 형태 분석 강도와 트렌드를 결합한다.
피보나치 회귀 지역: 최근 스윙 하이와 스윙 로우에 따라 피보나치 회귀 지역을 그리고, 선택적 매매점을 설정한다. 이러한 지역은 잠재적인 추세 반전과 회귀의 특징이 있다.
포지션 관리: 스토치 RSI와 적응 평행선의 강한 약한 신호에 따라 포지션을 동적으로 조정한다.
전략은 먼저 트렌드 방향을 판단하고, 주식 가격이 피보나치 회수 영역에 들어갔을 때 선택 구매 판매 지점을 설정한다. 적응 평균선과 스토치 RSI가 출입 신호를 냈을 때 선택 구매 판매 지점 근처에서 주문을 실행한다. 위험을 제어하기 위해 회수 영역 밖에서 중지 손실을 설정한다.
다중 시간 프레임에 적응하는 피보나치 파형 거래 전략은 다음과 같은 장점이 있습니다:
다중 시간 프레임 분석: 동시에 여러 주기 레벨을 평가 (분, 시간, 일선), 더 포괄적으로 추세를 판단한다.
동적 포지션 관리: 상황에 따라 포지션을 조정하고 위험을 제어한다.
정밀 위치 회귀 영역: 피보나치 영역은 트렌드에서 단기 반전을 잡을 수 있다.
엄격한 중지: 철수 지역 설정에 따라 중지 손실, 효과적으로 큰 손실을 피한다.
신호 필터링: 선택된 매매점 근처에서만 거래를 수행하여 가짜 침입을 방지한다.
매개 변수 최적화 공간: 여러 가지 입력 매개 변수가 시장에 따라 조정되어 전략 성능을 최적화 할 수 있습니다.
이 전략에는 다음과 같은 위험들이 있습니다.
철수 지역 실패 위험: 가격이 피보나치 지역이나 지역 실패를 만지지 못하여 창고를 구축할 수 없습니다. 지역 범위를 확장하고, 지역 수를 증가시킴으로써 완화 할 수 있습니다.
정지 상해 추적 위험: 정지 상해 정지 설정, 미리 타격될 수 있다. 동적 정지, 예비 정지 구역 등의 수단으로 최적화할 수 있다.
신호 허위 뚫림 위험: 자율 적응 평균선, Stoch RSI 가끔 허위 신호가 발생하여 불필요한 거래가 발생한다. 허위 뚫림 가능성을 줄이기 위해 신호를 적절히 필터링 할 수 있다.
너무 복잡한 위험: 여러 가지 변수와 기술 지표의 조합을 사용하면 전략의 복잡성이 증가합니다. 최적화 및 테스트가 더 어렵습니다.
다중 시간 프레임에 적응하는 피보나치 파운드 거래 전략은 다음과 같은 차원에서 더욱 최적화 될 수 있습니다.
더 많은 주식과 외환 품종을 테스트하여 전략의 안정성을 평가하십시오. 다른 시장에 따라 변수를 조정하십시오.
신호 필터링 메커니즘을 증가시키고, 가짜 신호의 가능성을 낮추고, 통신소음 비율을 향상시킨다.
다른 유형의 이동 평균선에 대한 파라미터의 효과를 테스트하고 비교한다.
고정 스톱을 추적 스톱 또는 예비 스톱 영역으로 변경하여 전략의 효과를 증진시키는 것을 시도하십시오.
브레이크아웃 신호나 트렌드 추적 기계를 시도하고, 긴 선을 이용해 수익을 창출하는 방법을 설계한다.
자조적 다중 시간 프레임워크 피보나치 파주 트레이딩 전략은 여러 가지 분석 도구를 통합하여 트렌드 상황을 식별하고 회귀 기간에 위치 위치를 배치한다. 엄격한 중단 손실 및 위험 제어 메커니즘은 큰 추세에서 이익을 최적화하는 데 도움이됩니다. 이 전략은 조정 가능한 공간과 최적화 방향이 더 많이 있으며, 적절한 조정 및 업데이트 후 안정적이고 신뢰할 수있는 양적 거래 전략이 될 것입니다.
/*backtest
start: 2023-12-17 00:00:00
end: 2023-12-24 00:00:00
period: 1m
basePeriod: 1m
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/
// © imal_max
//@version=5
strategy(title="Auto Fib Golden Pocket Band - Autofib Moving Average", shorttitle="Auto Fib Golden Pocket Band", overlay=true, pyramiding=15, process_orders_on_close=true, calc_on_every_tick=true, initial_capital=10000, currency = currency.USD, default_qty_value=100, default_qty_type=strategy.percent_of_equity, commission_type=strategy.commission.percent, commission_value=0.05, slippage=2)
//indicator("Auto Fib Golden Pocket Band - Autofib Moving Average", overlay=true, shorttitle="Auto Fib Golden Pocket Band", timeframe""")
// Fibs
// auto fib ranges
// fib band Strong Trend
enable_StrongBand_Bull = input.bool(title='enable Upper Bullish Band . . . Fib Level', defval=true, group='══════ Strong Trend Levels ══════', inline="0")
select_StrongBand_Fib_Bull = input.float(0.236, title=" ", options=[-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Strong Trend Levels ══════', inline="0")
enable_StrongBand_Bear = input.bool(title='enable Lower Bearish Band . . . Fib Level', defval=false, group='══════ Strong Trend Levels ══════', inline="1")
select_StrongBand_Fib_Bear = input.float(0.382, '', options=[-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Strong Trend Levels ══════', inline="1")
StrongBand_Lookback = input.int(title='Pivot Look Back', minval=1, defval=400, group='══════ Strong Trend Levels ══════', inline="2")
StrongBand_EmaLen = input.int(title='Fib EMA Length', minval=1, defval=120, group='══════ Strong Trend Levels ══════', inline="2")
// fib middle Band regular Trend
enable_MiddleBand_Bull = input.bool(title='enable Middle Bullish Band . . . Fib Level', defval=true, group='══════ Regular Trend Levels ══════', inline="0")
select_MiddleBand_Fib_Bull = input.float(0.618, '', options=[-0.272, 0, 0.236, 0.382, 0.5, 0.6, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Regular Trend Levels ══════', inline="0")
enable_MiddleBand_Bear = input.bool(title='enable Middle Bearish Band . . . Fib Level', defval=true, group='══════ Regular Trend Levels ══════', inline="1")
select_MiddleBand_Fib_Bear = input.float(0.382, '', options=[-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Regular Trend Levels ══════', inline="1")
MiddleBand_Lookback = input.int(title='Pivot Look Back', minval=1, defval=900, group='══════ Regular Trend Levels ══════', inline="2")
MiddleBand_EmaLen = input.int(title='Fib EMA Length', minval=1, defval=400, group='══════ Regular Trend Levels ══════', inline="2")
// fib Sideways Band
enable_SidewaysBand_Bull = input.bool(title='enable Lower Bullish Band . . . Fib Level', defval=true, group='══════ Sideways Trend Levels ══════', inline="0")
select_SidewaysBand_Fib_Bull = input.float(0.6, '', options=[-0.272, 0, 0.236, 0.382, 0.5, 0.6, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Sideways Trend Levels ══════', inline="0")
enable_SidewaysBand_Bear = input.bool(title='enable Upper Bearish Band . . . Fib Level', defval=true, group='══════ Sideways Trend Levels ══════', inline="1")
select_SidewaysBand_Fib_Bear = input.float(0.5, '', options=[-0.272, 0, 0.236, 0.382, 0.5, 0.618, 0.702, 0.71, 0.786, 0.83, 0.886, 1, 1.272], group='══════ Sideways Trend Levels ══════', inline="1")
SidewaysBand_Lookback = input.int(title='Pivot Look Back', minval=1, defval=4000, group='══════ Sideways Trend Levels ══════', inline="2")
SidewaysBand_EmaLen = input.int(title='Fib EMA Length', minval=1, defval=150, group='══════ Sideways Trend Levels ══════', inline="2")
// Strong Band
isBelow_StrongBand_Bull = true
isBelow_StrongBand_Bear = true
StrongBand_Price_of_Low = float(na)
StrongBand_Price_of_High = float(na)
StrongBand_Bear_Fib_Price = float(na)
StrongBand_Bull_Fib_Price = float(na)
/// Middle Band
isBelow_MiddleBand_Bull = true
isBelow_MiddleBand_Bear = true
MiddleBand_Price_of_Low = float(na)
MiddleBand_Price_of_High = float(na)
MiddleBand_Bear_Fib_Price = float(na)
MiddleBand_Bull_Fib_Price = float(na)
// Sideways Band
isBelow_SidewaysBand_Bull = true
isBelow_SidewaysBand_Bear = true
SidewaysBand_Price_of_Low = float(na)
SidewaysBand_Price_of_High = float(na)
SidewaysBand_Bear_Fib_Price = float(na)
SidewaysBand_Bull_Fib_Price = float(na)
// get Fib Levels
if enable_StrongBand_Bull
StrongBand_Price_of_High := ta.highest(high, StrongBand_Lookback)
StrongBand_Price_of_Low := ta.lowest(low, StrongBand_Lookback)
StrongBand_Bull_Fib_Price := (StrongBand_Price_of_High - StrongBand_Price_of_Low) * (1 - select_StrongBand_Fib_Bull) + StrongBand_Price_of_Low //+ fibbullHighDivi
isBelow_StrongBand_Bull := StrongBand_Bull_Fib_Price > ta.lowest(low, 2) or not enable_StrongBand_Bull
if enable_StrongBand_Bear
StrongBand_Price_of_High := ta.highest(high, StrongBand_Lookback)
StrongBand_Price_of_Low := ta.lowest(low, StrongBand_Lookback)
StrongBand_Bear_Fib_Price := (StrongBand_Price_of_High - StrongBand_Price_of_Low) * (1 - select_StrongBand_Fib_Bear) + StrongBand_Price_of_Low// + fibbullLowhDivi
isBelow_StrongBand_Bear := StrongBand_Bear_Fib_Price < ta.highest(low, 2) or not enable_StrongBand_Bear
if enable_MiddleBand_Bull
MiddleBand_Price_of_High := ta.highest(high, MiddleBand_Lookback)
MiddleBand_Price_of_Low := ta.lowest(low, MiddleBand_Lookback)
MiddleBand_Bull_Fib_Price := (MiddleBand_Price_of_High - MiddleBand_Price_of_Low) * (1 - select_MiddleBand_Fib_Bull) + MiddleBand_Price_of_Low //+ fibbullHighDivi
isBelow_MiddleBand_Bull := MiddleBand_Bull_Fib_Price > ta.lowest(low, 2) or not enable_MiddleBand_Bull
if enable_MiddleBand_Bear
MiddleBand_Price_of_High := ta.highest(high, MiddleBand_Lookback)
MiddleBand_Price_of_Low := ta.lowest(low, MiddleBand_Lookback)
MiddleBand_Bear_Fib_Price := (MiddleBand_Price_of_High - MiddleBand_Price_of_Low) * (1 - select_MiddleBand_Fib_Bear) + MiddleBand_Price_of_Low// + fibbullLowhDivi
isBelow_MiddleBand_Bear := MiddleBand_Bear_Fib_Price < ta.highest(low, 2) or not enable_MiddleBand_Bear
if enable_SidewaysBand_Bull
SidewaysBand_Price_of_High := ta.highest(high, SidewaysBand_Lookback)
SidewaysBand_Price_of_Low := ta.lowest(low, SidewaysBand_Lookback)
SidewaysBand_Bull_Fib_Price := (SidewaysBand_Price_of_High - SidewaysBand_Price_of_Low) * (1 - select_SidewaysBand_Fib_Bull) + SidewaysBand_Price_of_Low //+ fibbullHighDivi
isBelow_SidewaysBand_Bull := SidewaysBand_Bull_Fib_Price > ta.lowest(low, 2) or not enable_SidewaysBand_Bull
if enable_SidewaysBand_Bear
SidewaysBand_Price_of_High := ta.highest(high, SidewaysBand_Lookback)
SidewaysBand_Price_of_Low := ta.lowest(low, SidewaysBand_Lookback)
SidewaysBand_Bear_Fib_Price := (SidewaysBand_Price_of_High - SidewaysBand_Price_of_Low) * (1 - select_SidewaysBand_Fib_Bear) + SidewaysBand_Price_of_Low// + fibbullLowhDivi
isBelow_SidewaysBand_Bear := SidewaysBand_Bear_Fib_Price < ta.highest(low, 2) or not enable_SidewaysBand_Bear
// Fib EMAs
// fib ema Strong Trend
StrongBand_current_Trend_EMA = float(na)
StrongBand_Bull_EMA = ta.ema(StrongBand_Bull_Fib_Price, StrongBand_EmaLen)
StrongBand_Bear_EMA = ta.ema(StrongBand_Bear_Fib_Price, StrongBand_EmaLen)
StrongBand_Ema_in_Uptrend = ta.change(StrongBand_Bull_EMA) > 0 or ta.change(StrongBand_Bear_EMA) > 0
StrongBand_Ema_Sideways = ta.change(StrongBand_Bull_EMA) == 0 or ta.change(StrongBand_Bear_EMA) == 0
StrongBand_Ema_in_Downtrend = ta.change(StrongBand_Bull_EMA) < 0 or ta.change(StrongBand_Bear_EMA) < 0
if StrongBand_Ema_in_Uptrend or StrongBand_Ema_Sideways
StrongBand_current_Trend_EMA := StrongBand_Bull_EMA
if StrongBand_Ema_in_Downtrend
StrongBand_current_Trend_EMA := StrongBand_Bear_EMA
// fib ema Normal Trend
MiddleBand_current_Trend_EMA = float(na)
MiddleBand_Bull_EMA = ta.ema(MiddleBand_Bull_Fib_Price, MiddleBand_EmaLen)
MiddleBand_Bear_EMA = ta.ema(MiddleBand_Bear_Fib_Price, MiddleBand_EmaLen)
MiddleBand_Ema_in_Uptrend = ta.change(MiddleBand_Bull_EMA) > 0 or ta.change(MiddleBand_Bear_EMA) > 0
MiddleBand_Ema_Sideways = ta.change(MiddleBand_Bull_EMA) == 0 or ta.change(MiddleBand_Bear_EMA) == 0
MiddleBand_Ema_in_Downtrend = ta.change(MiddleBand_Bull_EMA) < 0 or ta.change(MiddleBand_Bear_EMA) < 0
if MiddleBand_Ema_in_Uptrend or MiddleBand_Ema_Sideways
MiddleBand_current_Trend_EMA := MiddleBand_Bull_EMA
if MiddleBand_Ema_in_Downtrend
MiddleBand_current_Trend_EMA := MiddleBand_Bear_EMA
// fib ema Sideways Trend
SidewaysBand_current_Trend_EMA = float(na)
SidewaysBand_Bull_EMA = ta.ema(SidewaysBand_Bull_Fib_Price, SidewaysBand_EmaLen)
SidewaysBand_Bear_EMA = ta.ema(SidewaysBand_Bear_Fib_Price, SidewaysBand_EmaLen)
SidewaysBand_Ema_in_Uptrend = ta.change(SidewaysBand_Bull_EMA) > 0 or ta.change(SidewaysBand_Bear_EMA) > 0
SidewaysBand_Ema_Sideways = ta.change(SidewaysBand_Bull_EMA) == 0 or ta.change(SidewaysBand_Bear_EMA) == 0
SidewaysBand_Ema_in_Downtrend = ta.change(SidewaysBand_Bull_EMA) < 0 or ta.change(SidewaysBand_Bear_EMA) < 0
if SidewaysBand_Ema_in_Uptrend or SidewaysBand_Ema_Sideways
SidewaysBand_current_Trend_EMA := SidewaysBand_Bull_EMA
if SidewaysBand_Ema_in_Downtrend
SidewaysBand_current_Trend_EMA := SidewaysBand_Bear_EMA
// trend states and colors
all_Fib_Emas_Trending = StrongBand_Ema_in_Uptrend and MiddleBand_Ema_in_Uptrend and SidewaysBand_Ema_in_Uptrend
all_Fib_Emas_Downtrend = MiddleBand_Ema_in_Downtrend and StrongBand_Ema_in_Downtrend and SidewaysBand_Ema_in_Downtrend
all_Fib_Emas_Sideways = MiddleBand_Ema_Sideways and StrongBand_Ema_Sideways and SidewaysBand_Ema_Sideways
all_Fib_Emas_Trend_or_Sideways = (MiddleBand_Ema_Sideways or StrongBand_Ema_Sideways or SidewaysBand_Ema_Sideways) or (StrongBand_Ema_in_Uptrend or MiddleBand_Ema_in_Uptrend or SidewaysBand_Ema_in_Uptrend) and not (MiddleBand_Ema_in_Downtrend or StrongBand_Ema_in_Downtrend or SidewaysBand_Ema_in_Downtrend)
allFibsUpAndDownTrend = (MiddleBand_Ema_in_Downtrend or StrongBand_Ema_in_Downtrend or SidewaysBand_Ema_in_Downtrend) and (MiddleBand_Ema_Sideways or SidewaysBand_Ema_Sideways or StrongBand_Ema_Sideways or StrongBand_Ema_in_Uptrend or MiddleBand_Ema_in_Uptrend or SidewaysBand_Ema_in_Uptrend)
Middle_and_Sideways_Emas_Trending = MiddleBand_Ema_in_Uptrend and SidewaysBand_Ema_in_Uptrend
Middle_and_Sideways_Fib_Emas_Downtrend = MiddleBand_Ema_in_Downtrend and SidewaysBand_Ema_in_Downtrend
Middle_and_Sideways_Fib_Emas_Sideways = MiddleBand_Ema_Sideways and SidewaysBand_Ema_Sideways
Middle_and_Sideways_Fib_Emas_Trend_or_Sideways = (MiddleBand_Ema_Sideways or SidewaysBand_Ema_Sideways) or (MiddleBand_Ema_in_Uptrend or SidewaysBand_Ema_in_Uptrend) and not (MiddleBand_Ema_in_Downtrend or SidewaysBand_Ema_in_Downtrend)
Middle_and_Sideways_UpAndDownTrend = (MiddleBand_Ema_in_Downtrend or SidewaysBand_Ema_in_Downtrend) and (MiddleBand_Ema_Sideways or SidewaysBand_Ema_Sideways or MiddleBand_Ema_in_Uptrend or SidewaysBand_Ema_in_Uptrend)
UpperBand_Ema_Color = all_Fib_Emas_Trend_or_Sideways ? color.lime : all_Fib_Emas_Downtrend ? color.red : allFibsUpAndDownTrend ? color.white : na
MiddleBand_Ema_Color = Middle_and_Sideways_Fib_Emas_Trend_or_Sideways ? color.lime : Middle_and_Sideways_Fib_Emas_Downtrend ? color.red : Middle_and_Sideways_UpAndDownTrend ? color.white : na
SidewaysBand_Ema_Color = SidewaysBand_Ema_in_Uptrend ? color.lime : SidewaysBand_Ema_in_Downtrend ? color.red : (SidewaysBand_Ema_in_Downtrend and (SidewaysBand_Ema_Sideways or SidewaysBand_Ema_in_Uptrend)) ? color.white : na
plotStrong_Ema = plot(StrongBand_current_Trend_EMA, color=UpperBand_Ema_Color, title="Strong Trend")
plotMiddle_Ema = plot(MiddleBand_current_Trend_EMA, color=MiddleBand_Ema_Color, title="Normal Trend")
plotSideways_Ema = plot(SidewaysBand_current_Trend_EMA, color=SidewaysBand_Ema_Color, title="Sidewaysd")
Strong_Middle_fillcolor = color.new(color.green, 90)
if all_Fib_Emas_Trend_or_Sideways
Strong_Middle_fillcolor := color.new(color.green, 90)
if all_Fib_Emas_Downtrend
Strong_Middle_fillcolor := color.new(color.red, 90)
if allFibsUpAndDownTrend
Strong_Middle_fillcolor := color.new(color.white, 90)
Middle_Sideways_fillcolor = color.new(color.green, 90)
if Middle_and_Sideways_Fib_Emas_Trend_or_Sideways
Middle_Sideways_fillcolor := color.new(color.green, 90)
if Middle_and_Sideways_Fib_Emas_Downtrend
Middle_Sideways_fillcolor := color.new(color.red, 90)
if Middle_and_Sideways_UpAndDownTrend
Middle_Sideways_fillcolor := color.new(color.white, 90)
fill(plotStrong_Ema, plotMiddle_Ema, color=Strong_Middle_fillcolor, title="fib band background")
fill(plotMiddle_Ema, plotSideways_Ema, color=Middle_Sideways_fillcolor, title="fib band background")
// buy condition
StrongBand_Price_was_below_Bull_level = ta.lowest(low, 1) < StrongBand_current_Trend_EMA
StrongBand_Price_is_above_Bull_level = close > StrongBand_current_Trend_EMA
StronBand_Price_Average_above_Bull_Level = ta.ema(low, 10) > StrongBand_current_Trend_EMA
StrongBand_Low_isnt_toLow = (ta.lowest(StrongBand_current_Trend_EMA, 15) - ta.lowest(low, 15)) < close * 0.005
StronBand_Trend_isnt_fresh = ta.barssince(StrongBand_Ema_in_Downtrend) > 50 or na(ta.barssince(StrongBand_Ema_in_Downtrend))
MiddleBand_Price_was_below_Bull_level = ta.lowest(low, 1) < MiddleBand_current_Trend_EMA
MiddleBand_Price_is_above_Bull_level = close > MiddleBand_current_Trend_EMA
MiddleBand_Price_Average_above_Bull_Level = ta.ema(close, 20) > MiddleBand_current_Trend_EMA
MiddleBand_Low_isnt_toLow = (ta.lowest(MiddleBand_current_Trend_EMA, 10) - ta.lowest(low, 10)) < close * 0.0065
MiddleBand_Trend_isnt_fresh = ta.barssince(MiddleBand_Ema_in_Downtrend) > 50 or na(ta.barssince(MiddleBand_Ema_in_Downtrend))
SidewaysBand_Price_was_below_Bull_level = ta.lowest(low, 1) < SidewaysBand_current_Trend_EMA
SidewaysBand_Price_is_above_Bull_level = close > SidewaysBand_current_Trend_EMA
SidewaysBand_Price_Average_above_Bull_Level = ta.ema(low, 80) > SidewaysBand_current_Trend_EMA
SidewaysBand_Low_isnt_toLow = (ta.lowest(SidewaysBand_current_Trend_EMA, 150) - ta.lowest(low, 150)) < close * 0.0065
SidewaysBand_Trend_isnt_fresh = ta.barssince(SidewaysBand_Ema_in_Downtrend) > 50 or na(ta.barssince(SidewaysBand_Ema_in_Downtrend))
StrongBand_Buy_Alert = StronBand_Trend_isnt_fresh and StrongBand_Low_isnt_toLow and StronBand_Price_Average_above_Bull_Level and StrongBand_Price_was_below_Bull_level and StrongBand_Price_is_above_Bull_level and all_Fib_Emas_Trend_or_Sideways
MiddleBand_Buy_Alert = MiddleBand_Trend_isnt_fresh and MiddleBand_Low_isnt_toLow and MiddleBand_Price_Average_above_Bull_Level and MiddleBand_Price_was_below_Bull_level and MiddleBand_Price_is_above_Bull_level and Middle_and_Sideways_Fib_Emas_Trend_or_Sideways
SidewaysBand_Buy_Alert = SidewaysBand_Trend_isnt_fresh and SidewaysBand_Low_isnt_toLow and SidewaysBand_Price_Average_above_Bull_Level and SidewaysBand_Price_was_below_Bull_level and SidewaysBand_Price_is_above_Bull_level and (SidewaysBand_Ema_Sideways or SidewaysBand_Ema_in_Uptrend and ( not SidewaysBand_Ema_in_Downtrend))
// Sell condition
StrongBand_Price_was_above_Bear_level = ta.highest(high, 1) > StrongBand_current_Trend_EMA
StrongBand_Price_is_below_Bear_level = close < StrongBand_current_Trend_EMA
StronBand_Price_Average_below_Bear_Level = ta.sma(high, 10) < StrongBand_current_Trend_EMA
StrongBand_High_isnt_to_High = (ta.highest(high, 15) - ta.highest(StrongBand_current_Trend_EMA, 15)) < close * 0.005
StrongBand_Bear_Trend_isnt_fresh = ta.barssince(StrongBand_Ema_in_Uptrend) > 50
MiddleBand_Price_was_above_Bear_level = ta.highest(high, 1) > MiddleBand_current_Trend_EMA
MiddleBand_Price_is_below_Bear_level = close < MiddleBand_current_Trend_EMA
MiddleBand_Price_Average_below_Bear_Level = ta.sma(high, 9) < MiddleBand_current_Trend_EMA
MiddleBand_High_isnt_to_High = (ta.highest(high, 10) - ta.highest(MiddleBand_current_Trend_EMA, 10)) < close * 0.0065
MiddleBand_Bear_Trend_isnt_fresh = ta.barssince(MiddleBand_Ema_in_Uptrend) > 50
SidewaysBand_Price_was_above_Bear_level = ta.highest(high, 1) > SidewaysBand_current_Trend_EMA
SidewaysBand_Price_is_below_Bear_level = close < SidewaysBand_current_Trend_EMA
SidewaysBand_Price_Average_below_Bear_Level = ta.sma(high, 20) < SidewaysBand_current_Trend_EMA
SidewaysBand_High_isnt_to_High = (ta.highest(high, 20) - ta.highest(SidewaysBand_current_Trend_EMA, 15)) < close * 0.0065
SidewaysBand_Bear_Trend_isnt_fresh = ta.barssince(SidewaysBand_Ema_in_Uptrend) > 50
StrongBand_Sell_Alert = StronBand_Price_Average_below_Bear_Level and StrongBand_High_isnt_to_High and StrongBand_Bear_Trend_isnt_fresh and StrongBand_Price_was_above_Bear_level and StrongBand_Price_is_below_Bear_level and all_Fib_Emas_Downtrend and not all_Fib_Emas_Trend_or_Sideways
MiddleBand_Sell_Alert = MiddleBand_Price_Average_below_Bear_Level and MiddleBand_High_isnt_to_High and MiddleBand_Bear_Trend_isnt_fresh and MiddleBand_Price_was_above_Bear_level and MiddleBand_Price_is_below_Bear_level and Middle_and_Sideways_Fib_Emas_Downtrend and not Middle_and_Sideways_Fib_Emas_Trend_or_Sideways
SidewaysBand_Sell_Alert = SidewaysBand_Price_Average_below_Bear_Level and SidewaysBand_High_isnt_to_High and SidewaysBand_Bear_Trend_isnt_fresh and SidewaysBand_Price_was_above_Bear_level and SidewaysBand_Price_is_below_Bear_level and SidewaysBand_Ema_in_Downtrend and not (SidewaysBand_Ema_Sideways or SidewaysBand_Ema_in_Uptrend and ( not SidewaysBand_Ema_in_Downtrend))
// Backtester
////////////////// Stop Loss
// Stop loss
enableSL = input.bool(true, title='enable Stop Loss', group='══════════ Stop Loss Settings ══════════')
whichSL = input.string(defval='low/high as SL', title='SL based on static % or based on the low/high', options=['low/high as SL', 'static % as SL'], group='══════════ Stop Loss Settings ══════════')
whichOffset = input.string(defval='% as offset', title='choose offset from the low/high', options=['$ as offset', '% as offset'], group='Stop Loss at the low/high')
lowPBuffer = input.float(1.4, title='SL Offset from the Low/high in %', group='Stop Loss at the low/high') / 100
lowDBuffer = input.float(100, title='SL Offset from the Low/high in $', group='Stop Loss at the low/high')
SlLowLookback = input.int(title='SL lookback for Low/high', defval=5, minval=1, maxval=50, group='Stop Loss at the low/high')
longSlLow = float(na)
shortSlLow = float(na)
if whichOffset == "% as offset" and whichSL == "low/high as SL" and enableSL
longSlLow := ta.lowest(low, SlLowLookback) * (1 - lowPBuffer)
shortSlLow := ta.highest(high, SlLowLookback) * (1 + lowPBuffer)
if whichOffset == "$ as offset" and whichSL == "low/high as SL" and enableSL
longSlLow := ta.lowest(low, SlLowLookback) - lowDBuffer
shortSlLow := ta.highest(high, SlLowLookback) + lowDBuffer
//plot(shortSlLow, title="stoploss", color=color.new(#00bcd4, 0))
// long settings - 🔥 uncomment the 6 lines below to disable the alerts and enable the backtester
longStopLoss = input.float(0.5, title='Long Stop Loss in %', group='static % Stop Loss', inline='Input 1') / 100
// short settings - 🔥 uncomment the 6 lines below to disable the alerts and enable the backtester
shortStopLoss = input.float(0.5, title='Short Stop Loss in %', group='static % Stop Loss', inline='Input 1') / 100
/////// Take profit
longTakeProfit1 = input.float(4, title='Long Take Profit in %', group='Take Profit', inline='Input 1') / 100
/////// Take profit
shortTakeProfit1 = input.float(1.6, title='Short Take Profit in %', group='Take Profit', inline='Input 1') / 100
////////////////// SL TP END
/////////////////// alerts
selectalertFreq = input.string(defval='once per bar close', title='Alert Options', options=['once per bar', 'once per bar close', 'all'], group='═══════════ alert settings ═══════════')
BuyAlertMessage = input.string(defval="Bullish Divergence detected, put your SL @", title='Buy Alert Message', group='═══════════ alert settings ═══════════')
enableSlMessage = input.bool(true, title='enable Stop Loss Value at the end of "buy Alert message"', group='═══════════ alert settings ═══════════')
AfterSLMessage = input.string(defval="", title='Buy Alert message after SL Value', group='═══════════ alert settings ═══════════')
////////////////// Backtester
// 🔥 uncomment the all lines below for the backtester and revert for alerts
shortTrading = enable_MiddleBand_Bear or enable_StrongBand_Bear or enable_SidewaysBand_Bear
longTrading = enable_StrongBand_Bull or enable_MiddleBand_Bull or enable_SidewaysBand_Bull
longTP1 = strategy.position_size > 0 ? strategy.position_avg_price * (1 + longTakeProfit1) : strategy.position_size < 0 ? strategy.position_avg_price * (1 - longTakeProfit1) : na
longSL = strategy.position_size > 0 ? strategy.position_avg_price * (1 - longStopLoss) : strategy.position_size < 0 ? strategy.position_avg_price * (1 + longStopLoss) : na
shortTP = strategy.position_size > 0 ? strategy.position_avg_price * (1 + shortTakeProfit1) : strategy.position_size < 0 ? strategy.position_avg_price * (1 - shortTakeProfit1) : na
shortSL = strategy.position_size > 0 ? strategy.position_avg_price * (1 - shortStopLoss) : strategy.position_size < 0 ? strategy.position_avg_price * (1 + shortStopLoss) : na
strategy.risk.allow_entry_in(longTrading == true and shortTrading == true ? strategy.direction.all : longTrading == true ? strategy.direction.long : shortTrading == true ? strategy.direction.short : na)
strategy.entry('Bull', strategy.long, comment='Upper Band Long', when=StrongBand_Buy_Alert)
strategy.entry('Bull', strategy.long, comment='Lower Band Long', when=MiddleBand_Buy_Alert)
strategy.entry('Bull', strategy.long, comment='Lower Band Long', when=SidewaysBand_Buy_Alert)
strategy.entry('Bear', strategy.short, comment='Upper Band Short', when=StrongBand_Sell_Alert)
strategy.entry('Bear', strategy.short, comment='Lower Band Short', when=MiddleBand_Sell_Alert)
strategy.entry('Bear', strategy.short, comment='Lower Band Short', when=SidewaysBand_Sell_Alert)
// check which SL to use
if enableSL and whichSL == 'static % as SL'
strategy.exit(id='longTP-SL', from_entry='Bull', limit=longTP1, stop=longSL)
strategy.exit(id='shortTP-SL', from_entry='Bear', limit=shortTP, stop=shortSL)
// get bars since last entry for the SL at low to work
barsSinceLastEntry()=>
strategy.opentrades > 0 ? (bar_index - strategy.opentrades.entry_bar_index(strategy.opentrades-1)) : na
if enableSL and whichSL == 'low/high as SL' and ta.barssince(StrongBand_Buy_Alert or MiddleBand_Buy_Alert or SidewaysBand_Buy_Alert) < 2 and barsSinceLastEntry() < 2
strategy.exit(id='longTP-SL', from_entry='Bull', limit=longTP1, stop=longSlLow)
if enableSL and whichSL == 'low/high as SL' and ta.barssince(StrongBand_Sell_Alert or MiddleBand_Sell_Alert or SidewaysBand_Sell_Alert) < 2 and barsSinceLastEntry() < 2
strategy.exit(id='shortTP-SL', from_entry='Bear', limit=shortTP, stop=shortSlLow)
if not enableSL
strategy.exit(id='longTP-SL', from_entry='Bull', limit=longTP1)
strategy.exit(id='shortTP-SL', from_entry='Bear', limit=shortTP)