Help with indicator  [SOLVED]

Questions about MultiCharts and user contributed studies.
bombaybom
Posts: 12
Joined: 13 Nov 2014
Has thanked: 7 times

Help with indicator

Postby bombaybom » 13 Nov 2014

Hi,

I hope you can guide me in the right direction.

Thanks in advance.


I woud like to have the Superindikator to work but have some problems with it.


-----------

Code: Select all

// my code

inputs: Length( 5 ), NumATRs( 1.5 ) ;

// Calculate the bands

Uband = (High + Low) / 2 + (NumATRs * AvgTrueRange( Length ));

Lband = (High + Low) / 2 - (NumATRs * AvgTrueRange( Length ));


//calculate the bands2
Up = If (or (Uband < Uband[1]; close > Uband[1])than Uband; Uband[1]);

Ned = If (or (Lband > Lband[1]; close > Lband[1])than Lband; Lband[1]);

//Calculate the trend

Trend = If(and(Trend[1]=up[1];close<Up);Up;If (and(trend=Up[1];close>Up);Ned;If(And(Trend[1]=Ned[1];Close>Ned);Ned;If(and(Trend[1]=Ned[1];close<Ned;Up Smiley: Wink )));


//Plot the line into the charts
Plot1(trend);
----------
what i woud like it to do :


Logic of SuperTrend
Values
• ATR = Average True Range value counting with Nbr_Periods as period.
• ATR Range = Multiplier * ATR.
• Medium Price = (High + Low)/2.
• Main Trend Line in Up Trend (Show in Color Lime) = Medium Price - ATR Range.
Tricky Part: And the value will keep the same as the previous one if the current value from the formula is less than the previous one, but it will rise up if the value is larger.
• Main Trend Line in Down Trend = Medium Price + ATR Range.
• Main Trend Line
Conditions
• Up Trend: Current close price is larger than the "Main Trend Line in Up Trend"
• Down Trend: Current close price is less than the "Main Trend Line in Down Trend"

User avatar
bensat
Posts: 331
Joined: 04 Oct 2014
Has thanked: 46 times
Been thanked: 104 times

Re: Help with indicator  [SOLVED]

Postby bensat » 13 Nov 2014

I hope I understood everything correct. I provide the code with the functions and indicator here. As you wished I inserted "Lime Green" & "Crimson Red" as colors.

Function : Color_Lime

Code: Select all

Color_Lime = RGB( 227, 255, 0);
Function : Color_Crimson

Code: Select all

Color_Crimson = RGB(153,0,0);
Function : Fct_SuperIndicator

Code: Select all

inputs: // INPUTS

Length(NumericSimple),
NumATR(NumericSimple),
CalcTrend(NumericRef);

vars: // VARIABLES
var.ATR(0),
var.ATRRange(0),
var.MedianPrice(0),
var.Uband(0),
var.Dband(0),
var.Up(0),
var.Dn(0),
var.Trend(1),
var.FlagH(0),
var.FlagL(0),
var.S(0),
var.High(0),
var.Low(0),
var.Close(0),
var.CB(0),
i.Length(0),
i.NumATR(0),
i.Trend(0);

// ::::::::::::::: <<-- INPUT CONVERSION -->> ::::::::::::::::::::::::::::::::::::::::::::::::::::::

i.Length = Length;
i.NumATR = NumATR;
var.High = high;
var.Low = low;
var.Close = close;
var.CB = currentbar;

// ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

var.ATR = AvgTrueRange(i.Length);
var.ATRRange = (var.ATR * i.NumATR);
var.MedianPrice = (var.High + var.low)*(0.5);

// ::::::: <-- UBAND / LBAND CALCULATION --> ::::::::::::::::::::::::::::::::::::::::::::::::::::::

var.Uband = (var.MedianPrice) + (i.NumATR * var.ATR);
var.Dband = (var.MedianPrice) - (i.NumATR * var.ATR);

// ::::::: <<-- TREND CONDITIONS & SELECTION -->> ::::::::::::::::::::::::::::::::::::::::::::::

If (var.Close > var.Uband[1]) then var.Trend = 1 else // change trend to pos if close > uband
if (var.Close < var.Dband[1]) then var.Trend = -1; // change trend to neg if close < dband

// if current trend changed to -1 from 1 then set flag for change for plot(dband) to 1
If (var.Trend < 0 and var.Trend[1] > 0) then var.FlagH = 1 else var.FlagH = 0;
// if current trend changed to 1 from -1 then set flag for change for plot(uband) to 1
If (var.Trend > 0 and var.Trend[1] < 0) then var.FlagL = 1 else var.FlagL= 0;

// if up trend indicated but current dband is < prev. ddand adj current dband to prev. dband level
If (var.Trend > 0 and var.Dband[0] < var.Dband[1]) then var.Dband = var.Dband[1];
// if dn trend indicated but current uband is > prev. udand adj current uband to prev. uband level
If (var.Trend < 0 and var.Uband[0] > var.Uband[1]) then var.Uband = var.Uband[1];

// specification for chnage of plot levels for both sides (dn + up trend)
If (var.FlagH = 1) then var.Uband = (var.MedianPrice) + (i.NumATR * var.ATR);
If (var.FlagL = 1) then var.Dband = (var.MedianPrice) - (i.NumATR * var.ATR);

// start with calc. of band levels after barnumber > length of ATR with current trend
If (var.Trend = 1) then var.S = var.Dband else var.S = var.Uband;
If (var.CB < i.Length + 1) then var.S = Lowest(var.Low, i.Length);

CalcTrend = var.Trend;

Fct_SuperIndicator = var.S; // set trend
Indicator : __Test__SuperIndicator

Code: Select all

inputs : // INPUTS

Length(5) ,
NumATR(1.5);

vars : // VARIABLES

var.SuperIndy(0),
var.SI(0),
i.Length(0),
i.NumATR(0);

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

i.Length = Length;
i.NumATR = NumATR;

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

var.SI = Fct_SuperIndicator(i.Length, i.NumATR, var.SuperIndy);

// :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Plot1(var.SI,"Up Trend");
Plot2(var.SI,"Down Trend");
Plot3(var.SI,"SuperTrend", Iff(var.SuperIndy = 1, Color_Lime, Color_Crimson));
Screenshot how it looks like.

Image

If it is not what you want, I'm sorry ;)

Regards.

Ben

bombaybom
Posts: 12
Joined: 13 Nov 2014
Has thanked: 7 times

Re: Help with indicator

Postby bombaybom » 14 Nov 2014

Thank you Ben!!!


That was perfect!
Just what I was looking for :)


Return to “MultiCharts”