Please help with this code for linear regression

 

Hi all, again and sorry for misunderstanding:

take a look to this indicator and you definitely figure what i meant with ("problem is that i have to wait to next day to draw if i put it on chart today")

if you put it on live chart you will not see any thing (and that is the problem) so test it on strategy tester on H1 time frame and here is the code which responsible for the drawing procedure of these trend lines:

int linear( int ax, color LR.c, color c.3, int style)
{
   LR.length = ax;
   int start.bar=LR.length, end.bar=0;
   int n=start.bar-end.bar+1;
//---- calculate price values
   double value=iClose(Symbol(),period,end.bar);
   double a,b,c;
   double sumy=value;
   double sumx=0.0;
   double sumxy=0.0;
   double sumx2=0.0;
   for(int i=1; i<n; i++)
     {
      value=iClose(Symbol(),period,end.bar+i);
      sumy+=value;
      sumxy+=value*i;
      sumx+=i;
      sumx2+=i*i;
     }
   c=sumx2*n-sumx*sumx;
   if(c==0.0) return;
   b=(sumxy*n-sumx*sumy)/c;
   a=(sumy-sumx*b)/n;
   double LR.price.2=a;
   double LR.price.1=a+b*n;
 
//---- maximal deviation calculation (not used)
   double max.dev=0;
   double deviation=0;
   double dvalue=a;
   for(i=0; i<n; i++)
   {
      value=iClose(Symbol(),period,end.bar+i);
      dvalue+=b;
      deviation=MathAbs(value-dvalue);
      if(max.dev<=deviation) max.dev=deviation;
   }
   //Linear regression trendline
              
               
    if (TimeHour(Time[0]) == 0)
    {
      for(int i2=1;i2<50;i2++)
      {
         if(TimeHour(Time[i2])==23)
         {  
               datetime aaa=iTime(Symbol(),period,start.bar);
               ObjectDelete(LR.length+"00");
               ObjectDelete(LR.length+"+01");
               ObjectDelete(LR.length+"-01");
               
               
               ObjectCreate(LR.length+"00",OBJ_TREND,0,aaa,LR.price.1,Time[end.bar],LR.price.2);
               ObjectSet(LR.length+"00",OBJPROP_COLOR,LR.c);
               ObjectSet(LR.length+"00",OBJPROP_WIDTH,line.width);
               ObjectSet(LR.length+"00",OBJPROP_RAY,true); 
               ObjectSet(LR.length+"00",OBJPROP_STYLE,style);
               
               ArrayInitialize(candle_dev,0.0);
               double x=0;
               for(i=0; i<LR.length-1; i++)
               {
                  double curHigh2=MathAbs(iClose(Symbol(),period,i)-ObjectGetValueByShift(LR.length+"00",i));
                  candle_dev[i]=curHigh2;
               }
               for(i=0; i<LR.length-1; i++)
               {
                  if(candle_dev[i]>x) {x=candle_dev[i];}
               }
               ObjectCreate(LR.length+"+01",OBJ_TREND,0,aaa,LR.price.1+x,
                                             Time[end.bar],LR.price.2+x);
               ObjectSet(LR.length+"+01" ,OBJPROP_COLOR,c.3);
               ObjectSet(LR.length+"+01" ,OBJPROP_WIDTH,line.width);
               ObjectSet(LR.length+"+01" ,OBJPROP_RAY,true);
               ObjectSet(LR.length+"+01",OBJPROP_STYLE,style);
   
               ObjectCreate(LR.length+"-01",OBJ_TREND,0,aaa,LR.price.1-x,
                                             Time[end.bar],LR.price.2-x);
               ObjectSet(LR.length+"-01",OBJPROP_COLOR,c.3);
               ObjectSet(LR.length+"-01",OBJPROP_WIDTH,line.width);
               ObjectSet(LR.length+"-01",OBJPROP_RAY,true);
               ObjectSet(LR.length+"-01",OBJPROP_STYLE,style);
        }
     
     }
     
   }
   
return(0);

}

and many thanks in advance

 
turkm:
WoOoW no reply, amazing.
Not really . . . I looked at your post and didn't understand what you mean by " problem is that i have to wait to next day to draw if i put it on chart today " I don't currently have time to trawl through your code to understand what your issue is and I can't easily compile and run it . . .
 
turkm:

i removed the topic, cuz there is no one could answer.

You need a little more patience . . . not everyone is on here 24/7
 
RaptorUK:
You need a little more patience . . . not everyone is on here 24/7

I was thinking about looking at the code. I said thinking about ... coz it was weekend (we need a holiday and tick won't come on holiday - its on holiday too) + the code require some thinking.

Some user here get reply after 2- 3 or weeks later. So be patient, not everyone here knows the answer and have time to answer.

RaptorUK:
Not really . . . I looked at your post and didn't understand what you mean by " problem is that i have to wait to next day to draw if i put it on chart today " I don't currently have time to trawl through your code to understand what your issue is and I can't easily compile and run it . . .

Do you think it's some bar ahead to the future and not using a ray on trendline.


 
onewithzachy:

I was thinking about looking at the code. I said thinking about ... coz it was weekend (we need a holiday and tick won't come on holiday - its on holiday too) + the code require some thinking.

Some user here get reply after 2- 3 or weeks later. So be patient, not everyone here knows the answer and have time to answer.

Do you think it's some bar ahead to the future and not using a ray on trendline.


I had a quick look, I didn't really understand the point I highlighted in bold and no further explanation was given. I think it maybe that the line wasn't drawn until 23:00 . . . but I may be mis-remembering . .
 
turkm:

Hi all, again and sorry for misunderstanding:

take a look to this indicator and you definitely figure what i meant with ("problem is that i have to wait to next day to draw if i put it on chart today")

if you put it on live chart you will not see any thing (and that is the problem) so test it on strategy tester on H1 time frame and here is the code which responsible for the drawing procedure of these trend lines:

and many thanks in advance

Sorry, I'm not going to run pre-compiled code on my test systems, I have no idea what it does . . . if you want to post the complete source code so I can compile it myself I will.

I suspect this is your problem . . .

if (TimeHour(Time[0]) == 0)
    {

the objects are only drawn at midnight . . . try this change:

if (TimeHour(Time[0]) == 0 || ObjectFind(LR.length+"00") == -1 || ObjectFind(LR.length+"+01") == -1 || ObjectFind(LR.length+"-01") == -1)
    {

so that the Objects will be drawn at any time if they currently do not exist.

 
RaptorUK:

Sorry, I'm not going to run pre-compiled code on my test systems, I have no idea what it does . . . if you want to post the complete source code so I can compile it myself I will.

I suspect this is your problem . . .

the objects are only drawn at midnight . . . try this change:

so that the Objects will be drawn at any time if they currently do not exist.


it works so nice, many many many thanks

but there is a problem which is:

its start drawing right a way from the current candle and this is wrong, what i want when i drop the indicator it has to look for the 00:00 hour of this day and start drawing back to 24 hour, (in tow words):

when i drop the indicator it has to draw the linear regression for the past 24 hours

 
turkm:


it works so nice, many many many thanks

but there is a problem which is:

its start drawing right a way from the current candle and this is wrong, what i want when i drop the indicator it has to look for the 00:00 hour of this day and start drawing back to 24 hour, (in tow words):

when i drop the indicator it has to draw the linear regression for the past 24 hours

So fix it . . . what is the problem ? you still haven't posted the whole code.
 
RaptorUK:
So fix it . . . what is the problem ? you still haven't posted the whole code.

Sorry for any disturbing, i will try by my self, and thanks for your efforts.
 

Raptor sounds like the only one that could code exactly what i have as system . i am impress with the kind of help u gave to turkm.


i kindly need help to code my system into an EA. it uses the linear regression channel, rsi and triangle by line tools.

i want mr raptor to help me do this, i think i have confidence in him, .

i have read many of his comment from other places online.

i dont know if it will be right for me to drop the system write up here for the coding.