Description
using System; using cAlgo.API; using cAlgo.API.Internals; using cAlgo.API.Indicators; namespace cAlgo.Indicators { [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)] public class SMAMTF : Indicator { [Parameter(DefaultValue = 14)] public int Periods { get; set; } [Parameter("SMA Timeframe1", DefaultValue = "Minute15")] public TimeFrame SMATimeframe1 { get; set; } [Parameter("SMA Timeframe2", DefaultValue = "Hour")] public TimeFrame SMATimeframe2 { get; set; } [Parameter("SMA Timeframe3", DefaultValue = "Hour4")] public TimeFrame SMATimeframe3 { get; set; } [Output("SMA1", Color = Colors.Blue)] public IndicatorDataSeries SMA1 { get; set; } [Output("SMA2", Color = Colors.Red)] public IndicatorDataSeries SMA2 { get; set; } [Output("SMA3", Color = Colors.Yellow)] public IndicatorDataSeries SMA3 { get; set; } private MarketSeries series1; private MarketSeries series2; private MarketSeries series3; private SimpleMovingAverage Sma1; private SimpleMovingAverage Sma2; private SimpleMovingAverage Sma3; protected override void Initialize() { series1 = MarketData.GetSeries(SMATimeframe1); series2 = MarketData.GetSeries(SMATimeframe2); series3 = MarketData.GetSeries(SMATimeframe3); Sma1 = Indicators.SimpleMovingAverage(series1.Close, Periods); Sma2 = Indicators.SimpleMovingAverage(series2.Close, Periods); Sma3 = Indicators.SimpleMovingAverage(series3.Close, Periods); } public override void Calculate(int index) { var index1 = GetIndexByDate(series1, MarketSeries.OpenTime[index]); if (index1 != -1) { SMA1[index] = Sma1.Result[index1]; } var index2 = GetIndexByDate(series2, MarketSeries.OpenTime[index]); if (index2 != -1) { SMA2[index] = Sma2.Result[index2]; } var index3 = GetIndexByDate(series3, MarketSeries.OpenTime[index]); if (index3 != -1) { SMA3[index] = Sma3.Result[index3]; } } private int GetIndexByDate(MarketSeries series, DateTime time) { for (int i = series.Close.Count - 1; i > 0; i--) { if (time == series.OpenTime[i]) return i; } return -1; } } }
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
public class SMAMTF : Indicator
{
[Parameter(DefaultValue = 14)]
public int Periods { get; set; }
[Parameter("SMA Timeframe1", DefaultValue = "Minute15")]
public TimeFrame SMATimeframe1 { get; set; }
[Parameter("SMA Timeframe2", DefaultValue = "Hour")]
public TimeFrame SMATimeframe2 { get; set; }
[Parameter("SMA Timeframe3", DefaultValue = "Hour4")]
public TimeFrame SMATimeframe3 { get; set; }
[Output("SMA1", Color = Colors.Blue)]
public IndicatorDataSeries SMA1 { get; set; }
[Output("SMA2", Color = Colors.Red)]
public IndicatorDataSeries SMA2 { get; set; }
[Output("SMA3", Color = Colors.Yellow)]
public IndicatorDataSeries SMA3 { get; set; }
private MarketSeries series1;
private MarketSeries series2;
private MarketSeries series3;
private SimpleMovingAverage Sma1;
private SimpleMovingAverage Sma2;
private SimpleMovingAverage Sma3;
protected override void Initialize()
{
series1 = MarketData.GetSeries(SMATimeframe1);
series2 = MarketData.GetSeries(SMATimeframe2);
series3 = MarketData.GetSeries(SMATimeframe3);
Sma1 = Indicators.SimpleMovingAverage(series1.Close, Periods);
Sma2 = Indicators.SimpleMovingAverage(series2.Close, Periods);
Sma3 = Indicators.SimpleMovingAverage(series3.Close, Periods);
}
public override void Calculate(int index)
{
var index1 = GetIndexByDate(series1, MarketSeries.OpenTime[index]);
if (index1 != -1)
{
SMA1[index] = Sma1.Result[index1];
}
var index2 = GetIndexByDate(series2, MarketSeries.OpenTime[index]);
if (index2 != -1)
{
SMA2[index] = Sma2.Result[index2];
}
var index3 = GetIndexByDate(series3, MarketSeries.OpenTime[index]);
if (index3 != -1)
{
SMA3[index] = Sma3.Result[index3];
}
}
private int GetIndexByDate(MarketSeries series, DateTime time)
{
for (int i = series.Close.Count - 1; i > 0; i--)
{
if (time == series.OpenTime[i])
return i;
}
return -1;
}
}
}
SO
sohoj
Joined on 02.01.2015
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: SMA MTF.algo
- Rating: 5
- Installs: 3653
- Modified: 13/10/2021 09:54
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
JO
Requires unlimited access rights, be careful.
Danke für das teilen