Iyi gunler, gomulu Heiken Ashi degerleri bir sonraki versiyon algo icerisinde kullanima acilacak. Mevcut hali ile Algo'da HeikenAshi_Bitmex stratejisinde olusturulan heiken ashi degerleri ile Most indikatoru ya da baska bir indikatoru besleyerek istediginiz sonuca ulasabilirsiniz.
Indikator icin kullanacagimiz kapanis degerlerinin indikatore beslenmesi gerektiginden, HA barlarinin olusturan for loop'u icerisinde besleme yaparsak MOST indikatoru de buffer'lanmis ve dogru degere ulasmis olarak loop'tan cikacaktir. Asagidaki ornekte bunu gorebilirsiniz.
most.Update(HA_Close, barDataCurrentValues.LastUpdate.BarDataIndex, barDataCurrentValues.LastUpdate.DTime);
Sadece yukaridaki satir eklenerek de kullanilabilir, fakat bu durumda dogru ortalamayi yakalamasi bir kac periyot surecektir.
using System;
using System.Collections.Generic;
using System.Linq;
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
{
public class HeikenAshi_Bitmex_hazirdan_most : MatriksAlgo
{
[SymbolParameter("XBT_USD_BMEX")]
public string Symbol;
[Parameter(100)]
public int Quantity;
[Parameter(SymbolPeriod.Min)]
public SymbolPeriod SymbolPeriod;
public bool FirstBar = true;
public int Position = 0;
decimal HA_Open = 0;
decimal HA_High = 0;
decimal HA_Low = 0;
decimal HA_Close = 0;
int bufferlength = 30;
decimal _open_ = 0, _high_ = 0, _low_ = 0, _close_ = 0;
MOST most;
DateTime _barOpeningTime_;
public override void OnInit()
{
most = new MOST(3, 2, MovMethod.Exponential);
AddSymbol(Symbol, SymbolPeriod);
SendOrderSequential(false);
WorkWithPermanentSignal(true);
}
public override void OnInitComplated()
{
}
public override void OnDataUpdate(BarDataCurrentValues barDataCurrentValues)
{
var barDataModel = GetBarData(Symbol, SymbolPeriod);
var open = barDataModel.Open[barDataCurrentValues.LastUpdate.BarDataIndex - 1];
var high = barDataModel.High[barDataCurrentValues.LastUpdate.BarDataIndex - 1];
var low = barDataModel.Low[barDataCurrentValues.LastUpdate.BarDataIndex - 1];
var close = barDataModel.Close[barDataCurrentValues.LastUpdate.BarDataIndex - 1];
Debug(open + ", " + high + ", " + low + ", " + close);
if (FirstBar)
{
Debug(bufferlength + " bar buffer hesaplaniyor");
for (int i = bufferlength; i >= 0; i--)
{
_open_ = Ref(barDataModel, OHLCType.Open, i);
_high_ = Ref(barDataModel, OHLCType.High, i);
_low_ = Ref(barDataModel, OHLCType.Low, i);
_close_ = Ref(barDataModel, OHLCType.Close, i);
HA_Open = i == bufferlength ? (_open_ + _close_) / 2 : HA_Open = (HA_Open + HA_Close) / 2;
HA_Close = (_open_ + _high_ + _low_ + _close_) / 4;
HA_High = Math.Max(_high_, Math.Max(HA_Open, HA_Close));
HA_Low = Minimum(_low_, Math.Min(HA_Open, HA_Close));
var indexOfRef = barDataCurrentValues.LastUpdate.BarDataIndex - i;
_barOpeningTime_ = barDataModel.Time[indexOfRef];
most.Update(HA_Close, indexOfRef, barDataModel.Time[indexOfRef]);
if (HA_Close > HA_Open)
Debug($"({i + 1} bar onceki fiyatlar: HA_Open = {Math.Round(HA_Open, 1)} , HA_Close= {HA_Close}, HA_High = {Math.Round(HA_High, 1)}, HA_Low = {HA_Low}. Bar POSITIVE)");
else
Debug($"({i + 1} bar onceki fiyatlar: HA_Open = {Math.Round(HA_Open, 1)} , HA_Close= {HA_Close}, HA_High = {Math.Round(HA_High, 1)}, HA_Low = {HA_Low}. Bar NEGATIVE)");
Debug($"Most Updated: HA_Close = {HA_Close}, time(Bar Opening) = {_barOpeningTime_})");
}
FirstBar = false;
}
else
{
HA_Open = (HA_Open + HA_Close) / 2;
HA_Close = (open + high + low + close) / 4;
HA_High = Math.Max(high, Math.Max(HA_Open, HA_Close));
HA_Low = Minimum(low, Math.Min(HA_Open, HA_Close));
}
most.Update(HA_Close, barDataCurrentValues.LastUpdate.BarDataIndex, barDataCurrentValues.LastUpdate.DTime);
Debug($"Heiken Ashi most = {Math.Round(most.CurrentValue,2)}, ExMov = {Math.Round(most.ExMOV.CurrentValue,2)}");
}
public override void OnOrderUpdate(IOrder order)
{
if (order.OrdStatus.Obj == OrdStatus.Filled)
{
}
}
}
}
***STRATEJILERI TEST/DENEME ORTAMINDA CALISTIRMADAN VE SIZIN ISTEDIGINIZ SEKILDE CALISTIGINA EMIN OLMADAN GERCEK ORTAMDA HIC BIR ZAMAN CALISTIRMAYINIZ***