Description
this indicator show other time frame close in lower time frame. for ex: show daily close in m 15.
support us for more free indicator and bot by sign up in LiteFinance broker from this link
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
public class IRCloseMTF : Indicator
{
[Parameter("Base Timeframe", DefaultValue = "Daily")]
public TimeFrame BaseTimeFrame { get; set; }
[Output("MA", LineColor = "Red", LineStyle = LineStyle.Solid, Thickness = 2)]
public IndicatorDataSeries close_Line { get; set; }
private MovingAverage _ma;
private Bars _baseTimeFrameBars;
double slope;
int n, nBars, lastBar = 0, One = 0, modeTimeframe = 0;
protected override void Initialize()
{
_baseTimeFrameBars = MarketData.GetBars(BaseTimeFrame);
_ma = Indicators.MovingAverage(_baseTimeFrameBars.ClosePrices, 1, MovingAverageType.Simple);
nBars = Bars.Count;
if (Chart.TimeFrame < BaseTimeFrame)
modeTimeframe = 1;
else if (Chart.TimeFrame == BaseTimeFrame)
modeTimeframe = 2;
}
private void Draw()
{
for (int j = 1; j <= nBars; j++)
{
var baseSeriesIndex = _baseTimeFrameBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[j]);
double ma1 = _ma.Result[baseSeriesIndex];
var baseSeriesIndexB = _baseTimeFrameBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[j - 1]);
double ma2 = _ma.Result[baseSeriesIndexB];
if (ma1 != ma2)
{
for (int i = j; i <= nBars; i++)
{
ma2 = _ma.Result[_baseTimeFrameBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[i])];
if (ma1 != ma2)
{
slope = (ma2 - ma1) / (i - j);
n = 0;
lastBar = j;
break;
}
}
}
close_Line[j] = ma1 + (slope * n);
n++;
}
}
public override void Calculate(int index)
{
if (modeTimeframe == 1)
{
if (nBars < Bars.Count)
nBars = Bars.Count;
if (One != nBars)
{
Draw();
One = nBars;
}
if (IsLastBar)
{
var baseSeriesIndex = _baseTimeFrameBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[index]);
double ma3 = _ma.Result[_baseTimeFrameBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[lastBar - 1])];
double ma4;
for (int i = lastBar - 1; i > 0; i--)
{
ma4 = _ma.Result[_baseTimeFrameBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[i])];
if (ma3 != ma4)
{
ma4 = _ma.Result[_baseTimeFrameBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[i + 1])];
ma3 = _ma.Result[_baseTimeFrameBars.OpenTimes.GetIndexByTime(Bars.OpenTimes[lastBar])];
slope = (ma3 - ma4) / (lastBar - i);
n = 0;
for (int j = i + 1; j <= lastBar; j++)
{
close_Line[j] = ma4 + (slope * n);
n++;
}
break;
}
}
}
}
else if (modeTimeframe == 2)
{
close_Line[index] = _ma.Result[index];
}
}
}
}
IR
IRCtrader
Joined on 17.06.2021
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: IR Close MTF.algo
- Rating: 5
- Installs: 307
- Modified: 03/05/2024 10:39
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.
No comments found.