Increase Script Speed

Optuma Forums Optuma Scripting Increase Script Speed

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #61667
    AvatarMichael
    • Topics: 7
    • Replies: 3
    • Posts: 10

    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;

    #61668
    MatthewMatthew
    • Topics: 5
    • Replies: 366
    • Posts: 371

    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:

    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.
    #61671
    AvatarMichael
    • Topics: 7
    • Replies: 3
    • Posts: 10

    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.

    #61752
    MatthewMatthew
    • Topics: 5
    • Replies: 366
    • Posts: 371

    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.
    #62005
    MathewMathew
    • Topics: 36
    • Replies: 1,806
    • Posts: 1,842

    Hi Michael,

    Just to add to this, recursive scripting is always the slowest part. So this line

    is 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=1026

    That should make it faster for you.

    All the best

    Mathew

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Pin It on Pinterest