# Help: Put study inside the script

#### Saylarr

##### Member
Hello, can someone help me?

I need to put this study that I designed into a script to use it in another study that I am designing, I have been trying but it cannot do it without breaking.

Here I leave the study code that I need in a script. I hope someone can help me

Code:
input aggregationPeriod = AggregationPeriod.DAY;
input tolerance = 0.05;

# Calcual maximo minimo y cierre del periodo anterior

def PH = high(period = aggregationPeriod)[1];
def PL = low(period = aggregationPeriod)[1];
def PC = close(period = aggregationPeriod)[1];

#ploteo de lineas de jackson soportes(S), Resistencias (R) Poc (pp) y maxima movimiento y minimo movimiento (hh y ll)

plot R3;
R3.HideTitle(); # Elimina Titulo
R3.HideBubble(); #Elimina Burbuja Lateral
plot R2;
R2.HideTitle();
R2.HideBubble();
plot R2M;
R2M.HideTitle();
R2M.HideBubble();
plot R1;
R1.HideTitle();
R1.HideBubble();
plot R1M;
R1M.HideTitle();
R1M.HideBubble();
plot HH;
HH.HideTitle();
HH.HideBubble();
plot PP;
PP.HideTitle();
PP.HideBubble();
plot LL;
LL.HideTitle();
LL.HideBubble();
plot S1M;
S1M.HideTitle();
S1M.HideBubble();
plot S1;
S1.HideTitle();
S1.HideBubble();
plot S2M;
S2M.HideTitle();
S2M.HideBubble();
plot S2;
S2.HideTitle();
S2.HideBubble();
plot S3;
S3.HideTitle();
S3.HideBubble();

# defino variables a usar, la logica es por ejemplo tolerancia resistencia 1 (TR1) o target resistencia 1 media (TR1M)

def DR;
def TR1;
def TR1M;
def TR2;
def TR2M;
def TS1;
def TS1M;
def TS2;
def TS2M;
def TPP1;
def TPP2;

HH = PH; #maximo periodo anterior
LL = PL; #minimo periodo anterior
PP = (PH + PL + PC) / 3; #calcula poc
DR = PH - PL; #calcula rango que sirve para calcular las zonas

# calcula las distintas resistencias y soportes
R1 = (0.5 * DR) + PP;
R1M = (0.618 * DR) + PP;

R2 = PP + DR;
R2M = PP + (1.382 * DR);

R3 = PP +  (2.618 * DR);

S1 = PP - (0.5 * DR);
S1M = PP - (0.618 * DR);

S2 = PP - DR;
S2M = PP - (1.382 * DR);

S3 = PP - (2.618 * DR);

# calculo las variables usano la tolerancia para la zona

TR1 =   R1M + ((R1M * tolerance) / 100) ;
TR1M =   R1 - ((R1 * tolerance) / 100) ;

TR2 = R2M + ((R2M * tolerance) / 100) ;
TR2M = R2 - ((R2 * tolerance) / 100) ;

TS1 = S1 + ((S1 * tolerance) / 100) ;
TS1M = S1M - ((S1M * tolerance) / 100) ;

TS2 = S2 + ((S2 * tolerance) / 100) ;
TS2M = S2M - ((S2M * tolerance) / 100) ;

TPP1 = PP + ((PP * tolerance) / 100) ;
TPP2 = PP - ((PP * tolerance) / 100);

# colores y dibujados de lineas

R3.SetDefaultColor(GetColor(5));
R2.SetDefaultColor(GetColor(5));
R2M.SetDefaultColor(GetColor(5));
R1.SetDefaultColor(GetColor(5));
R1M.SetDefaultColor(GetColor(5));
HH.SetDefaultColor(GetColor(4));
PP.SetDefaultColor(GetColor(0));
LL.SetDefaultColor(GetColor(1));
S1.SetDefaultColor(GetColor(6));
S1M.SetDefaultColor(GetColor(6));
S2.SetDefaultColor(GetColor(6));
S2M.SetDefaultColor(GetColor(6));
S3.SetDefaultColor(GetColor(6));

R3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R2M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
R1M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HH.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
PP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
LL.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S1M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S2M.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
S3.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

# dibujado de zonas o nubes con las tolerancias

R2M.SetStyle(Curve.SHORT_DASH);
R1M.SetStyle(Curve.SHORT_DASH);
HH.SetStyle(Curve.MEDIUM_DASH);
LL.SetStyle(Curve.MEDIUM_DASH);
S1M.SetStyle(Curve.SHORT_DASH);
S2M.SetStyle(Curve.SHORT_DASH);

R3.Hide();
HH.Hide();
LL.Hide();
S3.Hide();

##### Well-known member
VIP
@Saylarr Unfortunately, we cannot reference custom Studies or Strategies from within another Study/Strategy - only licensed studies... You must include the entire custom script within your new script... Some of the studies here have several complete studies or more in them...

#### Saylarr

##### Member
@Saylarr Unfortunately, we cannot reference custom Studies or Strategies from within another Study/Strategy - only licensed studies... You must include the entire custom script within your new script... Some of the studies here have several complete studies or more in them...

Yes I understand. Because first I tried to use the "reference" function for that and I realized what you are telling me. But I know that other codes can be done within the same study that make specific calculations and put them inside the "script" function to call them when they need it, the latter is what I want to do but I have not been able to do it without breaking it.

Sorry if it is not understood, I am using the translator because my English is bad.

Code:
script Example{
input x = 0;
input v = 0;
def LI44 = if GetValue(x, 1) then 1 else LI44[1] + 1;
plot one = GetValue(v, LI44);
plot two = GetValue(one, LI44);
}

Last edited:

##### Well-known member
VIP
Ok... So are you calling the script from within the code...??? Think of a script as a subroutine, function, procedure, whatever... It is a re-entrant piece of code - a script... We can use the default variable settings, even the inputs, or send them in the script call... Scripts are very under-used within Studies and Strategies, in my humble opinion...With them we could create libraries, shareable for future development...

#### Saylarr

##### Member
Ok... So are you calling the script from within the code...??? Think of a script as a subroutine, function, procedure, whatever... It is a re-entrant piece of code - a script... We can use the default variable settings, even the inputs, or send them in the script call... Scripts are very under-used within Studies and Strategies, in my humble opinion...With them we could create libraries, shareable for future development...

exactly what I want is to convert the code of that study that I put above into a "script". So that it is part of a larger study that I am doing, but I have problems doing it, it gives me failures especially with the plotting.