Custom values on an array

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #181234 quote
    GeonsGeons
    Participant
    Average

    Hi to all! I use a simple code on an indicator, just to plot some custom values on a subchart below SPX. My code is :

    if DATE = 20211028 THEN
    MyIndicator = 4440
    endif
    if DATE = 20211029 THEN
    MyIndicator = 4445
    endif

    Return MyIndicator as “MyIndicator”

     

    Because after the values are now 2-3 years, the whole platform starts to lag a little bit. So, I wonder, can I put my values on arrays, so to have a lighter code?

    And if yes, how to transform correct? Any example please????

    #181289 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Did you mean something like this one?

    $MyDate[1]  = 20211028
    $MyValue[1] = 4440
    //
    $MyDate[2]  = 20211029
    $MyValue[2] = 4445
    //
    MyIndicator = 0
    FOR i = 1 TO 2
       IF Date = $MyDate[i] THEN
          MyIndicator = $MyValue[i]
          Break
       ENDIF
    ENDIF
    RETURN MyIndicator

    You can add more elements at the beginning of the code, then replace 2 by the number of elements you have used.

    #181487 quote
    GeonsGeons
    Participant
    Average

    Thank you very much for your help! I am just thinking, if there is a way to not use the $MyDate, but to use only one time a StartDate value. Is this possible???? Appreciate any help

    #181491 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Can you make an example?

    #181492 quote
    GeonsGeons
    Participant
    Average

    StartDay = 20211101 then

    $MyValue[1] = 4440
    $MyValue[2] = 4445

    $MyValue[3] = 4550

    $MyValue[4] = 4600

    $MyValue[5] = 4732

    $MyValue[6] = 4660

    And then, Return myIndicator from the Startday with values from MyValue[1] to MyValue[6].  Something like this…

    #181493 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    Yes, there you go:

    $MyValue[1] = 0
    $MyValue[2] = 0
    $MyValue[3] = 0
    $MyValue[4] = 0
    $MyValue[5] = 0
    $MyValue[6] = 0
    IF Date = 20211101 then
       $MyValue[1] = 4440
       $MyValue[2] = 4445
       $MyValue[3] = 4550
       $MyValue[4] = 4600
       $MyValue[5] = 4732
       $MyValue[6] = 4660
    ENDIF
    RETURN $MyValue[1],$MyValue[2],$MyValue[3],$MyValue[4],$MyValue[5],$MyValue[6]
    #181494 quote
    GeonsGeons
    Participant
    Average

    Thank you again! With this code, I just limit the manual data entry only on 1 value. Have a nice day Roberto

    robertogozzi thanked this post
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Custom values on an array


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Geons @geons Participant
Summary

This topic contains 6 replies,
has 2 voices, and was last updated by GeonsGeons
4 years, 10 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 11/08/2021
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...