Description
This indicator displays the current trend in several timeframes from one minute to one month. It uses the Directional Movement System and the Parabolic SAR to determine the trend. In each timeframe the trend may be up, down or flat (uncertain).
The source code is not displayed correctly below because it has special characters for the arrows. You can download the source code from: this link
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Text;
using System.Collections.Generic;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class MTFTrend : Indicator
{
[Parameter("Vertical Alignment", Group = "Position", DefaultValue = VerticalAlignment.Top)]
public VerticalAlignment vAlignment { get; set; }
[Parameter("Horizontal Alignment", Group = "Position", DefaultValue = HorizontalAlignment.Right)]
public HorizontalAlignment hAlignment { get; set; }
[Output("Main")]
public IndicatorDataSeries Result { get; set; }
private List<Box> list;
private string lastResult;
private string UPARROW = "
guillermo
Joined on 07.06.2019
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: MTF Trend.algo
- Rating: 0
- Installs: 3233
- Modified: 13/10/2021 09:54
Comments
Major thanks
Hi Guys.
thankyou for the indicator, just installed it
would be great if we could see the colour changes implemented so you could see
at glance red or green.
much appreciated
thanks again
Hey, I color coded your output. No more need for the arrows and easier to read.
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Text;
using System.Collections.Generic;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class MTFTrend : Indicator
{
[Parameter("Vertical Alignment", Group = "Position", DefaultValue = VerticalAlignment.Top)]
public VerticalAlignment vAlignment { get; set; }
[Parameter("Horizontal Alignment", Group = "Position", DefaultValue = HorizontalAlignment.Right)]
public HorizontalAlignment hAlignment { get; set; }
private List<Box> list;
private string lastResult;
protected override void Initialize()
{
this.list = new List<Box>();
Bars barsM1 = MarketData.GetBars(TimeFrame.Minute);
Bars barsM5 = MarketData.GetBars(TimeFrame.Minute5);
Bars barsM15 = MarketData.GetBars(TimeFrame.Minute15);
Bars barsM30 = MarketData.GetBars(TimeFrame.Minute30);
Bars barsH1 = MarketData.GetBars(TimeFrame.Hour);
Bars barsH4 = MarketData.GetBars(TimeFrame.Hour4);
Bars barsD1 = MarketData.GetBars(TimeFrame.Daily);
Bars barsW1 = MarketData.GetBars(TimeFrame.Weekly);
Bars barsMN = MarketData.GetBars(TimeFrame.Monthly);
list.Add(new Box("MN", " ", Indicators.DirectionalMovementSystem(barsMN, 14), Indicators.ParabolicSAR(barsMN, 0.02, 0.2)));
list.Add(new Box("W1", " ", Indicators.DirectionalMovementSystem(barsW1, 14), Indicators.ParabolicSAR(barsW1, 0.02, 0.2)));
list.Add(new Box("D1", " ", Indicators.DirectionalMovementSystem(barsD1, 14), Indicators.ParabolicSAR(barsD1, 0.02, 0.2)));
list.Add(new Box("H4", " ", Indicators.DirectionalMovementSystem(barsH4, 14), Indicators.ParabolicSAR(barsH4, 0.02, 0.2)));
list.Add(new Box("H1", " ", Indicators.DirectionalMovementSystem(barsH1, 14), Indicators.ParabolicSAR(barsH1, 0.02, 0.2)));
list.Add(new Box("M30", " ", Indicators.DirectionalMovementSystem(barsM30, 14), Indicators.ParabolicSAR(barsM30, 0.02, 0.2)));
list.Add(new Box("M15", " ", Indicators.DirectionalMovementSystem(barsM15, 14), Indicators.ParabolicSAR(barsM15, 0.02, 0.2)));
list.Add(new Box("M5", " ", Indicators.DirectionalMovementSystem(barsM5, 14), Indicators.ParabolicSAR(barsM5, 0.02, 0.2)));
list.Add(new Box("M1", " ", Indicators.DirectionalMovementSystem(barsM1, 14), Indicators.ParabolicSAR(barsM1, 0.02, 0.2)));
this.lastResult = "";
}
public override void Calculate(int index)
{
string sb_green = "", sb_white = "", sb_red = "";
double price = (Symbol.Ask + Symbol.Bid) * 0.5;
foreach (Box box in this.list)
{
bool adxBullish = true;
bool psarBullish = true;
if (box.adx.DIPlus.LastValue < box.adx.DIMinus.LastValue)
{
adxBullish = false;
}
if (price < box.psar.Result.LastValue)
{
psarBullish = false;
}
if (adxBullish && psarBullish)
{
sb_green += " " + box.label;
sb_red += " " + box.empty;
sb_white += " " + box.empty;
}
else if (!adxBullish && !psarBullish)
{
sb_green += " " + box.empty;
sb_red += " " + box.label;
sb_white += " " + box.empty;
}
else
{
sb_green += " " + box.empty;
sb_red += " " + box.empty;
sb_white += " " + box.label;
}
}
string result = sb_green + sb_white + sb_red;
if (!result.Equals(this.lastResult))
{
Chart.DrawStaticText("idtext_green", "\n"+sb_green+".", this.vAlignment, this.hAlignment, Color.Green);
Chart.DrawStaticText("idtext_red", "\n"+sb_red+".", this.vAlignment, this.hAlignment, Color.Chocolate);
Chart.DrawStaticText("idtext_white", "\n"+sb_white+".", this.vAlignment, this.hAlignment, Color.Gray);
this.lastResult = result;
}
}
}
public class Box
{
public Box(string l, string e, DirectionalMovementSystem a, ParabolicSAR p)
{
this.label = l;
this.empty = e;
this.adx = a;
this.psar = p;
}
public string label { get; set; }
public string empty { get; set; }
public DirectionalMovementSystem adx { get; set; }
public ParabolicSAR psar { get; set; }
}
}
Major thanks