Dow 이론을 기반으로 한 RSI/MFI 모멘텀 지표 전략


생성 날짜: 2023-12-12 17:54:58 마지막으로 수정됨: 2023-12-12 17:54:58
복사: 0 클릭수: 774
avatar of ChaoZhang ChaoZhang
1
집중하다
1621
수행원

Dow 이론을 기반으로 한 RSI/MFI 모멘텀 지표 전략

개요

이 전략은 상대적으로 강하고 약한 지표 ((RSI) 또는 자본 흐름 지표 ((MFI) 를 사용하여 시장의 불 또는 곰을 판단하고, 다우 이론의 황소 곰 계수를 결합하여 조정된 확률 분포를 계산합니다. 다른 시장 유형에 따라 다른 입출금 논리를 사용합니다.

전략 원칙

  1. RSI 또는 MFI를 계산하여 시장의 현재 상태를 판단합니다.
  2. 다우시 이론의 황소와 곰의 계수를 계산하여 현재 가격과 거래량의 상관성을 반영한다
  3. RSI/MFI 확률 분포를 조정하여 정확한 다공간 분포를 결정합니다.
  4. 현재 세션Id 및 확률에 따라 입학 여부를 판단합니다.
  5. 이윤이 철회되거나 시장이 정리될 때 손실을 막습니다.

우위 분석

  1. 다오스 이론과 결합하여 시장 유형을 더 정확하게 판단할 수 있습니다.
  2. 수립 요소를 고려하여 맹목적으로 입학하지 마십시오.
  3. 수익률이 높고 철수율이 낮다.

위험 분석

  1. 이 문장에는 “이미, 이미, 이미, 이미, 이미, 이미, 이미, 이미, 이미, 이미”가 있습니다.
  2. 충분한 역사적 자료가 필요합니다.
  3. 정지 로직은 단순하며, 특수한 상황에 맞게 최적화할 수 없습니다.

최적화 방향

  1. 더 많은 지표와 함께 판단할 수 있습니다.
  2. 변동률, 역사 데이터 등에 기반한 보다 엄격한 손해 방지 논리를 추가합니다.
  3. 더 나은 매개 변수를 확인하는 기계 학습을 시도할 수 있습니다.

요약하다

이 전략은 전반적으로 재검사 결과가 좋으며, 실제 전쟁에 대한 가치가 있다. 그러나, 더 많은 테스트와 조정이 필요하며, 특히, 상쇄 논리이다. 보조 판단 지표로 사용하는 효과는 더 좋으며, 맹목적으로 따라서는 안된다.

전략 소스 코드
/*backtest
start: 2022-12-05 00:00:00
end: 2023-03-11 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=4

//MIT License

//Copyright (c) 2019 user-Noldo

//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:

//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.

//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.


strategy("Dow Factor RSI/MFI and Dependent Variable Odd Generator Strategy",shorttitle = "Dow_Factor RSI/MFI & DVOG Strategy", overlay = false, default_qty_type=strategy.percent_of_equity,commission_type=strategy.commission.percent, commission_value=0.125, default_qty_value=100 )
src = close 
lights          = input(title="Barcolor I / 0 ? ", options=["ON", "OFF"], defval="OFF")
method          = input(title="METHOD", options=["MFI", "RSI"], defval="RSI")

length = input(5, minval=2,maxval = 14, title = "Strategy Period")

// Essential Functions 

// Function Sum 

f_sum(_src , _length) => 

    _output  = 0.00 
    
    _length_adjusted = _length < 1 ? 1 : _length
    
    for i = 0 to _length_adjusted-1
        _output := _output + _src[i]


f_sma(_src, _length)=>
    _length_adjusted = _length < 1 ? 1 : _length
    float _sum = 0
    for _i = 0 to (_length_adjusted - 1)
        _sum := _sum + _src[_i]
    _return = _sum / _length_adjusted
   

// Unlocked Exponential Moving Average Function

f_ema(_src, _length)=>
    _length_adjusted = _length < 1 ? 1 : _length
    _multiplier = 2 / (_length_adjusted + 1)
    _return  = 0.00
    _return := na(_return[1]) ? _src : ((_src - _return[1]) * _multiplier) + _return[1]


// Function Standard Deviation

f_stdev(_src,_length) =>

    float _output = na 
    _length_adjusted = _length < 2 ? 2 : _length
    _avg  = f_ema(_src , _length_adjusted)
    evar  = (_src - _avg) * (_src - _avg)
    evar2 = ((f_sum(evar,_length_adjusted))/_length_adjusted)
    
    _output := sqrt(evar2)


// Linear Regression Channels : 

f_pearson_corr(_src1, _src2, _length) =>

    _length_adjusted = _length < 2 ? 2 : _length
    _ema1 = f_ema(_src1, _length_adjusted)
    _ema2 = f_ema(_src2, _length_adjusted)
    isum = 0.0
    for i = 0 to _length_adjusted - 1
        isum := isum + (_src1[i] - _ema1) * (_src2[i] - _ema2)
    isumsq1 = 0.0
    for i = 0 to _length_adjusted - 1
        isumsq1 := isumsq1 + pow(_src1[i] - _ema1, 2)
    isumsq2 = 0.0
    for i = 0 to _length_adjusted - 1
        isumsq2 := isumsq2 + pow(_src2[i] - _ema2, 2)
    pcc = isum/(sqrt(isumsq1*isumsq2))
    pcc


// Dow Theory Cycles 


dow_coeff = f_pearson_corr(src,volume,length)

dow_bull_factor = (1 + dow_coeff)
dow_bear_factor = (1 - dow_coeff)


// MONEY FLOW INDEX =====> FOR BULL OR BEAR MARKET (CLOSE)


upper_s = f_sum(volume * (change(src) <= 0 ? 0 : src), length)
lower_s = f_sum(volume * (change(src) >= 0 ? 0 : src), length)

_market_index = rsi(upper_s, lower_s)


// RSI (Close)

// Function RMA 

f_rma(_src, _length) =>
    _length_adjusted = _length < 1 ? 1 : _length
    alpha = _length_adjusted
    sum = 0.0
    sum := (_src + (alpha - 1) * nz(sum[1])) / alpha


// Function Relative Strength Index (RSI)

f_rsi(_src, _length) => 

    _output = 0.00 
    _length_adjusted = _length < 0 ? 0 : _length

    u = _length_adjusted < 1 ? max(_src - _src[_length_adjusted], 0) : max(_src - _src[1] , 0) // upward change
    d = _length_adjusted < 1 ? max(_src[_length_adjusted] - _src, 0) : max(_src[1] - _src , 0) // downward change
    rs = f_rma(u, _length) / f_rma(d, _length)
    res = 100 - 100 / (1 + rs)
    res


_rsi = f_rsi(src, length)


// Switchable Method Codes 

_method = 0.00 


if (method=="MFI")

    _method:= _market_index 
    
if (method=="RSI")

    _method:= _rsi   
    


// Conditions  

_bull_gross  = (_method )
_bear_gross  = (100 - _method )

_price_stagnant = ((_bull_gross * _bear_gross ) / 100)
_price_bull     =  (_bull_gross - _price_stagnant) 
_price_bear     =  (_bear_gross - _price_stagnant) 


_coeff_price = (_price_stagnant + _price_bull + _price_bear) / 100 

_bull     = _price_bull / _coeff_price 
_bear     = _price_bear / _coeff_price 
_stagnant = _price_stagnant / _coeff_price



// Market Types with Dow Factor

_temp_bull_gross     =  _bull     * dow_bull_factor       

_temp_bear_gross     =  _bear     * dow_bear_factor 


// Addition : Odds with Stagnant Market 


_coeff_normal = (_temp_bull_gross + _temp_bear_gross) / 100


// ********* OUR RSI / MFI VALUE ***********

_value        = _temp_bull_gross / _coeff_normal


// Temporary Pure Odds 

_temp_stagnant = ((_temp_bull_gross * _temp_bear_gross) / 100)
_temp_bull     = _temp_bull_gross - _temp_stagnant 
_temp_bear     = _temp_bear_gross - _temp_stagnant 


// Now we ll do venn scheme (Probability Cluster)
// Pure Bull + Pure Bear + Pure Stagnant = 100 
// Markets will get their share in the Probability Cluster 

 
_coeff = (_temp_stagnant + _temp_bull + _temp_bear) / 100

_odd_bull     = _temp_bull / _coeff
_odd_bear     = _temp_bear / _coeff
_odd_stagnant = _temp_stagnant / _coeff


_positive_condition     = crossover (_value,50)
_negative_condition     = crossunder(_value,50)
_stationary_condition   = ((_odd_stagnant > _odd_bull ) and (_odd_stagnant > _odd_bear))


// Strategy 

closePosition = _stationary_condition


if (_positive_condition)
    strategy.entry("Long", strategy.long, comment="Long")
    
strategy.close(id = "Long", when = closePosition )

if (_negative_condition)
    strategy.entry("Short", strategy.short, comment="Short")
    
strategy.close(id = "Short", when = closePosition )    


// Plot Data

// Plotage 

oversold   = input(25 , type = input.integer , title = "Oversold")   
overbought = input(75 , type = input.integer , title = "Overbought") 

zero    = 0 
hundred = 100
limit   = 50

// Plot Data 

stagline       = hline(limit      , color=color.new(color.white,0)   , linewidth=1, editable=false)
zeroline       = hline(zero       , color=color.new(color.silver,100), linewidth=0, editable=false)
hundredline    = hline(hundred    , color=color.new(color.silver,100), linewidth=0, editable=false)
oversoldline   = hline(oversold   , color=color.new(color.silver,100), linewidth=0, editable=false)
overboughtline = hline(overbought , color=color.new(color.silver,100), linewidth=0, editable=false)

// Filling Borders

fill(zeroline       , oversoldline   , color=color.maroon  , transp=88 , title = "Oversold Area")
fill(oversoldline   , stagline       , color=color.red     , transp=80 , title = "Bear Market")
fill(stagline       , overboughtline , color=color.green   , transp=80 , title = "Bull Market")
fill(overboughtline , hundredline    , color=color.teal    , transp=88 , title = "Overbought Market")


// Plot DOW Factor Methods

plot(_value, color = #F4C430 , linewidth = 2 , title = "DOW F-RSI" , transp = 0)

// Plot border lines

plot(oversold  ,style = plot.style_line,color = color.new(color.maroon,30),linewidth = 1)
plot(overbought,style = plot.style_line,color = color.new(color.teal,30)  ,linewidth = 1)


plot(zero     ,style = plot.style_line , color = color.new(color.silver,30) , linewidth = 1 ,editable = false)
plot(hundred  ,style = plot.style_line , color = color.new(color.silver,30) , linewidth = 1 ,editable = false)


// Switchable Barcolor ( On / Off)

_lights = 0.00 


if (lights=="ON")

    _lights:= 1.00
    
if (lights=="OFF")

    _lights:= -1.00   


bcolor_on  = _lights ==  1.00
bcolor_off = _lights == -1.00


barcolor((_positive_condition and bcolor_on)    ? color.green : (_negative_condition and bcolor_on) ? color.red : 
          (_stationary_condition and bcolor_on) ? color.yellow : na)


// Alerts 

alertcondition(_positive_condition , title='Strong Buy !', message='Strong Buy Signal ')
alertcondition(crossover(_value,overbought) , title='Gradual Buy', message='Gradual Buy Signal')
alertcondition(crossover(_value,oversold)   , title='Gradual Buy', message='Gradual Buy Signal')

alertcondition(crossunder(_value,overbought) , title='Gradual Sell', message='Gradual Sell Signal')
alertcondition(crossunder(_value,oversold)   , title='Gradual Sell', message='Gradual Sell Signal')

alertcondition(_negative_condition , title='Strong Sell !', message='Strong Sell Signal ')