90 Points instrument issue

Questions about MultiCharts and user contributed studies.
tcat
Posts: 176
Joined: 02 Feb 2008
Location: Lausanne, Switzerland
Has thanked: 9 times
Been thanked: 5 times

90 Points instrument issue

Postby tcat » 12 May 2021

I have migrated the SuperTrend indicator to a function in order to integrate it in a system. Working on "minutes" charts, the function gives the same results as the indicator when plotted.

However, when working on a 90 points chart, the function output a fixed value, resulting in a straight line when plotted. The following codes are being used:

SuperTrend Indicator:

Code: Select all

// SuperTrend INDICATOR inputs: ATRLength(2), ATRMult(1.2), AVG.Value((h+l+c)/3); vars: ATR(0), dn.value(0), up.value(0), trend(1), flag(0), flagh(0), SuperTrend(0); ATR = AvgTrueRange(ATRLength) * ATRMult; up.value = AVG.Value + ATR; dn.value = AVG.Value - ATR; //-------------------------------------------------------------- if close > up.value[1] then trend = 1 //trend positif else if close < dn.value[1] then trend = -1; //trend negatif if trend < 0 then begin //if trend negatif if trend[1] > 0 then flag = 1 else flag = 0; if up.value> up.value[1] then up.value= up.value[1]; end; if trend > 0 then begin //if trend positif if trend[1] < 0 then flagh = 1 else flagh = 0; if dn.value < dn.value[1] then dn.value = dn.value[1]; end; //-------------------------------------------------------------- if flag = 1 then up.value = AVG.Value + ATR; if flagh = 1 then dn.value = AVG.Value - ATR; if trend = 1 then SuperTrend = dn.value else SuperTrend = up.value; //-------------------------------------------------------------- Plot10(SuperTrend,"SuperTrend",iff(trend = 1, green, red));
SuperTrend Function

Code: Select all

// SuperTrend.Function -------------------------------------------------------------------- Input: SuperTrend.Value(NumericSeries); vars: ATR.Length(2), ATR.Mult(1.2), AVG.Value(0), ATR(0), dn.value(0), up.value(0), trend(1), flag(0), flagh(0); vars: opend0(0),highd0(0), lowd0(0), closed0(0); opend0 = OpenS(0); highd0= HighS(0); lowd0= LowS(0); closed0= CloseS(0); AVG.Value = ((highd0 + lowd0 + closed0)/3) ; ATR = AvgTrueRange(ATR.Length) * ATR.Mult; up.value = AVG.Value + ATR; dn.value = AVG.Value - ATR; if closed0 > up.value[1] then trend = 1 // trend positif else if closed0 < dn.value[1] then trend = -1; // trend negatif if trend < 0 then begin // if trend negatif if trend[1] > 0 then flag = 1 else flag = 0; if up.value> up.value[1] then up.value= up.value[1]; end; if trend > 0 then begin // if trend positif if trend[1] < 0 then flagh = 1 else flagh = 0; if dn.value < dn.value[1] then dn.value = dn.value[1]; end; if flag = 1 then up.value = AVG.Value + ATR; if flagh = 1 then dn.value = AVG.Value - ATR; if trend = 1 then SuperTrend.Function = dn.value else SuperTrend.Function = up.value;
SuperTrend plot for function

Code: Select all

var: SuperTrend.Calc(0), SuperTrend.Value(0); SuperTrend.Calc = SuperTrend.Function(SuperTrend.Value); Plot10(SuperTrend.Calc,"SuperTrend", Yellow);
As mentionned, this code works fine with "minutes" instruments but fails with point instruments. I am suspecting that this relates to the usage of
OpenS(0), HighS(0), LowS(0) and CloseS(0) which may not support point instruments. Would that be the case, how can I get OHLC data be properly work in a function applied to point instruments?


Tcat

User avatar
Tammy MultiCharts
Posts: 200
Joined: 06 Aug 2020
Has thanked: 6 times
Been thanked: 65 times

Re: 90 Points instrument issue

Postby Tammy MultiCharts » 08 Jun 2021

Hi tcat,

In the indicator you use (H+L+C)/3 to define AVG.Value.

Code: Select all

// SuperTrend INDICATOR inputs: ATRLength(2), ATRMult(1.2), AVG.Value((h+l+c)/3); vars: ATR(0), dn.value(0), up.value(0), trend(1), flag(0), flagh(0), SuperTrend(0); ATR = AvgTrueRange(ATRLength) * ATRMult; up.value = AVG.Value + ATR; dn.value = AVG.Value - ATR;
In the function, on the other hand, OpenS(0), HighS(0), LowS(0), CloseS(0) are used for defining AVG.Value.

Code: Select all

// SuperTrend.Function -------------------------------------------------------------------- Input: SuperTrend.Value(NumericSeries); vars: ATR.Length(2), ATR.Mult(1.2), AVG.Value(0), ATR(0), dn.value(0), up.value(0), trend(1), flag(0), flagh(0); vars: opend0(0),highd0(0), lowd0(0), closed0(0); opend0 = OpenS(0); highd0= HighS(0); lowd0= LowS(0); closed0= CloseS(0); AVG.Value = ((highd0 + lowd0 + closed0)/3) ; ATR = AvgTrueRange(ATR.Length) * ATR.Mult; up.value = AVG.Value + ATR; dn.value = AVG.Value - ATR;
Hence, you get different results for the indicator and the function.
To have the same calculation results on point chart please try to make the corresponding changes in SuperTrend.Function: instead of AVG.Value = ((highd0 + lowd0 + closed0)/3); use AVG.Value = ((h+l+c)/3);

tcat
Posts: 176
Joined: 02 Feb 2008
Location: Lausanne, Switzerland
Has thanked: 9 times
Been thanked: 5 times

Re: 90 Points instrument issue

Postby tcat » 11 Jun 2021

Hello Tammy,

Thanks for your reply but it doesn't answer my issue. My focus is on the "SuperTrend Function" and the "SuperTrend plot for function".

Working on NZDCHF minutes charts (60-1440), the "SuperTrend plot for function" works fine.
Working on NZDCHF 90 points range charts, the value of the indicator is not correctly plotted.

I had put the original Supertrend Indicator as a reference and I am aware that it is using HLC and not highd0, lowd0 and closed0. However, this is not my issue, my issue being that an indicators which works on minutes charts does not work on range charts.

Cheers,
Thierry


Return to “MultiCharts”