code replacement

Questions about MultiCharts and user contributed studies.
User avatar
siscop
Posts: 197
Joined: 09 Jan 2011
Has thanked: 34 times
Been thanked: 29 times

code replacement

Postby siscop » 20 Jan 2011

Is there a way to sum code together that comes up every time? Something like:

Code: Select all

#xxxpla:
begin
Print(“ this is good”);
Print(“this is bad”);
Buy this bar on close;
var0=var0+1;
End;
And everytime I use the key “xxxpla” the code from begin to end will replace that. something like define or replacement.
So I can write

Code: Select all

If condition0 then
xxxpla;
xxxpla will be replaced from PL automaticaly. Is something like that possible?
It would be easy to build up his own personal library this way.

How do u build your personal library? This copy-paste thing bugs me. Can somebody give me an example/frame how u build your library efficiently? I didnt have any problems with other languages but PL is "different".

User avatar
TJ
Posts: 7742
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2222 times

Re: code replacement

Postby TJ » 20 Jan 2011

Is there a way to sum code together that comes up every time? Something like:

Code: Select all

#xxxpla:
begin
Print(“ this is good”);
Print(“this is bad”);
Buy this bar on close;
var0=var0+1;
End;
And everytime I use the key “xxxpla” the code from begin to end will replace that. something like define or replacement.
So I can write

Code: Select all

If condition0 then
xxxpla;
xxxpla will be replaced from PL automaticaly. Is something like that possible?
It would be easy to build up his own personal library this way.

How do u build your personal library? This copy-paste thing bugs me. Can somebody give me an example/frame how u build your library efficiently? I didnt have any problems with other languages but PL is "different".
You can create FUNCTIONs to off load some of the duplicate or often used code segments. I am not sure if you can do buy/sell though.

User avatar
Dave Masalov
Posts: 1712
Joined: 16 Apr 2010
Has thanked: 51 times
Been thanked: 489 times

Re: code replacement

Postby Dave Masalov » 21 Jan 2011

Dear siscop,

Such substitutions are not possible in PL scripts. The only thing I can suggest is to use functions. You can write your own custom dll library and pass a part of your calculations there.

User avatar
siscop
Posts: 197
Joined: 09 Jan 2011
Has thanked: 34 times
Been thanked: 29 times

Re: code replacement

Postby siscop » 21 Jan 2011

ok Thank you for the answer.
I already placed everything I could in those functions but using them in a indicator or on a signal I always have to copy and paste additional code into it. I just thought I could make this job a little easier since I always (try to) use the same variablenames on every signal/indicator.

This way I would only work on the functions and have the signal/indicator in notime.


Return to “MultiCharts”