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));
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;
Code: Select all
var: SuperTrend.Calc(0), SuperTrend.Value(0);
SuperTrend.Calc = SuperTrend.Function(SuperTrend.Value);
Plot10(SuperTrend.Calc,"SuperTrend", Yellow);
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