Announcement

Collapse
No announcement yet.

hl2 as source?

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

  • hl2 as source?

    I've pasted a section of script from a "stop and reverse" which I'd like to use the hl2 point as datum for the ATR adjustment.

    I've commented the bits I've added i.e. eval the hl2 the getValue below. It works, but is it the right way to do it?

    PHP Code:
    //called on each new bar
        
    if ( getBarState() == BARSTATE_NEWBAR ) {
        
            
    //save the prior ATR value
            
    nATR_1  nATR;
            
            
    //calculate the Average True Range via Wilder's formula
            
    nV1 Math.abshigh(-1)-low(-1) );
            
    nV2 Math.absclose(-2)-high(-1) );
            
    nV3 Math.absclose(-2)-low(-1) );
            
            
    source = eval(hl2()); //added eval of source
        
            
    nTrToday Math.maxnV1nV2nV3 );
        
            
    nATR  = ( ( Period-) * nATR_1 nTrToday ) / Period;
            
            
    //determine the ratchet, if any
            
    nRatchet 1.0 - ( nBarsInTrade nRatchetInc );
            
            
    //adjust long stop
            
    if ( nStatus == ) {
                
    nVal ATRs nATR;
                
    nTmp source.getValue(-1) - ( nVal nRatchet );// using getValue
                
    if (nTmp>nStopPricenStopPrice nTmp

  • #2
    Re: hl2 as source?

    James
    In the code example you posted you do not need to use eval() since hl2() is not a string. You may want to see this article in the EFS KnowledgeBase for the description and syntax of the eval() function. You can also find several examples of its use by searching these forums for the keyword eval()
    Alex


    Originally posted by James 88
    I've pasted a section of script from a "stop and reverse" which I'd like to use the hl2 point as datum for the ATR adjustment.

    I've commented the bits I've added i.e. eval the hl2 the getValue below. It works, but is it the right way to do it?

    PHP Code:
    //called on each new bar
        
    if ( getBarState() == BARSTATE_NEWBAR ) {
        
            
    //save the prior ATR value
            
    nATR_1  nATR;
            
            
    //calculate the Average True Range via Wilder's formula
            
    nV1 Math.abshigh(-1)-low(-1) );
            
    nV2 Math.absclose(-2)-high(-1) );
            
    nV3 Math.absclose(-2)-low(-1) );
            
            
    source = eval(hl2()); //added eval of source
        
            
    nTrToday Math.maxnV1nV2nV3 );
        
            
    nATR  = ( ( Period-) * nATR_1 nTrToday ) / Period;
            
            
    //determine the ratchet, if any
            
    nRatchet 1.0 - ( nBarsInTrade nRatchetInc );
            
            
    //adjust long stop
            
    if ( nStatus == ) {
                
    nVal ATRs nATR;
                
    nTmp source.getValue(-1) - ( nVal nRatchet );// using getValue
                
    if (nTmp>nStopPricenStopPrice nTmp

    Comment

    Working...
    X