Announcement

Collapse
No announcement yet.

EasyLanguage/PowerLanguage in Efs

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

  • EasyLanguage/PowerLanguage in Efs

    Hi all again,

    first of all I have to say I'm not an experienced professional programmer, but just a self-taught programmer.
    I read EFS KnowledgeBase, I studied as examples shared files, and I am convinced that the eSignal's javascript is a very powerful and versatile language with which you can write anything!

    However, as all users of eSignal participating in this forum, when I read magazines or books on trading, or when I search on internet about ideas for trading systems I always come across with EasyLanguage code (or its equivalent PowerLanguage).
    My first question, just out of curiosity, is: Why did you have not chosen to be compatible with EasyLanguage, like other platforms did?

    Second. From the little I have learned about EasyLanguage, it contains hundreds of functions that make programmer's life easier.
    It is certainly true that each of those functions can be programmed with EFS, but of course it is less comfortable.

    And here is my humble suggestion:
    It would be nice if, a little at a time, the eSignal's programmers would create libraries (EfsLib) with functions similar to those of EasyLanguage, so as to facilitate the conversion of the codes.
    It would be nice also to see an example of EfsLib not encrypted to learn how to build your own !

    I hope I have explained the concept in an understandable english.
    Regards
    Massimo

  • #2
    /************************************************** * OpenSource_EL_Lib.efslib :
    Started by Massimo Rizzi on December 2011.
    This library aims to be a collection of functions that emulates the corresponding EasyLanguage functions.
    It is intended as a library open to contributions of all those who wish to participate.
    If you want to add your own functions, or want to add the same features that already exist but you think you have written them better, feel free to do so.
    Please, respect the following few rules:
    - for the name of the function, use the following format: FunctionNameEasyLanguage_YourID. (Example Pivot_MRT).
    - please always include a description of any changes you make.
    ******************************************/


    /* Pivot function (by Massimo Rizzi, December 2011) ----------
    In EasyLanguage:
    - Pivot(Price, Length, LeftStrength, RightStrength, Instance, HiLo, oPivotPrice, oPivotBar)
    where:
    - Price: specifies which bar value (price, function, or formula) to be considered.
    - Length: sets the number of bars to consider for the pivot.
    - LeftStrength: sets the required number of bars on the left side of the pivot bar.
    - RightStrength: sets the required number of bars on the right side of the pivot bar.
    - Instance: sets which occurrence (that is, 1 = most recent, 2 = 2nd most recent, and so on) to return.
    - HiLo: sets which pivot values to return, 1 = High, -1 = Low.
    - oPivotPrice: returns the specified bar value at the pivot point.
    - oPivotBar: returns the number of bars ago the pivot point occurred.
    - The Pivot function itself returns a value of 1 if a pivot is found, and -1 if not found.
    - Example:
    Assigns to Value2 the most recent pivot low price over the last 21 bars and to Value3 the number
    of bars ago the pivot low occurred using a left strength of 4 and a right strength of 2.
    Vars: oPivotPrice(0), oPivotBar(0);
    Value1 = Pivot(Low,21,4,2,1,-1,oPivotPrice,oPivotBar);
    Value2 = oPivotPrice;
    Value3 = oPivotbar;

    In Pivot_MRT () function returns:
    - vRetPivot: a value of 1 if a pivot is found, and -1 if not found.
    - vRetPivotPrice: returns the specified bar value at the pivot point.
    - vRetPivotBar: returns the number of bars ago the pivot point occurred.
    - Pivot() function returns (-1, -1, -1) if pivot not found.

    - Example:
    var myLibrary = addLibrary( "OpenSource_EL_Lib.efslib" );
    var vPivot = myLibrary.Pivot(low(), 21,4,2,1,-1);
    var oRetPivot = vPivot[0];
    var oRetPivotPrice = vPivot[1];
    var oRetPivotBar = vPivot[2];
    -----------------------------------------------------------------*/

    var bPivotInit=false;
    function Pivot_MRT (xPrice, xLength, xLeftStrength, xRightStrength, xInstance, xHiLo) {
    if (bPivotInit==false) {
    var vPrice=eval(xPrice);
    var vLength=-Math.abs(xLength);
    var vLeftStrength=-Math.abs(xLeftStrength);
    var vRightStrength=-Math.abs(xRightStrength);
    var vInstance=xInstance;
    var vHiLo=xHiLo;
    bPivotInit=true;
    }
    var vX=vRightStrength;
    var vCounter=0;
    var bPivotFlag=false;
    while (bPivotFlag==false && vX>=vLength) {
    var bFlag=false;
    var vY=vX+1;
    while (bFlag==false && vY<=vX-vRightStrength) {
    if (vHiLo==1 && vPrice.getValue(vX)<=vPrice.getValue(vY)) bFlag=true;
    else if (vHiLo==-1 && vPrice.getValue(vX)>=vPrice.getValue(vY)) bFlag=true;
    else vY++;
    }
    if (bFlag==false) {
    vY=vX-1;
    while (bFlag==false && vY>=vX+vLeftStrength) {
    if (vHiLo==1 && vPrice.getValue(vX)<vPrice.getValue(vY)) bFlag=true;
    else if (vHiLo==-1 && vPrice.getValue(vX)>vPrice.getValue(vY)) bFlag=true;
    else vY--;
    }
    }
    if (bFlag==false) vCounter++;
    if (bFlag==false && vCounter==vInstance) bPivotFlag=true;
    else vX--;
    }
    if (bPivotFlag==true) {
    var vRetPivot=1;
    var vRetPivotPrice=vPrice.getValue(vX);
    var vRetPivotBar=vX;
    } else {
    var vRetPivot=-1;
    var vRetPivotPrice=-1;
    var vRetPivotBar=-1;
    }
    return new Array (vRetPivot, vRetPivotPrice, vRetPivotBar);
    }
    Attached Files

    Comment


    • #3
      Added :
      SwingHigh, SwingHighBar, SwingLow, SwingLowBar functions.
      Attached Files

      Comment


      • #4
        Rewritten:
        Pivot, SwingHigh, SwingHighBar, SwingLow, SwingLowBar functions.
        Added:
        PivotHighVS, PivotHighVSBar, PivotLowVS, PivotLowVSBar functions.
        Attached Files

        Comment


        • #5
          PHP Code:
          function SwingHighBar_MRT(xInstancexPricexStrengthxLength)
          {
            var 
          vInstance xInstance;
            var 
          vPrice = eval(xPrice);
            var 
          vLeftStrength Math.abs(xStrength);
            var 
          vRightStrength Math.abs(xStrength);
            var 
          vLength Math.abs(xLength);
            var 
          vHiLo 1;
            var 
          vSwingHighBar Pivot_MRT(vPricevLengthvLeftStrengthvRightStrengthvInstancevHiLo);
            return (
          vSwingHighBar[2]);


          I would recommend this style (the PHP tags to post this code are putting in extra blank lines. In the real code, I always put a blank line after the last "var" declaration, group the next 2 lines and then a blank line between them and the return statement):

          PHP Code:
          function SwingHighBar_MRT(xInstancexPricexStrengthxLength)
          {
            var 
          vSwingHighBar;

            
          xStrength Math.abs(xStrength);
            
          vSwingHighBar Pivot_MRT(xPrice*1Math.abs(xLength), xStrengthxStrengthxInstance1);


            return 
          vSwingHighBar[2];

          Notes:

          1. It's not necessary to copy function parameter variables into local variables. Use them directly.

          2. Avoid using eval() if you can. If you want to ensure that a variable is numeric instead of a string, then just multiply it by 1 (e.g., "2"*1 = 2). Conversely, if you want to convert a numeric to a string then you can do this: "" + 2 = "2". Of course, there's parseFloat(string), parseInt(string), toFixed() and toString() to do the same types of things but I find my suggestions to be easy to read in the code and concise.

          3. If you're returning 1 value, then you don't need parens on the return statement.

          4. One other thing not related to the code above, instead of using:

          return new Array(var1, var2, var3);

          You can also do this:

          return [var1, var2, var3];

          The brackets create a new array of whatever is contained within them.

          Verbosity is okay if it helps to improve readability, but if it involves creating a lot of local variables, I'd avoid that. For example, your function could have been a one-liner, but it hurts the readability too much, so I *do* draw the line somewhere:


          PHP Code:
          // I avoid this kind of coding.  Trying to be too clever hurts readability.

          function SwingHighBar_MRT(xInstancexPricexStrengthxLength)
          {
            return (
          Pivot_MRT(xPrice*1Math.abs(xLength), Math.abs(xStrength), Math.abs(xStrength), xInstance1))[2];

          Comment


          • #6
            Wow,
            this is the first thing I thought after reading your response, Steve.
            Here it soon becomes clear who is the rookie and who is the expert !!!
            I am sincerely grateful to you for your corrections and suggestions that help me to improve myself as a programmer.
            Here there is no superiority complex but only a great desire to learn.
            As for the "function parameter variables" I confess I have not yet understood how to treat them. When to copy them to local variables even within a "bInit condition" and when to use them directly.
            I'd appreciate if you would spend a little time to explain the topic or if you could send me some links.
            As soon as possible I will correct the functions according to your suggestions.
            Thanks again.
            Massimo

            Comment


            • #7
              Rewritten efsLib according SteveH's suggestions.

              Attached an example that draws trendlines between two pivot points:

              function preMain() {
              setPriceStudy(true);
              }
              function main() {
              if (getCurrentBarIndex()==0 && getBarState()==BARSTATE_NEWBAR) {

              var myLib = addLibrary( "OpenSource_EL_Lib.efsLib" );
              var vPivot0 = myLib.Pivot_MRT(high(), 100, 3, 3, 1, 1);
              var vPivot1 = myLib.Pivot_MRT(high(), 100, 3, 3, 3, 1);
              var vPivot2 = myLib.Pivot_MRT(low(), 100, 3, 3, 1, -1);
              var vPivot3 = myLib.Pivot_MRT(low(), 100, 3, 3, 3, -1);

              drawLineRelative(-vPivot1[2], vPivot1[1], -vPivot0[2], vPivot0[1], PS_SOLID, 1, Color.green, "TagName");
              drawLineRelative(-vPivot3[2], vPivot3[1], -vPivot2[2], vPivot2[1], PS_SOLID, 1, Color.red, "TagName1");

              }
              }
              Attached Files

              Comment


              • #8
                IFF function (EL) and If statement (EFS)

                IFF function (EL) and If statement (EFS):

                FWIW,
                I discovered that EL IFF function:

                IFF (Condition, TrueVal, FalseVal);

                can be written like:

                if (Condition ?TrueVal :FalseVal);

                that means:

                if (Condition) TrueVal;
                else FalseVal;

                Massimo

                Comment

                Working...
                X