How can a PL command be dynamically created and submitted ?

Questions about MultiCharts and user contributed studies.
gillesc
Posts: 7
Joined: 16 Sep 2015
Has thanked: 5 times

How can a PL command be dynamically created and submitted ?

Postby gillesc » 16 Sep 2015

I would like to have the ability to dynamically create/format a PowerLanguage command, then execute it. This would allow me to make effective use of parameters and shorten the amount of code required.

For example, I currently use the following construct to plot a line and its associated Standard Error deviations (up to 4 bands):

Code: Select all

inputs:
Long_Deviation_Bands ( 3 ) ,
Long_Deviation_Bands_First ( 1 ) ,
Long_Deviation_Bands_Next ( 1 ) ;

variables:
v_Long_Linear_Reg_Current ( 0 ) ,
v_Long_Dev ( 0 ) ,
k ( 0 ) ,
x ( 0 ) ;

plot1( v_Long_Linear_Reg_Current, "Line 1 Method") ;
for k = 1 to Long_Deviation_Bands
begin
x = (Long_Deviation_Bands_First + (k - 1) * Long_Deviation_Bands_Next) * v_Long_Dev ;
switch (k)
begin
case 1 :
begin
plot2 (v_Long_Linear_Reg_Current + x) ;
plot3 (v_Long_Linear_Reg_Current - x)) ;
end ;
case 2 :
begin
plot4 (v_Long_Linear_Reg_Current + x) ;
plot5 (v_Long_Linear_Reg_Current - x) ;
end ;
case 3 :
begin
plot6 (v_Long_Linear_Reg_Current + x) ;
plot7 (v_Long_Linear_Reg_Current - x) ;
end ;
case 4 :
begin
plot8 (v_Long_Linear_Reg_Current + x) ;
plot9 (v_Long_Linear_Reg_Current - x) ;
end ;
end ;
end ;
I would like to have the ability to do something like this:

Code: Select all

inputs:
Long_Deviation_Bands ( 3 ) ,
Long_Deviation_Bands_First ( 1 ) ,
Long_Deviation_Bands_Next ( 1 ) ;

variables:
v_Long_Linear_Reg_Current ( 0 ) ,
v_Long_Dev ( 0 ) ,
Dynamic_Command ( "" ) ,
k ( 0 ) ,
x ( 0 ) ;

plot1( v_Long_Linear_Reg_Current, "Line 1 Method") ;
for k = 1 to Long_Deviation_Bands
begin
x = (Long_Deviation_Bands_First + (k - 1) * Long_Deviation_Bands_Next) * v_Long_Dev ;
Dynamic_Command = "plot" & NumtoStr(k*2,0) & "(v_Long_Linear_Reg_Current + x)" ;
SubmitDynCmd (Dynamic_Command);
Dynamic_Command = "plot" & NumtoStr(k*2+1,0) & "(v_Long_Linear_Reg_Current - x)" ;
SubmitDynCmd (Dynamic_Command);
end ;
Is anyone aware of any capabilities in PowerLanguage that would allow to do something similar to this?

If not, is there any appetite in the field for such a capability, in which case I would submit a feature request in the Project Management section ?

Thank You.

Erik Pepping
Posts: 74
Joined: 25 Aug 2007
Been thanked: 6 times

Re: How can a PL command be dynamically created and submitte

Postby Erik Pepping » 18 Sep 2015

Well you make a function. That will make your code a lot shorter.

Code: Select all

plot1( v_Long_Linear_Reg_Current, "Line 1 Method") ;
for k = 1 to Long_Deviation_Bands
begin
x = (Long_Deviation_Bands_First + (k - 1) * Long_Deviation_Bands_Next) * v_Long_Dev ;
myfunction(k,v_Long_Linear_Reg_Current ,x);
end ;


Return to “MultiCharts”