+ Reply to Thread
Results 1 to 1 of 1

Thread: Tradestation Volatility Stop code

  1. #1

    Tradestation Volatility Stop code

    Here is the TS volatility stop code for those who are interested. I used the investor/RT algorithm. (I just switched to TS two months ago, and am still learning the language, so the code might be a bit hacky). Thanks to Billy for introducing such a wonderful tool.

    ======
    inputs:
    TR_period ( 65),
    TR_multiplier ( 5),
    uptrend_color (green),
    downtrend_color (red);

    variables:
    vstop(0),
    v_range(0),
    max_closing(0),
    min_closing(10000),
    up_trend(true),
    prev_vstop(0);

    v_range = Average( TrueRange, TR_period) * TR_multiplier;

    {if trend continues}
    If up_trend then Begin
    If Close > max_closing then
    max_closing = Close;
    vstop = max_closing - v_range;
    If vstop < prev_vstop then
    vstop = prev_vstop;
    end
    Else Begin
    If Close < min_closing then
    min_closing = Close;
    vstop = min_closing + v_range;
    If vstop > prev_vstop then
    vstop = prev_vstop;
    end;

    {check for trend change}
    If up_trend and Close < vstop then Begin
    up_trend = false;
    min_closing = Close;
    max_closing = 0;
    vstop = Close + v_range;
    end
    Else if (up_trend <> true) and Close > vstop then Begin
    up_trend = true;
    max_closing = Close;
    min_closing = 10000;
    vstop = Close - v_range;
    end;

    Plot1( vstop, "VStop" ) ;

    prev_vstop = vstop;

    If up_trend then begin
    SetPlotColor(1, uptrend_color);
    end
    Else begin
    SetPlotColor(1, downtrend_color);
    end;
    Attached Files
    Last edited by Wei; 09-26-2011 at 06:46 PM.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts