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

Re: Looking for some suggestions, to make this code run better??



PureBytes Links

Trading Reference Links

You do the first part (setting THDate and THTime) only on the first bar. I assume that's what you want.

However you do the rest of it -- including drawing all those trendlines -- on ALL bars. Unless I'm mistaken, you're drawing the trendlines many many times. No wonder it's slow!

Try putting "if LastBarOnChart then begin ... end;" around all the trendline code, so the trendlines are only drawn once.

I don't know why you think you need the arrays, especially since you don't seem to be referencing the individual values at all. But I suspect you don't want to be overwriting THTLRef[counter] with every trendline operation. I don't have my TS references available and it's been much too long since I did anything with trendlines, but I think you probably want to do something like:

THTLRef = TL_New(THDate[0], THTime[0], THVal, LastCalcDate, THTime[0], THVal);
   Junk = TL_SetColor(THTLRef, 15);
   Junk = TL_SetStyle(THTLRef, 2);
   etc

That way you get a new THTLref when you create a new trendline, and you pass that THTLref into the rest of the TL operations to set the color, style, etc on the new trendline. The THTLref value refers to the trendline you just created and tells the TL_SetColor &etc functions what TL they're supposed to modify. Your code was overwriting THTLref with each TL_SetColor &etc call so you didn't have the TL reference any more. (I don't remember what TL_SetColor &etc return but I don't think they return the TL ref value.)

BTW the "else if" is unnecessary here:

   if counter = 1 then begin {start from the top }
   ...
end else begin if counter > 1 then begin
If you just say:

   if counter = 1 then begin {start from the top }
   ...
end else begin

...then the first part executes when counter = 1, and the else part executes in all other cases -- which is when counter > 1.

Gary



-------- Original Message  --------
Subject: Re: Looking for some suggestions, to make this code run better??
From: Rene Muench <muenchr@xxxxxxxxxxxxxx>
To: 'Omega-List' <omega-list@xxxxxxxxxx>
Date: 7/14/2009 10:52 PM
Hi Everyone,

I noticed a error transferring the code to email;

for counter = 1 to (Max - Min) + 1 begin
 should

for counter = 1 to ((max-min)/lenth) + 1 begin in this case it is 27.

Sorry

Cheers Rene'

-----Original Message-----
From: Rene Muench [mailto:muenchr@xxxxxxxxxxxxxx] Sent: Wednesday, July 15, 2009 2:06 PM
To: 'Omega-List'
Subject: Looking for some suggestions, to make this code run better??

Hi Everyone,

The code below runs OK, but is very slow. I don't know how to determine the cause of its slow running and wonder if
anyone of you guys could shade some in sides on how to make it run faster?

I am attempting to remove TS charts background grid and relace it with
trendlines as outlined in the code.
Please don't ask why I assigned certain values to the arrays. I couldn't get
the code to work until I assign these values, whether that makes sense or
not is a different question.

Thanks in advance
Kind Regards,

Rene' __________________________________________________________________
{Horizontal Trendlines by 7 points as of start of the chart and based on
close}
{sval = Starting amount, THVal = trendline Value}
{THDate Horizontal trendline date, THTime = Horizontal trendline time,
THTLRef = Horizontal trendline reference point}
Inputs:length(7),Min(308.00),Max(490.00);
vars: counter(0),sVal(0),THVal(0);
Arrays: THDate[10](0), THTime[10](0), THTLRef[32](100);


if currentbar = 1 then begin

THDate[0] = Date[0];
THTime[0] = Time[0];

end;

for counter = 1 to (Max - Min) + 1 begin
if counter = 1 then begin {start from the top }

   	sVal = Max;             {Stet the first horizontal trendline}

	THVal= sVal;
	THTLRef[counter] = TL_New(THDate[0], THTime[0], THVal, LastCalcDate
, THTime[0], THVal);
	THTLRef[counter] = TL_SetColor(THTLRef[counter], 15);
	THTLRef[counter] = TL_SetStyle(THTLRef[counter], 2);
	THTLRef[counter] = TL_SetExtRight(THTLRef[counter], true);	
    end	
else begin if counter > 1 then begin
	sVal = sval - length;
THVal= sVal; THTLRef[counter] = TL_New(THDate[0], THTime[0], THVal, LastCalcDate
, THTime[0], THVal);
	THTLRef[counter] = TL_SetColor(THTLRef[counter], 15);
	THTLRef[counter] = TL_SetStyle(THTLRef[counter], 2);
	THTLRef[counter] = TL_SetExtRight(THTLRef[counter], true);
	

end;	
end;
end; {end of code}