Announcement

Collapse
No announcement yet.

easy question to answer

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • easy question to answer

    But as I admitted last time I don't know - I'm not a programmer by training. Although I finally was able to do my own trivial code to answer my last question on my own - a snap for a guru, no ?

    Anyway, here are two scripts that do the same thing - indentically on the screen -

    Here's the question, which version will take up less computer resources - which one will theoretically run faster ?

    And it would be worthwhile to hear the explanation of the

    if ( bInit == false )

    and why the good programmers use this.

    Best Regards,
    Glenn


    var bInit = false;
    function preMain() {
    setPriceStudy(true);
    setDefaultBarFgColor(Color.RGB(50,50,0),0);
    setDefaultBarFgColor(Color.RGB(45,0,0),1);
    }
    function main() {
    if ( bInit == false ) {
    w20 = wma(20)
    w60 = wma(60)
    bInit = true;
    }

    myw20 = w20.getValue(0);
    myw20p = w20.getValue(-1);
    drawLineRelative(0, myw20, 5, (myw20+5*(myw20-myw20p)), PS_SOLID, 1, Color.RGB(50,50,0), 0 );

    myw60 = w60.getValue(0);
    myw60p = w60.getValue(-1);
    drawLineRelative(0, myw60, 5, (myw60+5*(myw60-myw60p)), PS_SOLID, 1, Color.RGB(45,0,0), 1 );

    return new Array(myw20,myw60);
    }



    OR

    function preMain() {
    setPriceStudy(true);
    setDefaultBarFgColor(Color.RGB(50,50,0),0);
    setDefaultBarFgColor(Color.RGB(45,0,0),1);
    }
    function main() {
    w20 = wma(20)
    w60 = wma(60)
    drawLineRelative(0, w20, 5, (w20+5*(w20-w20.getValue(-1))), PS_SOLID, 1, Color.RGB(50,50,0),0);
    drawLineRelative(0, w60, 5, (w60+5*(w60-w60.getValue(-1))), PS_SOLID, 1, Color.RGB(45,0,0), 1);
    return new Array(w20,w60);
    }

  • #2
    never mind

    dug around some more and found some things Alexis had written years ago

    Comment


    • #3
      Hey fastflyer, do you think you could link to the articles that you found regarding the

      Here's the question, which version will take up less computer resources - which one will theoretically run faster ? And it would be worthwhile to hear the explanation of the if ( bInit == false ) and why the good programmers use this.
      I'd really like to check those out and I cannot find many good references regarding the reasons for using if ( bInit == false )

      Thanks,

      Comment


      • #4
        Hi,

        The reason is that the creation of efs2 objects can be relatively resource intensive and it only has to be done once. So it is most efficient to declare them in a conditional at the beginning of the efs, assigning the efs2 objects to global variables. A Boolean check (done every tick) is pretty efficient as well, so it is a good practice.

        As a result, the usage of a bInit conditional has become a preferred practice.

        There are several resources that that explain the use of bInit ...


        eSignal Formula Script (EFS) Tutorial Series (BACK TESTING TUTORIAL 3)

        eSignal Formula Script (EFS) Tutorial Series (INTRODUCTORY TUTORIAL 3)

        You can also look through the forum using google, the link is in my signature below.

        There are also some great threads that discuss efs2 that have information on this subject in the links below as well.

        Comment

        Working...
        X