[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [EquisMetaStock Group] How to convert from e-signal lenguage to metastock le



PureBytes Links

Trading Reference Links

The code you posted does not compute a linear regression in eSignal

The JavaScript (with eSignal mods) below does - you can easily see the
differences.  

This code compares favorably with the MetaStock built-in function

Reef-Break



/****************************************************************************************************
Title:  Offset Regression Oscillator
Author: Ed Hoopes
Date:   Sept 2004
Rev:    A
*****************************************************************************************************/
function preMain() {

    debugClear();
	setPriceStudy(true);
//	setColorPriceBars(true);
	setDefaultBarFgColor(Color.lime,0);
    setDefaultBarFgColor(Color.red,1);

	var fp1 = new FunctionParameter("Pers", FunctionParameter.NUMBER);
	fp1.setLowerLimit(4);
    fp1.setUpperLimit(50);
	fp1.setDefault(19);
	
}

//Global vars go here;

  var vATR        =  null;
  var vLastPt     =   0.0; //The value of the last point in the regr fit;
  var vPrevLastPt =   0.0; 

//End of Global vars;

function main(Pers) {

//Local vars go here;

  var nBarState = getBarState();
  var j         =  null;
  var k         =  null;
  var n         =  null;
  var x         =  null;
  var vSumX     =   0.0;
  var vSumX2    =   0.0;
  var vXSum2    =   0.0;
  var vOpen     =   0.0;
  var vHigh     =   0.0;
  var vLow      =   0.0;
  var vClose    =   0.0;
  var vOHLC     =   0.0;
  var vSumY     =   0.0;
  var vSumXY    =   0.0;
  var m         =   0.0; //The regression slope;
  var b         =   0.0; //The regression intercept;

  
 
//End of Local vars;

if (nBarState == BARSTATE_NEWBAR)  
    {
     vPrevLastPt = vLastPt;
    }

//The sums of X;

for ( x = 1; x <= Pers; x++) 
    {
    vSumX  = vSumX  + x;
    vXSum2 = vXSum2 + x*x;
    //debugPrintln( "x = " + x + " vSumX = " + vSumX + " vXSum2 = " +
vXSum2 );
    }

    vSumX2 = vSumX * vSumX;
    //debugPrintln(" vSumX2 = " + vSumX2);
    
//The sums of y & xy;

for ( x = 1; x <= Pers; x++)    
    {
     k        =   -1 * x;
     vOpen    =   open(k);
     vHigh    =   high(k);
     vLow     =    low(k);
     vClose   =  close(k);
     //debugPrintln( "x = " + k + " O = " + vOpen + " H = " + vHigh +
" L = " + vLow + " C = " + vClose); 
     
     vOHLC    = (vOpen+vHigh+vLow+vClose) / 4;
     vSumY    = vSumY + vOHLC; 
     vSumXY   = vSumXY + x * vOHLC;
     //debugPrintln("x = " + x + " vSumY = " + vSumY + " vOHLC = " +
vOHLC + " vSumXY = " + vSumXY );
     
    }

//Compute the slope m; 

    m = (Pers * vSumXY - vSumX * vSumY) / (Pers * vXSum2 - vSumX2);
    //debugPrintln("m = " + m );
    
//Compute the intercept b;

    b = (vSumY / Pers) - (m * vSumX / Pers);
    //debugPrintln("m = " + m + " b = " + b );

//Compute and return the last datapoint of the regression fit;

    vLastPt = m * (1.0) + b;
    //debugPrintln(" vLastPt = " + vLastPt );
       

    return new Array(vLastPt, vPrevLastPt);
    
}



--- In equismetastock@xxxxxxxxxxxxxxx, "giccanto" <giccanto@xxx> wrote:
>
> Thanks for that Lionel, I have already check it but they are 
> different..
> 
> 
> 
> --- In equismetastock@xxxxxxxxxxxxxxx, "Lionel Issen" <lissen@> 
> wrote:
> >
> > There is a linear regression line that comes with Metastock.  It 
> may be what
> > you need.
> > 
> >  
> > 
> > Lionel
> > 
> >  
> > 
> > From: equismetastock@xxxxxxxxxxxxxxx 
> [mailto:equismetastock@xxxxxxxxxxxxxxx]
> > On Behalf Of giccanto
> > Sent: Thursday, May 31, 2007 6:17 PM
> > To: equismetastock@xxxxxxxxxxxxxxx
> > Subject: [EquisMetaStock Group] How to convert from e-signal 
> lenguage to
> > metastock lenguage
> > 
> >  
> > 
> > Anyone can help and suggest how to convert formulas written in efs 
> (e-
> > signal lenguage) to metastock lenguage, for instance this Linear 
> > Regression Line. Thanks
> > 
> > 1 function preMain()
> > 2{
> > 3 setStudyTitle("Linear Regression Line");
> > 4 setCursorLabelName("LR", 0);
> > 5 setDefaultBarFgColor(Color.red, 0);
> > 6 setDefaultBarThickness(3, 0);
> > 7 setPriceStudy(true);
> > 8}
> > 9
> > 10function main(Length) {
> > 11 if(Length == null) Length = 5;
> > 12 var sum = 0;
> > 13 var i = 0;
> > 14 var mt = 0;
> > 15 var wt = 0;
> > 16 for(i = Length; i > 0; i--)
> > 17 sum += (i - (Length + 1) / 3) * close(i - Length);
> > 18 wt = 6 / (Length * (Length + 1)) * sum
> > 19 return wt;
> > 20}
> > 21
> > 22
> > 
> >  
> > 
> >  
> > 
> > No virus found in this incoming message.
> > Checked by AVG Free Edition.
> > Version: 7.5.472 / Virus Database: 269.8.5/826 - Release Date: 
> 5/31/2007
> > 4:51 PM
> > 
> > 
> > No virus found in this outgoing message.
> > Checked by AVG Free Edition. 
> > Version: 7.5.472 / Virus Database: 269.8.5/826 - Release Date: 
> 5/31/2007
> > 4:51 PM
> >  
> > 
> > 
> > [Non-text portions of this message have been removed]
> >
>




 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/equismetastock/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/equismetastock/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:equismetastock-digest@xxxxxxxxxxxxxxx 
    mailto:equismetastock-fullfeatured@xxxxxxxxxxxxxxx

<*> To unsubscribe from this group, send an email to:
    equismetastock-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/