How to simplify a code recall a part of it  [SOLVED]

Questions about MultiCharts and user contributed studies.
gianluca71
Posts: 15
Joined: 22 Aug 2018
Has thanked: 2 times

How to simplify a code recall a part of it

Postby gianluca71 » 05 Oct 2018

Hi all,
I need a help to simplify a long code with many function. What I'd like to do is write the functions into a function list and recall it from the main code without create single function.
I explain with this example

Code: Select all

Original code:

var1 = funct1(abc, bcd, 1, point_c, point_d);
var2 = funct1(abc, bcd, -1, point_c, point_d);
//where abc, bcd, point_c, point_d are input and variables

New code:

var1 = funct(1);
var2 = funct(2);
//where funct(n) are functions recalled (similar to command switch/case)
I hope I explained myself.
Thanks a lot, regards

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

Re: How to simplify a code recall a part of it

Postby TJ » 05 Oct 2018

You are overthinking it.

Please make a REAL example.
Please use real variables . . . you will see your thought process better.

Let's use a popular function as an example -- MACD.

Let's use two different set of inputs
-- the regular MACD 12, 26, 9.
-- the FAST MACD 5, 13, 6.

Please walk us through what are your concerns.

gianluca71
Posts: 15
Joined: 22 Aug 2018
Has thanked: 2 times

Re: How to simplify a code recall a part of it

Postby gianluca71 » 06 Oct 2018

TJ, I make a real example a little bit different from previous one.
I'm using zigzag code block in some different indicators (zigzag code is the same for all). When I make a change the zigzag code I must change it on all the indicators codes.
What I'd like is make a single zigzag block and then recall when necessary, see the example below.
Thanks

Code: Select all

Inputs:
Price(Close),
RetracePnts(0.05);

Variables:
var0(0),
var1(Price),
var2(Date),
var3(Time),
var4(0),
var5(false),
var6(false),
var7(false),
var8(0),
Point_X(0),
Point_A(0),
Point_B(0),
Point_C(0),
Point_D(0);

//***********************ZigZag code block***********************
var0 = SwingHigh(1, Price, 1, 2) ;
if var0 <> -1 then begin
condition1 = var4 <= 0 and var0 >= var1 + RetracePnts ;
if condition1 then begin
var5 = true ;
var6 = true ;
var4 = 1 ;
end
else
begin
condition1 = var4 = 1 and var0 >= var1 ;
if condition1 then
begin
var5 = true ;
var7 = true ;
end;
end ;
end
else begin
var0 = SwingLow(1, Price, 1, 2) ;
if var0 <> -1 then begin
condition1 = var4 >= 0 and var0 <= var1 - RetracePnts ;
if condition1 then begin
var5 = true ;
var6 = true ;
var4 = -1 ;
end
else begin
condition1 = var4 = -1 and var0 <= var1 ;
if condition1 then
begin
var5 = true;
var7 = true ;
end ;
end;
end ;
end ;

if var5 then begin
var1 = var0 ;
var2 = Date[1] ;
var3 = Time[1] ;
var5 = false ;
end ;

if var6 then begin
var8 = TL_New(var2, var3, var1, var2[1], var3[1], var1[1]) ;
TL_SetSize(var8, 1) ;
TL_SetColor(var8, yellow) ;
//******************ZigZag XABCD points******************
Point_X = Point_A;
Point_A = Point_B;
Point_B = Point_C;
Point_C = var1[1];
var6 = false ;
end
else if var7 then begin
TL_SetEnd(var8, var2, var3, var1) ;
var7 = false ;
end ;

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

Re: How to simplify a code recall a part of it

Postby TJ » 06 Oct 2018

For what you described, it can be done.

For the zig zag code, you have to rewrite some of the parts. It will take some time and effort.

gianluca71
Posts: 15
Joined: 22 Aug 2018
Has thanked: 2 times

Re: How to simplify a code recall a part of it  [SOLVED]

Postby gianluca71 » 06 Oct 2018

Just done it, effectively it was long and a little difficoult.
My problem is that I know little EL and some passes needed time and help.
Anyway many thanks TJ for support.
Regards


Return to “MultiCharts”