21.05.2024
0
0
0
0

RSI Bands, RSI %B and RSI Bandwidth


https://www.tradingview.com/script/zWq2YfzA-RSI-Bands-RSI-B-and-RSI-Bandwidth/


======== RSI Bands ========

= Geliştirici: LazyBear

= Yazar: Kripex

=======================


study("RSI Bands [LazyBear]", shorttitle="RSIBANDS_LB", overlay=true)

obLevel = input(70, title="RSI Overbought")

osLevel = input(30, title="RSI Oversold")

length = input(14, title="RSI Length")

src=close


ep = 2 * length - 1

auc = ema( max( src - src[1], 0 ), ep )

adc = ema( max( src[1] - src, 0 ), ep )


x1 = (length - 1) * ( adc * obLevel / (100-obLevel) - auc)

ub = iff( x1 >= 0, src + x1, src + x1 * (100-obLevel)/obLevel )

x2 = (length - 1) * ( adc * osLevel / (100-osLevel) - auc)

lb = iff( x2 >= 0, src + x2, src + x2 * (100-osLevel)/osLevel )


plot( ub, title="Resistance", color=red, linewidth=2)

plot( lb, title="Support", color=green, linewidth=2)

plot( avg(ub, lb), title="RSI Midline", color=gray, linewidth=1)



/*

======== RSI Bands ========
= Geliştirici: LazyBear 
= Yazar: Kripex
=============================

study("RSI Bands [LazyBear]", shorttitle="RSIBANDS_LB", overlay=true)
obLevel = input(70, title="RSI Overbought")
osLevel = input(30, title="RSI Oversold")
length = input(14, title="RSI Length")
src=close

ep = 2 * length - 1
auc = ema( max( src - src[1], 0 ), ep )
adc = ema( max( src[1] - src, 0 ), ep )

x1 = (length - 1) * ( adc * obLevel / (100-obLevel) - auc)
ub = iff( x1 >= 0, src + x1, src + x1 * (100-obLevel)/obLevel )
x2 = (length - 1) * ( adc * osLevel / (100-osLevel) - auc)
lb = iff( x2 >= 0, src + x2, src + x2 * (100-osLevel)/osLevel )

plot( ub, title="Resistance", color=red, linewidth=2)
plot( lb, title="Support", color=green, linewidth=2)
plot( avg(ub, lb), title="RSI Midline", color=gray, linewidth=1)

// List of all my indicators: https://www.tradingview.com/v/4IneGo8h/

*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.ComponentModel;
using Matriks.Data.Identifiers;
using Matriks.Data.Symbol;
using Matriks.Engines;
using Matriks.Indicators;
using Matriks.Symbols;
using Matriks.AlgoTrader;
using Matriks.Trader.Core;
using Matriks.Trader.Core.Fields;
using Matriks.Trader.Core.TraderModels;
using Matriks.Lean.Algotrader.AlgoBase;
using Matriks.Lean.Algotrader.Models;
using Matriks.Lean.Algotrader.Trading;

namespace Matriks.Lean.Algotrader
{
	//Ilk parametre indikatörün adı, sınıfın adıyla aynı olmalıdır.
	//Ikinci parametre indikatörün Dataserisinin üzerine mi yeni pencereye mi ekleneceğini belirtir. Yeni pencere için ->IndicatorDrawingArea.NewWindow , Data Serisi için IndicatorDrawingArea.OnDataSeries
	[IndicatorInformationAttribute("RsiBandKripex", IndicatorDrawingArea.OnDataSeries)]
	//Indikatörün çizgilerinin isimleri
	[IndicatorLineInformationAttribute(new []
		{
			"Resistance (0,1,2,3)","RSI Midline","Support"
		}, new []
		{
			"#00CCFF", "#FFFF00", "#e600de"
		}, new []
		{
			false, false, false
		}, new []
		{
			0, 0, 0
		}, new []
		{
			1, 1, 1
		}
	)]

	public class RsiBandKripex : MatriksIndicator
	{

		//Indicator opsiyon panelinde değerleri değiştirebildiğimiz parametreler. Int, Bool, Decimal ve Enum değerleri alabilir.Tüm değişken tiplerini DefaultValue ile tanımlarız. 
		[DefaultValue(14)]
			public int Period
		{
			get; set;
		}

		[DefaultValue(30)]
			public decimal OversoldLevel
		{
			get; set;
		}

		[DefaultValue(70)]
			public decimal OverboughtdLevel
		{
			get; set;
		}

		[DefaultValue(MovMethod.E)]
			public MovMethod MovMethod
		{
			get; set;
		}

		MOV ema1, ema2;

		public sealed override void OnInit()
		{
			var ep = 2 * Period -1;
			ema1 = new MOV(ep, MovMethod);
			ema2 = new MOV(ep, MovMethod);
		}

		public override void OnDataUpdate(int currentBar, decimal inputValue, DateTime barDateTime)
		{

			if (currentBar < Period)
			{
				SetLine(0, currentBar, 0);
				SetLine(1, currentBar, 0);
				SetLine(2, currentBar, 0);
				return ;
			}

			/*
			ep = 2 * length - 1
			auc = ema( max( src - src[1], 0 ), ep )
			adc = ema( max( src[1] - src, 0 ), ep )
			*/

			var close = Instrument.SymbolBarData.Close[currentBar];
			var prevClose = Instrument.SymbolBarData.Close[currentBar -1];

			var ema1Deger = 0.0m;
			var ema2Deger = 0.0m;

			if (close>prevClose)
			{
				ema1Deger = close - prevClose;
			}else
			{
				ema2Deger = prevClose - close;
			}

			ema1.Update(ema1Deger, currentBar, barDateTime);
			ema2.Update(ema2Deger, currentBar, barDateTime);

			/*
			x1 = (length - 1) * ( adc * obLevel / (100-obLevel) - auc)
			ub = iff( x1 >= 0, src + x1, src + x1 * (100-obLevel)/obLevel )
			x2 = (length - 1) * ( adc * osLevel / (100-osLevel) - auc)
			lb = iff( x2 >= 0, src + x2, src + x2 * (100-osLevel)/osLevel )
			*/

			var x1 = (100 - OverboughtdLevel) != 0? (Period -1) * (ema2.CurrentValue * OverboughtdLevel / (100 - OverboughtdLevel) - ema1.CurrentValue) :0;
			var ub = x1 >= 0? close + x1:(OverboughtdLevel != 0? close + x1 * (100 - OverboughtdLevel) / OverboughtdLevel:0);
			var x2 = (100 - OversoldLevel) != 0? (Period -1) * (ema2.CurrentValue * OversoldLevel / (100 - OversoldLevel) - ema1.CurrentValue) :0;
			var lb = x2 >= 0? close + x2:(OversoldLevel != 0? close + x2 * (100 - OversoldLevel) / OversoldLevel:0);

			/*
			plot( ub, title="Resistance", color=red, linewidth=2)
			plot( lb, title="Support", color=green, linewidth=2)
			plot( avg(ub, lb), title="RSI Midline", color=gray, linewidth=1)
			*/

			SetLine(0, currentBar, ub);
			SetLine(1, currentBar, (ub+lb)/2);
			SetLine(2, currentBar, lb);

		}
	}
}

0 Yorum