Requests & Ideas - page 147

 

adeo

This is the function I used in the automatic (linear) regression channel :

//---------------------------------------------------------------------------------|

// |

//---------------------------------------------------------------------------------|

//

//

//

//

//

int lr.period=0;

double lr.sumX;

double lr.sumXSqr;

double lr.divisor;

//

//

//

//

//

double iLRValue(double& LinearRegSlope, int len, int shift)

{

double LinearRegValue;

double Intercept;

double SumXY = 0;

double SumY = 0;

//

//

//

//

//

if (lr.period != len)

{

lr.period = len;

lr.sumX = lr.period * (lr.period-1) / 2;

lr.sumXSqr = lr.period * (lr.period-1) * (2 * lr.period - 1) / 6;

lr.divisor = MathPow(lr.sumX,2) - lr.period * lr.sumXSqr;

}

//

//

//

//

//

for (int i=0; i<lr.period; i++)

{

double price = prices;

SumXY += i*price;

SumY += price;

}

if( lr.divisor != 0 )

LinearRegSlope = (lr.period * SumXY - lr.sumX * SumY)/lr.divisor;

else LinearRegSlope = 0;

//

//

//

//

//

Intercept = (SumY - LinearRegSlope * lr.sumX) / lr.period ;

LinearRegValue = Intercept + LinearRegSlope * (lr.period-1);

return(LinearRegValue);

}

It is returning the linear regression value as a "direct" return, but it also changes the "passed by reference" LinearRegSlope so that it receives the exact value of the slope (slope is given as a bar-to-bar slope not as a "total" slope" - you have to multiply it with the period-1 to get the "total" slope) so maybe this one is what are you looking for. Will make a version with one additional parameter (the "price") and that way it will become independent of any other working buffer and will post it here when done

adeo:
mladen:

Question about 'past regression deviated - main with slope line'...

If I understand it correctly, one could calculate the slope by querying the slBuffer buffer at the [0] bar and the [LR.length] bar (as in, IndicatorSlope = (slbuffer[0]-slbuffer[LR.length-1])/LR.length-1)?

If so, would you recommend this calculation or an added buffer for use in automation?

If the buffer, would you please add a buffer to your 'past regression deviated - main with slope line' that makes the actual slope of the line available in a buffer? I think there is one left. If not, we could get by with only one pair of buffers for the SD. Or, maybe you feel it better reworked in the work[][] format.

Thanks a bunch.
 

...

Janusz

Angles on a time series can be calculated only as an approximation. Did you see this indicator :https://c.mql5.com/forextsd/forum/108/angle_of_average.mq4 from this post https://www.mql5.com/en/forum/general of the elite indicators thread?

Janusz123:
Dear Mladen/Mr Tools, As we know buying and selling currencies based on the direction they are moving is one of the most profitable ways of making money especially over the longer term. Is it then possible to design an indicator which would recognise the degree of the slope and colour it according to whether the currencies have risen or fallen or stayed in ranging periods? No matter how far and how long they have moved, thus to avoid staying overbought or oversold so typical for oscillators. Such an indicator should also have a multi timeframe functionality and can be used for manual trading. I would appreciate your work on that.
 

...

adeo

As promised, this is a "standalone" (no buffers allocated to it before the call to it) version for linear regression value and slope.

//-------------------------------------------------------

//

//-------------------------------------------------------

//

//

//

//

//

double lrPrices[][1];

double iLRValue(double tprice, double& LinearRegSlope, int lr.period, int i, int instanceNo=0)

{

if (ArrayRange(lrPrices,0)!=Bars) ArrayResize(lrPrices,Bars); i = Bars-i-1;

double LinearRegValue;

double Intercept;

double SumXY = 0;

double SumY = 0;

double lr.sumX = lr.period * (lr.period-1) / 2;

double lr.sumXSqr = lr.period * (lr.period-1) * (2 * lr.period - 1) / 6;

double lr.divisor = MathPow(lr.sumX,2) - lr.period * lr.sumXSqr;

lrPrices = tprice;

//

//

//

//

//

for (int k=0; k<lr.period; k++)

{

double price = lrPrices;

SumXY += k*price;

SumY += price;

}

if( lr.divisor != 0 )

LinearRegSlope = (lr.period * SumXY - lr.sumX * SumY)/lr.divisor;

else LinearRegSlope = 0;

//

//

//

//

//

Intercept = (SumY - LinearRegSlope * lr.sumX) / lr.period ;

LinearRegValue = Intercept + LinearRegSlope * (lr.period-1);

return(LinearRegValue);

}

[/PHP]

example of call would be like this

[PHP]double slope;

double value = iLRValue(Close,slope,ChannelPeriod,i);

after this call, both value and slope are assigned their according values. You can use any values instead of the Close (value of some other indicator, for example)

 

Regression slope

Thank you for considering and then solving. I'm sure I can work with the * lr period solution, but did you intend to include a new version of the indicator?

 

...

adeo

A new version of exactly which indicator?

adeo:
Thank you for considering and then solving. I'm sure I can work with the * lr period solution, but did you intend to include a new version of the indicator?
 

Clarification

mladen:
adeo A new version of exactly which indicator?

You said above, "As promised, this is a "standalone" (no buffers allocated to it before the call to it) version for linear regression value and slope."

I did not know if 'version' meant a new indicator or snippet to incorporate into existing indicator. I just wanted to know if you meant to attach anything to the last post as I did not see a file attachment. I haven't taken the time to understand the call, but will look through it and incorporate as able. Thanks.

 

...

Previous version of the function "assumed" that there is a buffer called "prices" and that it is filled in with values before you call it. This version takes care of arrays needed for calculation and is enough to call it the proposed way and it will calculate the needed. That is what I meant when I said the "standalone". It can simply be copied and used without a need to add any other code to the "basic" code. Also, if you wish to use multiple instances calculation, it is already ready for that and all that is needed to be changed is the second dimension of the lrPrices array to desired number of instances

Anyway, glad that it is sorted out. Sometimes I tell too much, an sometimes to little (like probably in the post where I posted the function )

regards

Mladen

adeo:
You said above, "As promised, this is a "standalone" (no buffers allocated to it before the call to it) version for linear regression value and slope." I did not know if 'version' meant a new indicator or snippet to incorporate into existing indicator. I just wanted to know if you meant to attach anything to the last post as I did not see a file attachment. I haven't taken the time to understand the call, but will look through it and incorporate as able. Thanks.
 

Impending Gold and Silver breakout

Hi guys.

Gold and Silver has formed the same and very interesting patterns on the weekly and monthly charts.

there will be a big move coming unless the patterns are busted....any clues to direction of breakout ...

Files:
gold.gif  21 kb
gold2.gif  19 kb
 

...

I am not trading those, but what I do know is that Soros is buying gold

Here is the quote from an article (with a link to the original article at the bottom of the quote) :

Legendary financier George Soros returned to buying gold in late 2011 after selling it earlier, and is due to reap the benefits later this year when Fed policies will likely weaken the dollar and send the precious metal climbing, Emerging Money reports.

In the first quarter of 2011, Soros Fund Management sold almost all its shares in the SPDR Gold Trust and the iShares Gold Trust exchange-traded funds, Bloomberg reports, citing SEC data.

Gold later fell in 2011 as the dollar resumed its safe-haven status on sentiment that the U.S. economy was set to improve and somewhat decouple itself from Europe's woes. So, if that can be a recommendation ...
petros244:
Hi guys.

Gold and Silver has formed the same and very interesting patterns on the weekly and monthly charts.

there will be a big move coming unless the patterns are busted....any clues to direction of breakout ...
 

gold/silver flag

info much appreciated,mladen

Reason: