Description
This is a simple indicator to show if global and local trend directions are the same. It uses two timeframes, a "local" timeframe and a higher order "global" timeframe.The indicator shows price action only and has no lag. It generates a square wave (green line), the output signal is above zero if the price tendency is bullish upward, and below zero for bearish downward tendency. The red line shows the tendency of a higher order timeframe (the global tendency). The idea is to trade long when price tends to grow on both timeframes (indicator showing both lines cross zero and go above), and vice versa, trade short when the price tends down (both lines cross zero and go below). Close or exit positions on the opposite signal. The global timeframe setting of at least 4x local timeframe is recommended, for example, m15/h1, or h1/ h4, etc...
using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo {
[Indicator (IsOverlay = false, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class CandlestickTendency : Indicator {
[Parameter ()]
public TimeFrame HighOrderTimeFrame { get; set; }
[Output ("Line", PlotType = PlotType.Line, Color = Colors.Green)]
public IndicatorDataSeries Line { get; set; }
[Output ("Histogram", PlotType = PlotType.Histogram, Color = Colors.DarkGreen)]
public IndicatorDataSeries Histogram { get; set; }
[Output ("High Order Line", PlotType = PlotType.Line, Color = Colors.Red)]
public IndicatorDataSeries HighOrderLine { get; set; }
int index1, index2;
MarketSeries series2;
double value1, value2;
protected override void Initialize () {
value1 = value2 = 0;
series2 = MarketData.GetSeries (HighOrderTimeFrame);
}
public bool trend1IsRising { get { return (MarketSeries.Close[index1] > MarketSeries.Open[index1 - 1]); }}
public bool trend1IsFalling { get { return (MarketSeries.Close[index1] < MarketSeries.Open[index1 - 1]); }}
public bool trend2IsRising { get { return (series2.Close[index2] > series2.Open[index2 - 1]); }}
public bool trend2IsFalling { get { return (series2.Close[index2] < series2.Open[index2 - 1]); }}
public override void Calculate (int index) {
index1 = index;
index2 = series2.OpenTime.GetIndexByExactTime (MarketSeries.OpenTime[index1]);
if (trend1IsFalling)
value1 = -1;
if (trend1IsRising)
value1 = 1;
if (trend2IsFalling)
value2 = -2;
if (trend2IsRising)
value2 = 2;
Line[index] = value1;
Histogram[index] = value1;
HighOrderLine[index] = value2;
}
}
}
igorkroitor
Joined on 03.01.2015
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Candlestick Tendency.algo
- Rating: 5
- Installs: 6277
- Modified: 13/10/2021 09:54
Comments
I don't know how to post a picture...
Thanks for this indicator.
Nevertheless, I failed to use it inside a bot.
See the chart attached. Higher timeframe is H2. The indicator displays 2 for HighOrderLine between 16:00 and 19:30, and -2 between 8:00 and 15:30:
But when I print this : Print("HighOrderLine = {0}, Line = {1}", tendency.HighOrderLine.Last(0), tendency.Line.Last(0));
I have in the log : 2 between 18:00 and 19:30, but -2 at 17:00 and 17:30 which are incorrect, and I don't know why.
Please could you help me ?
Again thanks.
Nota : UTC+1 for both chart and Log
indicator exchange trend then returns to the original again, there's no way to make sure the information it passes.
Hello Igorkroitor, greetings from indonesia.
First of all, thank you for coding this indicator and sharing this with us, this is a nice concept but i have a concern.
this indicator redraw its higher time frame, as shown by following picture
following is the current image
[IMG]http://i68.tinypic.com/2e3ct3k.jpg[/IMG]
and this is the backtest image, minus 2 day
[IMG]http://i63.tinypic.com/30w8msy.jpg[/IMG]
i thought the concept was following the higher time frame trend, and looking for chances of following that trend with the lower time frame, but if it redraw it will lose its purpose. I really hope you can fix this problem because this indicator has clean and nice interface.
Thank you for your hardwork.
Regards
Bagus