Enter Parameters

Hi,

I am trying to write a script for an indicator but have some problems in doing so. I want therefore ask you for some assistance.

As you can see from the screen shot "test script #1.png" all seems to be right. BUT I want change the numbers "21" and "17" with changeable parameters so that I can change the values latter on as I want.

But when I change "21" with "BARS=21" I get an error message (see screen shot "test script #2.png".

With the code "var1 / var2" I have also a problem. Since I have to use the division result of "var1 / var2" later on in the formula I have tried to write it as "Part1 = var1 / var2" so that I had only use "Part1" as a reference later on in the formula but this approach resulted also in an error message (see screen shot "test script #3.png").

Writing the formula in one line as "var1" resulted also in an error message (see screen shot "test script #4.png").

I hope it is possible for you to give me some advise how can I solve this issue.

Thanks a lot,
Thomas

test-script-1.png

test-script-2.png

test-script-3.png

test-script-4.png

Hi Thomas,

Can you please copy and paste the script(s) you are using into the thread directly, rather than using a screen image. This makes sure we’re working with the identical script you are when reviewing it on our own systems here.

Hi Thomas,

Q1: Changing parameters within a Script (test script #1.png): As far as I'm aware there is no way to change parameters within Scripts when the script is being run or displayed, ie as an external user input once applied to a chart. Any change in values must be made within the Script before execution.

Q2: Test Script #2.png: "Bars=21" is not correct syntactically. The divisor must be a number or a defined variable. You can amend the script to read:

// Test Script #3

BARS=21;

var1 = 1-(SIN((2*3.14159) / BARS));

var2 = COS((2*3.14159)/17);

var1/var2

//EXP(((1.414*-1)*3.14159)/17)

var3=EXP(((1.414*9-1))/17);

20190204 Test Script #2

Q3: Test Script #3.png: The are 2 syntactical issues with this script:

  • The line Part1 should end with a ";" and "Part1", the result, should appear on a new line
  • It is recommended as good practice that the output of a Script, in this case "Par1", be the last code line of the Script

so the code becomes:

// Test Script #3

BARS=21;

var1 = 1-(SIN((2*3.14159) / BARS));

var2 = COS((2*3.14159)/17);

Part1 = var1/var2;

//EXP(((1.414*-1)*3.14159)/17)

var3=EXP(((1.414*9-1))/17);

Part1

20190204 Test Script #3

Note also that all code lines (except comments) must end with a ";", except the script's final result line.

Q4: Test Script #3.png: The Script does not has a result line, ie all code lines end with ";". The Script result line does not have a ";", so the Script becomes:

// Test Script #4

BARS=21;

var1 = 1-(SIN((2*3.14159) / BARS)) / COS((2*3.14159)/17);

//EXP(((1.414*-1)*3.14159)/17)

var3=EXP(((1.414*9-1))/17);

var1

20190204 Test Script #4

Also, to make it easier for those reviewing and commenting, might I suggest you insert the screenshots in the body of the post so they can be seen in context, along with the code so it can be copied, so commentators don't have to retype your code to test it.

 

Cheer

Trevor

Auld Tyma Data Logo with URL 1 cm

Hi all,

thank you very much for your help, especially Trevor. As requested I now copy the script into the mail. I was not familiar with that procedure, sorry.

I am trying to write a script for an indicator but have some problems in doing so. I want therefore ask you for some assistance.

As you can see from the screen shot “test script #1.png” all seems to be right. BUT I want change the numbers “21” and “17” with changeable parameters so that I can change the values latter on as I want.

//test script #1

// (1 - (SIN((2*3.14159) / 21))) / COS((2*3.14159) / 21)

var1 = 1-(SIN((2*3.14159) / 21));
var2 = COS((2*3.14159) / 21);
var1 / var2

//EXP(((1.414*-1)*3.14159)/17)
var3 = EXP(((1.414*9-1)) / 17);

But when I change “21” with “BARS=21” I get an error message (see screen shot “test script #2.png”.

//test script #2

// (1 - (SIN((2*3.14159) / 21))) / COS((2*3.14159) / 21)

var1 = 1-(SIN((2*3.14159) / BARS=21));
var2 = COS((2*3.14159) / 21);
var1 / var2

//EXP(((1.414*-1)*3.14159)/17)
var3 = EXP(((1.414*9-1)) / 17);

 

With the code “var1 / var2” I have also a problem. Since I have to use the division result of “var1 / var2” later on in the formula I have tried to write it as “Part1 = var1 / var2” so that I had only use “Part1” as a reference later on in the formula but this approach resulted also in an error message (see screen shot “test script #3.png”).

//test script #3

// (1 - (SIN((2*3.14159) / 21))) / COS((2*3.14159) / 21)

var1 = 1-(SIN((2*3.14159) / 21));
var2 = COS((2*3.14159) / 21);
Part1 = var1 / var2

//EXP(((1.414*-1)*3.14159)/17)
var3 = EXP(((1.414*9-1)) / 17);

Writing the formula in one line as “var1” resulted also in an error message (see screen shot “test script #4.png”).

//test script #4

// (1 - (SIN((2*3.14159) / 21))) / COS((2*3.14159) / 21)

var1 = (1-(SIN((2*3.14159) / 21))) / COS((2*3.14159) / 21);

//EXP(((1.414*-1)*3.14159)/17)
var3 = EXP(((1.414*9-1)) / 17);

 

I hope it is possible for you to give me some advise how can I solve this issue.

Thanks a lot,
Thomas

Hi Thomas,

 

I addressed each of the issues you raised in my response above.

Cheers

 

Trevor

Hi Trevor,

I think I need again your help. I have now developed the script further and am encounter again a problem.

Here is my current version:

BARS1=21;

BARS2=17;

var1 = (1-(SIN((2*3.14159) / BARS1))) / (COS((2*3.14159) / BARS1));

var2 = (0.5 * (1 + var1) * (Close() - Close(1))) + (var1 * var2(1));

var3 = EXP(((1.414*9-1)) / BARS2);

var4 = 2 * var3 * (COS((1.414 * 3.14259) / BARS2));

var5 = (var3 * -1) * var3;

var6 = 1 - var4 - var5;

var7 = (var6 * ((var2 + var2(1)) / 2)) + (var4 * var7(1)) + (var5 * var7(2));

var7

 

Until var7 all has worked fine but var7 resulted an error message.

Let me explain what var7 should do:

Add today's value of var2 to yesterday's value of var2, divided this by 2 and multiply the product with var6

Plus the result of today's value of var4 times yesterday's value of var7

Plus the result of today's value of var5 times the day before yesterday's value of var7

 

It seems that yesterday's values and the day before yesterday's value causing the problems.

I have an Excel file with the formulas and try to script the code in Opatuma. This Excel calculations are working fine.

In the program "TradeStation" the code looks like this:

Inputs:

Duration(40);

Vars:

alpha1(0),

HP(0),

a1(0),

b1(0),

c1(0),

c2(0),

c3(0),

Filt(0),

count(0),

Wave(0),

Pwr(0);

alpha1 = (1 - Sine (360 / Duration)) / Cosine(360 / Duration);

HP = .5*(1 + alpha1)*(Close - Close[1]) + alpha1*HP[1];

a1 = expvalue(-1.414*3.14159 / 10);

b1 = 2*a1*Cosine(1.414*180 / 10);

c2 = b1;

c3 = -a1*a1;

c1 = 1 - c2 - c3;

Filt = c1*(HP + HP[1]) / 2 + c2*Filt[1] + c3*Filt[2];

Wave = (Filt + Filt[1] + Filt[2]) / 3;

Pwr = (Filt*Filt + Filt[1]*Filt[1] + Filt[2]*Filt[2]) / 3;

Wave = Wave / SquareRoot(Pwr);

Plot1(Wave);

 

I am currently at "stage" - Filt = c1*(HP + HP[1]) / 2 + c2*Filt[1] + c3*Filt[2];

Perhaps this helps.

Thanks again

Thomas

 

Hi Thomas,

The first issue I find with your Script is in the var2, because when I reduce your script to:

// Test script #5

BARS1=21;

BARS2=17;

var1 = (1-(SIN((2*3.14159) / BARS1))) / (COS((2*3.14159) / BARS1));

var2 = (0.5 * (1 + var1) * (Close(0) – Close(1)))+ (var1 * var2(1));

var2

I get the following:

20190205 Test Script #5

This shows that var2 is not working, because, I believe, it is calling itself with your required OFFSET of 1, by the variable var2(1). By the way, if you are wanting an OFFSET from a variable you need to use square brackets "[]", which would mean that line would read:

var2 = (0.5 * (1 + var1) * (Close(0) – Close(1)))+ (var1 * var2[1]);

but that too, will show a scripting error as var2 is calling itself.

You will run into the same issue with var7, as it too is calling itself a couple of times within the variable calculation.

You will need to rearrange your formulae so that there is no recursive calling of variables.

Cheers

Trevor

Auld Tyma Data Logo with URL 1 cm

 

 

Hi,

a question to all Optuma Script experts.

Trevor suggested me I should rearrange my script because some variables are calling itself.

My question now is: "Is there at all a possibility in Optuma to rearrange my script in a way that it works or is it simply impossible?"

If it is possible please give me some hints how I can do it.

Many thanks,

Thomas

Hi,

I have once again a question concerning the scripting of my indicator.

Is there a possibility to use the Pascal Programming module to create a custom tool of my above mentioned indicator?

Thanks,

Thomas

Hi Thomas

I did a quick test on your script that involves recursive variables by using the square brackets var7[1], var7[2] and var2[1] instead of var7(1) etc.

Here is the script that shows valid results. Please let us know how they compare to the Excel data.

BARS1=21;
BARS2=17;
var1 = (1-(SIN((2*3.14159) / BARS1))) / (COS((2*3.14159) / BARS1));

var2  =  (0.5 * (1 + var1) * (Close() - Close(1))) + (var1 * var2[1]);

var3 = EXP(((1.414*9-1)) / BARS2);

var4 = 2 * var3 * (COS((1.414 * 3.14259) / BARS2));

var5 = (var3 * -1) * var3;  

var6 =  1 - var4 - var5;   

var7 = (var6 * ((var2 + var2[1]) / 2)) + (var4 * var7[1]) + (var5 * var7[2]); 

var7

Optuma scripting is already able to handle simple recursive variable.

var1 = var1[1] + 1;
var1

If you put the above script in Show View, you can see a plot increased by 1 at a time.

Hope it makes sense to you.

Henry

Hi Henry,

many thanks for your time and efforts to look over my script. Unfortunately, it does not work.

Until var6 all calculations are correct.

But var7 has an error, although the script is correct written.

var7 = (var6 * ((var2 + var2[1]) / 2)) + (var4 * var7[1]) + (var5 * var7[2]);

Even if I use a “shortened” var7 with NO recursives, the result is wrong.

My “shortened” var7 is:

BARS1=21;
BARS2=17;
var1 = (1-(SIN((23.14159) / BARS1))) / (COS((23.14159) / BARS1));
var2 = (0.5 * (1 + var1) * (Close() - Close(1) )) + (var1 * var2[1]);
var3 = EXP(((1.414*-1) *3.14159) / BARS2);
var4 = 2 * var3 * (COS((1.414 * 3.14259) / BARS2));
var5 = (var3 * -1) * var3;
var6 = 1 - var4 - var5;
var7 = (var6 * ((var2) / 2));
var7

It seems that referring to var2 that already contains a recursive is the problem.

This is surprising since the code of var2 is correct and the result is right.

BARS1=21;
BARS2=17;
var1 = (1-(SIN((23.14159) / BARS1))) / (COS((23.14159) / BARS1));
var2 = (0.5 * (1 + var1) * (Close() - Close(1) )) + (var1 * var2[1]);
var2

The result of var2 is correct, it is 9.758


Another try for testing what causes the problem:

BARS1=21;
BARS2=17;
var1 = (1-(SIN((23.14159) / BARS1))) / (COS((23.14159) / BARS1));
var2 = (0.5 * (1 + var1) * (Close() - Close(1) )) + (var1 * var2[1]);
var3 = EXP(((1.414*-1) *3.14159) / BARS2);
var4 = 2 * var3 * (COS((1.414 * 3.14259) / BARS2));
var5 = (var3 * -1) * var3;
var6 = 1 - var4 - var5;
var7 = (var6 * ((var1) / 2));
var7

As you can see I have replaced in var7 the var2 with var1. Var1 contains NO recursive.

The result is correct, it produces as a result 0.039.

This confirms my assumption, that the problem is that var7 refers to var2 that contains already a recursive.

If you should have any ideas about this issue I would be really very happy.

But nevertheless many thanks for your efforts.

Thanks

Thomas

 

Hi Thomas,

I will need to do some more testing on this.

This confirms my assumption, that the problem is that var7 refers to var2 that contains already a recursive var7 = (var6 * ((var2) / 2));

As you point out here, I need to check with you about the expected result of var7.

var2 = (0.5 * (1 + var1) * (Close() – Close(1) )) + (var1 * var2[1]); 

When calculating var7, are you expecting the var2 to have the final result on the last bar of the chart or have the immediate result on the current bar (assume the entire script calculations are on going).

Were you perhaps expecting the immediate result of var2 and apply it on var7 when calculating var7 one bar at a time ?

Henry

Hi Henry,

thanks a lot for your help.

To answer your questions I have decided to open a support ticket with the ticket number #644007.

In this ticket I have included some files that should help you best to see how I use the calculations in Excel and Optuma.

I hope this was a good idea from me, if not please let me know.

Thanks

Thomas