Optuma Forums › Optuma Scripting › Increase Script Speed
- This topic has 4 replies, 3 voices, and was last updated 14 hours, 59 minutes ago by
Mathew.
-
AuthorPosts
-
December 11, 2020 at 11:27 am #61667
Michael
- Topics: 4
- Replies: 1
- Posts: 5
Hi, I am working on my first major script and have run into an issue. Part of the code is causing the script to either go very slow or crashes Optuma. So I assume I am doing something wrong and hope you can help. When I add the condition (EC == 0) in the code it makes the system slow or crashes. Can you check if I am doing something wrong? I bolded the section of the code that has (EC == 0) which is at the bottom of the below script.
I am using the code in a watch list of about 100 codes. Although I have not built out the entire code yet, the end goal is to track the count of distribution days and turn buy switch on and off. Thank you!
// Percentage change vs. prior day- Value
PC= (CLOSE()-Close(OFFSET=1))/Close(OFFSET=1); // Higher volume than prior day- True or False
HVol = VOL() > VOL(OFFSET=1);// Percent Change over 1% for Follow Through FT. True or False
PCOver1% = PC > .01;// Higher close by 1% than prior day on higher volume
PCFT = PCOver1% and HVol; // True false// Populate variables- Down the road I will create code to populate these three variables
DailyDistD = 2;
S1= 3;
S2 = 0;// Exposure Count- (the higher the count the more risk in market)
ECDaily = DailyDistD + PCFT; // Exposure count current day
EC = ECDaily + (Offset(EC, OFFSET=1)); // Exposure count total// Turn Buy Switch On Off (if buy switch off bring exposure to zero)
// HAVING EC IN THE BUYSWITCH CODE SLOWS DOWN CODE OR CRASHES SYSTEM
BSDailyOff = (S1> 5) or (S2 == 0) or (EC == 0));
BSDailyOn = (PCFT == 1); // True or 1 if Higher close by 1% than prior day on higher volume
BS = If(BSDailyOff ==1, 0, If(BSDailyOn ==1, 1, OFFSET(BS, OFFSET=1))); // Buy switch off if dailyoff is positive 1 ELSE BS on if daily is positive ELSE use prior BS
EC;December 11, 2020 at 11:38 am #61668Matthew
- Topics: 5
- Replies: 326
- Posts: 331
Hi,
You have too many close brackets on that line, the way it’s setup now it does not register as a valid script. Once it was adjusted to:
123BSDailyOff = (S1> 5) or (S2 == 0) or (EC == 0);The rest of the script worked.
I applied it to the S&P100 codes in a Watchlist, trying different outputs (EC, BS, etc) and it worked without crashing once the change was made.
1 user thanked author for this post.
December 12, 2020 at 3:07 am #61671Michael
- Topics: 4
- Replies: 1
- Posts: 5
Thank you Matthew,
Yes the version I sent you had the bracket issue, thanks for identifying that. I actually fixed that before I submitted the question on how to increase the speed but I sent the wrong version of code without the bracket fix. So, I still have the issue with speed of the code and hope someone can let me know if I should restructure the code. The code runs at an ok speed when I remove the Variable EC from the script BSDailyOff = (S1> 5) or (S2 == 0) or (EC == 0); I wonder if the code is going in unnecessary loops as the BSDailyoff variable references EC? I have a new computer with 64 mb ram so seems like this code should run quicker. I plan to expand on this code significantly and I am already having speed issues. Thanks so much for any suggestions.
December 15, 2020 at 10:32 am #61752Matthew
- Topics: 5
- Replies: 326
- Posts: 331
Hi Michael,
We’ve been looking at the script and there is nothing obvious to change in order to increase the speed. The BS variable line is a recursive call, meaning it has to do a full process for each bar, which will slow things down a lot.
We are working on optimizing this in future updates to Optuma.
For now, there are no adjustments we can recommend to increase the speed of the script.
1 user thanked author for this post.
January 15, 2021 at 12:13 pm #62005Mathew
- Topics: 32
- Replies: 1,648
- Posts: 1,680
Hi Michael,
Just to add to this, recursive scripting is always the slowest part. So this line
123EC = ECDaily + (Offset(EC, OFFSET=1)); // Exposure count totalis going to be slow.
Since what you are doing is a simple accumulation, you might be able to use the ACC() function and set the range to All Time.
See https://help.optuma.com/kb/faq.php?id=1026That should make it faster for you.
All the best
Mathew
-
AuthorPosts
- You must be logged in to reply to this topic.