How to prevent indicator slowing down Marketscope

Moderator: admin

How to prevent indicator slowing down Marketscope

Postby MeiniOz » Mon Nov 22, 2010 5:23 pm

Hi all,

I am working on my first indicator and ran into the issue that things slow down to a grinding halt when I move the chart to the past with my indicator on. All I have to do is to move a week or two backwards in an hourly chart and things become unresponsive enough to be useless. It seems to be even worse when the market is busy and there are a lot of price updates.

There is no need to recalculate the entire date over and over again as it seems to do. I had a go at various things including the mode parameter in the Update function, but can't work out any way to elevate the problem.

I am stuck. Could anyone point me in the right direction please?

Meini
MeiniOz
FXCodeBase: Confirmed User
 
Posts: 34
Joined: Wed Nov 17, 2010 4:39 pm

Re: How to prevent indicator slowing down Marketscope

Postby Apprentice » Mon Nov 22, 2010 5:40 pm

Post your indicator.
In order to optimize it.
In Order To all learn something.
Although I must admit that I am not the best man for the optimization,
sometimes.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36495
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: How to prevent indicator slowing down Marketscope

Postby MeiniOz » Mon Nov 22, 2010 6:37 pm

Thanks for your reply.

I startet out using an existing indicator. So I went back to that one and realized it worked well. The structure is basically the same, but amongst standard stuff that should not have an impact on speed the key difference was this line of code that I had put into the Update function:

Code: Select all
core.host:execute("drawLine", lineId, bid:date(p), value, bid:date(p+2), value, color); lineId = lineId + 1;


A rather large number of short horizontal lines to mark levels. I commented the line and things worked fine.

Now the question is this: is there a better, faster way of drawing those lines or is there a way I can supress them when they are off screen?
MeiniOz
FXCodeBase: Confirmed User
 
Posts: 34
Joined: Wed Nov 17, 2010 4:39 pm

Re: How to prevent indicator slowing down Marketscope

Postby Timon55 » Tue Nov 23, 2010 1:41 am

Maybe this link http://www.lua.org/pil/17.1.html will be useful for you.

Memoize Functions

A common programming technique is to trade space for time. You can speed up some functions by memoizing their results so that, later, when you call the function with the same arguments, it can reuse the result.
Timon55
FXCodeBase: Confirmed User
 
Posts: 43
Joined: Thu Jul 15, 2010 5:35 am
Location: Omsk

Re: How to prevent indicator slowing down Marketscope

Postby Timon55 » Tue Nov 23, 2010 2:14 am

Or if you make some hard calculations in your indicator you can code it in C and use as additional LUA module.
Timon55
FXCodeBase: Confirmed User
 
Posts: 43
Joined: Thu Jul 15, 2010 5:35 am
Location: Omsk

Re: How to prevent indicator slowing down Marketscope

Postby uglock » Tue Nov 23, 2010 4:49 pm

MeiniOz wrote:
Code: Select all
core.host:execute("drawLine", lineId, bid:date(p), value, bid:date(p+2), value, color); lineId = lineId + 1;


A rather large number of short horizontal lines to mark levels. I commented the line and things worked fine.

Now the question is this: is there a better, faster way of drawing those lines or is there a way I can supress them when they are off screen?

And why you don't use regular output stream to draw the horizontal lines? Seems like it's a hard task for Marketscope to have a line each two candles.
uglock
FXCodeBase: Confirmed User
 
Posts: 13
Joined: Fri Feb 05, 2010 1:20 am

Re: How to prevent indicator slowing down Marketscope

Postby MeiniOz » Tue Nov 23, 2010 5:49 pm

Thanks Timon55 and uglock for your replies.

To answer your comment uglock: because I did not know any better. I searched the documentation for "line" and found this option. But it sounds logical what you are saying. I am still at the very beginning of getting the hang of writing indicators and frankly the lack of examples in the documentation does not make it easier. But I'll get there!

I guess I have to read up a bit more on output streams now. I'll come back if I can't work it out :) Thanks again for all your advice!
MeiniOz
FXCodeBase: Confirmed User
 
Posts: 34
Joined: Wed Nov 17, 2010 4:39 pm

Re: How to prevent indicator slowing down Marketscope

Postby MeiniOz » Tue Nov 23, 2010 7:10 pm

I just wanted to share this link to this well written indicator by Nikolay.Gekht http://fxcodebase.com/code/viewtopic.php?f=17&t=1974&p=3998&hilit=TRADESESSIONS#p3998. It is extremely useful for learning by example.

Thanks all :)
Meini
MeiniOz
FXCodeBase: Confirmed User
 
Posts: 34
Joined: Wed Nov 17, 2010 4:39 pm


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 56 guests