Linear Regression Channel (Simple)

Here you can post and download custom indicators. PLEASE: Do not start topics unless you are posting your own indicator, they will be moved to appropriate section even if you do.

Moderator: admin

Re: Linear Regression Channel (Simple)

Postby Apprentice » Wed Feb 16, 2011 1:21 pm

Very interesting proposal.
I'll try to write it as soon as possible.

In addition, I'll try to write a Price / Data filters in order to filter the different data sources.
What would later be used with existing indicators.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Linear Regression Channel (Simple)

Postby Apprentice » Wed Feb 16, 2011 1:57 pm

I add a version that contains a simple data filter.

if open[i] > Mid[i]+ SD[i] then
open[i] = Mid[i]+ SD[i];
elseif open[i] < Mid[i] - SD[i] then
open[i] = Mid[i] - SD[i] ;
end


if close[i] > Mid[i]+ SD[i] then
close[i] = Mid[i]+ SD[i];
elseif close[i] < Mid[i] - SD[i] then
close[i] = Mid[i] - SD[i];
end


if high[i] > Mid[i]+ SD[i] then
high[i] = Mid[i]+ SD[i];
elseif high[i] < Mid[i] - SD[i] then
high[i] = Mid[i] - SD[i];
end


if low[i] > Mid[i]+ SD[i] then
low[i] = Mid[i]+ SD[i];
elseif low[i] < Mid[i] - SD[i] then
low[i] = Mid[i] - SD[i] ;
end


After thorough research plans to release an independent data filter.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Linear Regression Channel (Simple)

Postby BlueBloodedTrader » Mon Aug 01, 2011 4:53 am

UPDATE REQUEST

Would it be possible to have this indicator working on a basis where it doesn't include the current candle (so a linear regression channel based on candles n-x to n-1) and then incorporate a breakout strategy on this indicator so that if the current candle (not included in the regression calculation) breaks out of either the upper or lower limit then a trade is entered?
BlueBloodedTrader
 
Posts: 11
Joined: Tue Feb 15, 2011 6:02 pm

Re: Linear Regression Channel (Simple)

Postby Coondawg71 » Sun Dec 09, 2012 12:33 pm

Can we please request an update to this indicator which would add user option of additional standard deviation parameters such as 0.25, 0.50, 0.75, 1.618, 2.0, 3.0.

thanks,

sjc
User avatar
Coondawg71
FXCodeBase: Graduate
 
Posts: 324
Joined: Sat Jan 15, 2011 11:45 am

Re: Linear Regression Channel (Simple)

Postby Apprentice » Mon Dec 10, 2012 3:08 am

Version with Multiple, deviation lines added.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Linear Regression Channel (Simple)

Postby Coondawg71 » Mon Dec 10, 2012 6:55 am

Thanks! Exactly what I needed. Works great for trading off the median lines and the trend lines associated with it. As you probably know, there is the small issue of: if you toggle any of the additional ratios to "OFF" it creates an error for the indicator. So before users flood the thread with error notices, users please toggle all the default ratios to "YES", and the "Channel Mode to "Deviation"; these ratios will prove to be quite beneficial trend lines for future price action!

Thanks Again for another job well done and expeditious turn around!

sjc
User avatar
Coondawg71
FXCodeBase: Graduate
 
Posts: 324
Joined: Sat Jan 15, 2011 11:45 am

Re: Linear Regression Channel (Simple)

Postby Apprentice » Mon Dec 10, 2012 9:01 am

Corrected.
By mistake I upload wrong, in development version.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Linear Regression Channel (Simple)

Postby boss_hogg » Tue Jan 08, 2013 12:55 pm

BlueBloodedTrader wrote:UPDATE REQUEST

Would it be possible to have this indicator working on a basis where it doesn't include the current candle (so a linear regression channel based on candles n-x to n-1) and then incorporate a breakout strategy on this indicator so that if the current candle (not included in the regression calculation) breaks out of either the upper or lower limit then a trade is entered?


This is exactly what I also wanted, I think I managed to make it work. Keep in mind the following:
For a 2 candle period, lets consider the last 4 candles:
n is the current (still running) one: the lines are drawn up to this candle so you see if there will be a break out or not; it is not taken into account for the calculations though
n-1 and n-2: these are the candles used for the calculations
n-3: the line is also drawn till that but it is not taken into account for the calculations; I could not remove it so I just kept it and just ignore it.

I have also added two output streams, one for tilt and one for break out:
tilt: -1 for downslope, 0 for horizontal, 1 for upslope
break out: 1 for breaking top line, -1 for breaking bottom line, 0 for not breaking either

When the current candle closes, keep in mind that:
- break out is calculated if the close value of the CURRENT candle is higher/lower than the top/bottom lines at the CURRENT candle period
- THEN the standard deviation is calculated and then tilt is calculated considering candles n and n-1 (which are to become n-1 and n-2)
- THEN the new top and bottom lines are calculated and they will be used for break out calculation of the NEW current candle.

Apprentice one question for you: I tried to use internal streams (addInternalStream) for passing values to a strategy but I failed; is it only possible with normal streams (addStream) ?
Attachments
Raff regression.lua
(10.63 KiB) Downloaded 678 times
boss_hogg
FXCodeBase: Confirmed User
 
Posts: 48
Joined: Fri Oct 26, 2012 3:03 am

Re: Linear Regression Channel (Simple)

Postby boss_hogg » Tue Jan 08, 2013 1:01 pm

One more thing, if there are two ore more consecutive break outs in the same direction, then break out value is 2 or -2 for top/bottom respectively.
boss_hogg
FXCodeBase: Confirmed User
 
Posts: 48
Joined: Fri Oct 26, 2012 3:03 am

Re: Linear Regression Channel (Simple)

Postby Apprentice » Wed Jan 09, 2013 5:06 pm

Yes you have to use normal streams.


Try to use this implementation.

indicator.parameters:addBoolean("Use", "Use Signal Mode", "" , true);

local Use;
local Out;

Use =instance.parameters.Use;

if Use then
Out = instance:addStream("Out", core.Line, name, "Out",core.rgb(0,0,0), first);
end


if Use then
if condition then
Out[period]= 1;
elseif condition then
Out[period]= -1;
end
end


By adding this Additional parameter, Use.
You can control the output signal.
If u use it as indicator, set it to false.
If called from the strategy Use true.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

PreviousNext

Return to Custom Indicators

Who is online

Users browsing this forum: Bing [Bot] and 50 guests