25.01.2022
0
2
92
100

ASO-Average Sentiment Oscillator

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("ASOKripex", IndicatorDrawingArea.NewWindow)]
	//Indikatörün çizgilerinin isimleri
	[IndicatorLineInformationAttribute(new []
		{
			"Bull(0,1)","Bear"
		})]

	public class ASOKripex : 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(20)]
		public int Length
		{
			get; set;
		}
		
		[DefaultValue(Mode.mod0)]
		public Mode mode
		{
			get; set;
		}		
		
		public enum Mode
		{
			mod0,mod1,mod2
		}
		
		
		[DefaultValue(MovMethod.Simple)]
		public MovMethod MovMethod
		{
			get; set;
		}		

		MOV movBull,movBear;

		public sealed override void OnInit()
		{
			movBull = new MOV(Length, MovMethod);
			movBear = new MOV(Length, MovMethod);
		}		

		public override void OnDataUpdate(int currentBar, decimal inputValue, DateTime barDateTime)
		{
			var O=Instrument.SymbolBarData.Open[currentBar];			
			var H=Instrument.SymbolBarData.High[currentBar];
			var L=Instrument.SymbolBarData.Low[currentBar];			
			var C=Instrument.SymbolBarData.Close[currentBar];		
			
			var intrarange=H-L;
			var grouphigh=HighestHigh(OHLCType.High,Length);
			var grouplow=LowestLow(OHLCType.Low,Length);			
			var groupopen=Instrument.SymbolBarData.Open.ContainsKey(currentBar-Length+1)? Instrument.SymbolBarData.Open[currentBar-Length+1]:0;
			var grouprange=grouphigh-grouplow;
			
			var K1=intrarange==0?1:intrarange;
			var K2=grouprange==0?1:grouprange;
			
			var intrabarbulls=K1!=0?((((C-L)+(H-O))/2)*100)/K1:0;
			
			var groupbulls=K2!=0?((((C-grouplow)+(grouphigh-groupopen))/2)*100)/K2:0;
			
			var intrabarbears=K1!=0?((((H-C)+(O-L))/2)*100)/K1:0;

			var groupbears=K2!=0? ((((grouphigh-C)+(groupopen-grouplow))/2)*100)/K2:0;
			
			var TempBufferBulls=mode==Mode.mod0?(intrabarbulls+groupbulls)/2:(mode==Mode.mod1?intrabarbulls:groupbulls); 
			var TempBufferBears=mode==Mode.mod0?(intrabarbears+groupbears)/2:(mode==Mode.mod1?intrabarbears:groupbears); 
			
			movBull.Update(TempBufferBulls,currentBar,barDateTime);
			movBear.Update(TempBufferBears,currentBar,barDateTime);
			
			if (currentBar < Length)
			{
				SetLine(0, currentBar, 0);
				SetLine(1, currentBar, 0);
				return ;
			}

			SetLine(currentBar, movBull.CurrentValue);
			SetLine(1,currentBar, movBear.CurrentValue);

		}
	}
}

0 Yorum