Information
Username: | sohoj |
Member since: | 02 Jan 2015 |
Last login: | 02 Jan 2015 |
Status: | Active |
Activity
Where | Created | Comments |
---|---|---|
Algorithms | 1 | 4 |
Forum Topics | 0 | 0 |
Jobs | 0 | 0 |
Last Algorithm Comments
//For SMA By Sohoj
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;
}
}
}
Here is modified code
Language: C#
Trading Platform:
{
[Indicator
{
[Parameter
[Parameter
[Parameter
[Parameter
[Output
{
_bollingerBands = Indicators
}
{
Diff[index] = (_bollingerBands.Top[index] - _bollingerBands.Bottom[index]) / _bollingerBands.Main[index];
}
}
}
Is it possible to plot the this indicator as histogram instead of lines
Thanks in advance.
Credit - cjdduarte