Announcement

Collapse
No announcement yet.

converting an expression into a serial object

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

  • converting an expression into a serial object

    I am having some difficulties in converting an expression into a serial object. The expression is
    PHP Code:
        nPRHigh hhv(fpLengthhigh());
        
    nPRLow llv(fpLengthlow());
        
    nPRPrice = ( hhv(fpLengthhigh()) + llv(fpLengthlow()) + close() ) / 3.0
    return new Array(
    nPRPricenPRHighnPRLow ); 
    so far I got
    PHP Code:
    // global variables
    var bInit false;  //initialization flag
    var nPRPrice null;     //Pivot Range Price
    var nPRHigh null;      //Pivot Range High
    var nPRLow null;       //Pivot Range low

    function main(fpSymbolfpIntervalfpPT1fpPS1fpThick1fpColor1fpPT2fpPS2fpThick2fpColor2fpPT3fpPS3fpThick3fpColor3fpPVarfpLength)
    {
        
    // one time initialization
        
    if(bInit == false){
            if(
    fpSymbol == nullfpSymbol getSymbol();
            if(
    fpInterval == nullfpInterval getInterval();

        var 
    vSymbol fpSymbol "," fpInterval;
        
    nPRHigh hhv(fpLengthhigh(sym(vSymbol)) );
        
    nPRLow llv(fpLengthlow(sym(vSymbol)) );
        
    nPRPrice 
        
    bInit true;
        }   
    //end of initialization  
    //nPRPrice = ( hhv(fpLength, high()) + llv(fpLength, low()) + close() ) / 3.0;

    return new Array(nPRPricenPRHighnPRLow ); 
    I have to admit that I'm stuck in converting
    ( hhv(fpLength, high()) + llv(fpLength, low()) + close() ) / 3.0;
    to work with series.

    Thanks

  • #2
    scjohn
    If you move hhv() and llv() out of the bInit statement they appear to work

    PHP Code:
    var bInit false;
    var 
    nPRPrice null;
    var 
    nPRHigh null;
    var 
    nPRLow null;
    var 
    Symbol null;

    function 
    main(fpSymbolfpIntervalfpLength){

        if(
    fpLength==nullfpLength=10;

        if(
    bInit == false){
            if(
    fpSymbol == nullfpSymbol getSymbol();
            if(
    fpInterval == nullfpInterval getInterval();
            var 
    vSymbol fpSymbol "," fpInterval;
            
    Symbol vSymbol;
            
    //nPRHigh = hhv(fpLength, high(sym(vSymbol)) );
            //nPRLow = llv(fpLength, low(sym(vSymbol)) ); 
            
    bInit true;
        }
        
        
    nPRHigh hhv(fpLengthhigh(sym(Symbol)));
        
    nPRLow  llv(fpLengthlow(sym(Symbol)));
        
    nPRPrice = ( nPRHigh nPRLow close(sym(Symbol)) ) / 3.0;

        return new Array(
    nPRPricenPRHighnPRLow );

    While waiting for a fix if you want to maintain the functions inside the bInit statement you can use upperDonchian() in place of hhv() and lowerDonchian() in place of llv() and the returned values will be identical (compare it using the script below)
    Alex

    PHP Code:
    var bInit false;
    var 
    nPRPrice null;
    var 
    nPRHigh null;
    var 
    nPRLow null;
    var 
    Symbol null;

    function 
    main(fpSymbolfpIntervalfpLength){

        if(
    fpLength==nullfpLength=10;

        if(
    bInit == false){
            if(
    fpSymbol == nullfpSymbol getSymbol();
            if(
    fpInterval == nullfpInterval getInterval();
            var 
    vSymbol fpSymbol "," fpInterval;
            
    Symbol vSymbol;
            
    nPRHigh upperDonchian(fpLengthhigh(sym(Symbol)) );
            
    nPRLow lowerDonchian(fpLengthlow(sym(Symbol)) );
            
    bInit true;
        }
        
        
    //nPRHigh = hhv(fpLength, high(sym(Symbol)));
        //nPRLow  = llv(fpLength, low(sym(Symbol)));
        
    nPRPrice = ( getSeries(nPRHigh) + getSeries(nPRLow) + close(sym(Symbol)) ) / 3.0;

        return new Array(
    nPRPricenPRHighnPRLow );

    Comment


    • #3
      Alexis,

      It would appear that hhv() and llv() have problems outside of binit statement.

      I get two lines of ouput

      High: 0 Low: 0
      High: 595 Low: 586.9

      And nothing appears on the chart.

      I right click on chart the click Reload, I see: PivotRange, loading data.

      PHP Code:
          nPRHigh hhv(fpLengthhigh(sym(vSymbol)) );
          
      nPRLow llv(fpLengthlow(sym(vSymbol)) );
          
      debugPrintln("High: " +  nPRHigh " Low: " nPRLow);
          
      nPRPrice = ( nPRHigh nPRLow close(sym(vSymbol)) ) / 3.0;

          return new Array(
      nPRPricenPRHighnPRLow ); 

      Comment


      • #4
        scjohn
        That is because vSymbol needs to be a global variable. That is why I added var Symbol = null; as an external (ie global) variable and then inside bInit I added Symbol = vSymbol. Try running the sample script I posted earlier and you should see that it works
        Alex

        Comment

        Working...
        X