Help for an indicator-Custom bands  [SOLVED]

Questions about MultiCharts and user contributed studies.
Marktwizz
Posts: 10
Joined: 18 Aug 2016
Has thanked: 1 time
Been thanked: 1 time

Help for an indicator-Custom bands

Postby Marktwizz » 01 Nov 2018

Dear community, I need help for building a custom indicator on Easylanguage.
I provide a brief explaination of the indicator.
I would like to calculate a function for every bar in a range of past bars. Than i would like to pick the highest and lowest value among the values of the function for each bar in the range; then i would sum the highest value to a moving average and subtract the lowest value from the same moving average. So my idea is to build a two bands indicator. I am not an expert in programming so if you could help me making the code I would be able to understand the logic behind. Thanks to anyone who will help me. Regards.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Help for an indicator-Custom bands

Postby TJ » 01 Nov 2018

Dear community, I need help for building a custom indicator on Easylanguage.
I provide a brief explaination of the indicator.
I would like to calculate a function for every bar in a range of past bars. Than i would like to pick the highest and lowest value among the values of the function for each bar in the range; then i would sum the highest value to a moving average and subtract the lowest value from the same moving average. So my idea is to build a two bands indicator. I am not an expert in programming so if you could help me making the code I would be able to understand the logic behind. Thanks to anyone who will help me. Regards.
The first steps in writing an indicator --

1. You must be able to visualize it -- draw a mockup chart, with notes explaining the salient points of the indicator.
2. You must be able to manually demonstrate it -- put some numbers on an Excel spreadsheet and show us how the calculation is done.

After the above is done, then you can attempt to write some pseudo-codes.

Marktwizz
Posts: 10
Joined: 18 Aug 2016
Has thanked: 1 time
Been thanked: 1 time

Re: Help for an indicator-Custom bands

Postby Marktwizz » 01 Nov 2018

Function = (Close - sma(30))/standarddev
I need to compute this value for the last 30 bars and pick the greates and the lowest values.
Than i would sum the greatest value of the function to the sma(30) and i would subtract the lowest value of the function from the sma(30). I hope i have been more clear now. Thanks a lot TJ

hughesfleming
Posts: 275
Joined: 22 Apr 2014
Has thanked: 70 times
Been thanked: 72 times

Re: Help for an indicator-Custom bands

Postby hughesfleming » 02 Nov 2018

Like this? Subtracting the lowest of the standarddev vaues would give you a line that is very close the moving average. This is substacting highest value from the MA and adding the highest value to the MA.
Bands Example.PNG
(65.25 KiB) Downloaded 671 times

Marktwizz
Posts: 10
Joined: 18 Aug 2016
Has thanked: 1 time
Been thanked: 1 time

Re: Help for an indicator-Custom bands

Postby Marktwizz » 02 Nov 2018

Thanks a lot. Could you share the code please?

hughesfleming
Posts: 275
Joined: 22 Apr 2014
Has thanked: 70 times
Been thanked: 72 times

Re: Help for an indicator-Custom bands

Postby hughesfleming » 02 Nov 2018

@Marktwizz,

I had to make a minor correction to the code as I realised that the values of your function needed to be absolute values.
Bands Example2.PNG
(60.24 KiB) Downloaded 664 times

Code: Select all

inputs:

priceseries(close),
lookback(30);

vars:

series(0),
funcseries(0),
funcseries_highestvalue(0),
bandhigh(0),
bandlow(0);


funcseries = absvalue((priceseries - average(priceseries,lookback)) / StandardDev(priceseries,lookback,2));
funcseries_highestvalue = HighestFC(funcseries,lookback);

series = AverageFC(priceseries,lookback);
bandhigh = series + funcseries_highestvalue;
bandlow = series - funcseries_highestvalue;

Plot1(series);
Plot2(bandhigh);
Plot3(bandlow);


hughesfleming
Posts: 275
Joined: 22 Apr 2014
Has thanked: 70 times
Been thanked: 72 times

Re: Help for an indicator-Custom bands

Postby hughesfleming » 02 Nov 2018

Using StdDev directly on the price series will always result in jumpy values of your bands. If you want smoother bands then another appoach would be to load the 30 highest values into an array and then apply a little bit of averaging. You get more or less the same but smoother. Making minor adjustments to lookback length and band smoothing gives you some flexibility. There can be serveral different but similar ways to solve the same problem in Easylanguage. One is not better than the other but it helps to be aware of them.
Smoother Stddev bands.PNG
(82.78 KiB) Downloaded 664 times

Code: Select all


inputs:

priceseries(close),
lookback(30),
bandsmoothing(5);

vars:

xx(0),
Peak(0),
series(0),
funcseries(0),
bandhigh(0),
bandlow(0);

arrays:

HV_array[100](0);


funcseries = absvalue((priceseries - average(priceseries,lookback)) / StandardDev(priceseries,lookback,2));


series = AverageFC(priceseries,lookback);

For xx = 0 to LookBack-1

begin

HV_Array[xx] = funcseries[xx];
Array_Sort(HV_Array,0,LookBack,false);


end;

Peak = AverageArray(HV_array,bandsmoothing);

bandhigh = series+peak;
bandlow = series-peak;



Plot1(series);
Plot2(bandhigh);
Plot3(bandlow);


Marktwizz
Posts: 10
Joined: 18 Aug 2016
Has thanked: 1 time
Been thanked: 1 time

Re: Help for an indicator-Custom bands  [SOLVED]

Postby Marktwizz » 02 Nov 2018

Thanks a lot hughesfleming, i really appreciate your suggestions.

Marktwizz
Posts: 10
Joined: 18 Aug 2016
Has thanked: 1 time
Been thanked: 1 time

Re: Help for an indicator-Custom bands

Postby Marktwizz » 02 Nov 2018

Thanks a 1000000.how can I pick a specific value in an array after it has been sorted.
Lets say I would like to pick the value number 19,what would be the code?
Thanks.

hughesfleming
Posts: 275
Joined: 22 Apr 2014
Has thanked: 70 times
Been thanked: 72 times

Re: Help for an indicator-Custom bands

Postby hughesfleming » 02 Nov 2018

Declare a variable, lets say y ....then y=HV_array[19]

You might to look through this. http://www.traderslaboratory.com/forums ... ylanguage/

regards,

Alex


Return to “MultiCharts”