Announcement

Collapse
No announcement yet.

Help adding Function Parameter

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

  • Help adding Function Parameter

    I've a trailing stop (long) study based on ATR (which I've attempted to re-write). I'd like to add in the FunctionParameter of choosing between the price low & close (in edit studies), but have not quite got it. I'm new to this, so if anyone could cast an eye over this and point out any glaring errors, I'd be very grateful. It did work until I added the fp3 FunctionParameter then I lost the line on the chart (but without any syntax errors). I've also added a max Stop period of 21 because of the array (21). Is that necessary?

    Ps. Alex, I'm working on the posting below. That's my next job & I've started on the tutorials. Cheers
    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("TStopL");
        
    setCursorLabelName("TStopL");
        
    setDefaultBarThickness(1);
        
    setDefaultBarFgColor(Color.red);
        
        
    setShowTitleParameters(false);
        
    setComputeOnClose();
        
        
    // Formula Parameters
        
    var fp1 = new FunctionParameter("nATR"FunctionParameter.NUMBER);
            
    fp1.setName("ATR Periods");
            
    fp1.setLowerLimit(1);
            
    fp1.setDefault(13);
        var 
    fp2 = new FunctionParameter("nStop"FunctionParameter.NUMBER);
            
    fp2.setName("Stop Periods");
            
    fp2.setLowerLimit(1);
            
    fp2.setUpperLimit(21);
            
    fp2.setDefault(13);
        var 
    fp3 = new FunctionParameter("sPrice"FunctionParameter.STRING);
            
    fp3.setName("Price");
            
    fp3.addOption("close");
            
    fp3.addOption("low");
            
    fp3.setDefault("low");
            
            
        
    // Study Parameters
        
    var sp1 = new FunctionParameter("nThick"FunctionParameter.NUMBER);
            
    sp1.setName("Thickness");
            
    sp1.setDefault(1); 
    }

    var 
    bEdit true;
    var 
    vATR null;
    var 
    aStopL = new Array(21);

    function 
    main(nATRnStopsPricenThick) {
        if (
    bEdit == true) {
            
    vATR = new ATRStudy(nATR);
            
    setDefaultBarThickness(nThick0);
            
    bEdit false;
        }
        
        var 
    nState getBarState();
        if (
    nState == BARSTATE_NEWBAR) {
            
    aStopL.pop();
            
    aStopL.unshift(0);
        }
        
        var 
    ATR vATR.getValue(ATRStudy.ATR);
        if (
    ATR == null) return;
        
        var 
    sPrice();
        var 
    vStopL = (- (2*ATR));
        
    aStopL[0] = vStopL;
        
        var 
    vStopxL vStopL;
        for (var 
    0nStopi++) {
            
    vStopxL Math.max(aStopL[i], vStopxL);
        }
        
        return 
    vStopxL;


  • #2
    James
    With regards to adding a FunctionParameter to select which price to use see this thread on the same subject
    Alex


    Originally posted by James 88
    I've a trailing stop (long) study based on ATR (which I've attempted to re-write). I'd like to add in the FunctionParameter of choosing between the price low & close (in edit studies), but have not quite got it. I'm new to this, so if anyone could cast an eye over this and point out any glaring errors, I'd be very grateful. It did work until I added the fp3 FunctionParameter then I lost the line on the chart (but without any syntax errors). I've also added a max Stop period of 21 because of the array (21). Is that necessary?

    Ps. Alex, I'm working on the posting below. That's my next job & I've started on the tutorials. Cheers
    [/PHP]

    Comment

    Working...
    X