Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

volatility entry and trailing stop indicators

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

    volatility entry and trailing stop indicators

    Hello, I´m new to ninjatrader and I have two indicators wich have been very usefull in esignal, but so far I couldn't translate them to ninjatrader...

    they're pretty good for intraday traiding... so any help would be appreciated...

    the original codes, developed by jim berg and posted in esginal forums are the following...

    /************************************************** ***************
    Provided By : eSignal (c) Copyright 2004
    Description: Volatility Entry Advisor - by Jim Berg

    Version 1.1

    Notes:
    2/15/2005 - Added setComputeOnClose()

    February 2005 Issue - "The Truth About Volatility"

    Formula Parameters: Defaults:
    ATR Periods 10
    LL and HH Periods 20
    Thickness 2
    ************************************************** ***************/

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Volatility Entry Advisor");
    setCursorLabelName("Entry", 0);
    setCursorLabelName("Exit", 1);
    setDefaultBarThickness(2, 0);
    setDefaultBarThickness(2, 1);
    setDefaultBarFgColor(Color.lime, 0);
    setDefaultBarFgColor(Color.magenta, 1);

    setColorPriceBars(true);
    setDefaultPriceBarColor(Color.grey);
    setComputeOnClose();

    setShowTitleParameters(false);

    // Formula Parameters
    var fp1 = new FunctionParameter("nATRlen", FunctionParameter.NUMBER);
    fp1.setName("ATR Periods");
    fp1.setLowerLimit(1);
    fp1.setDefault(10);
    var fp2 = new FunctionParameter("nDonlen", FunctionParameter.NUMBER);
    fp2.setName("LL and HH Periods");
    fp2.setLowerLimit(1);
    fp2.setDefault(20);

    // Study Parameters
    var sp1 = new FunctionParameter("nThick", FunctionParameter.NUMBER);
    sp1.setName("Thickness");
    sp1.setDefault(2);
    }

    var bEdit = true;
    var vATR = null;
    var vDonchian = null;
    var vColor = Color.grey;

    function main(nATRlen, nDonlen, nThick) {
    if (bEdit == true) {
    vATR = new ATRStudy(nATRlen);
    vDonchian = new DonchianStudy(nDonlen, 0);
    setDefaultBarThickness(nThick, 0);
    setDefaultBarThickness(nThick, 1);
    bEdit = false;
    }

    var nState = getBarState();
    if (nState == BARSTATE_NEWBAR) {
    }

    var ATR = vATR.getValue(ATRStudy.ATR);
    var HHV = vDonchian.getValue(DonchianStudy.UPPER);
    var LLV = vDonchian.getValue(DonchianStudy.LOWER);
    var ATR1 = vATR.getValue(ATRStudy.ATR,-1);
    var HHV1 = vDonchian.getValue(DonchianStudy.UPPER,-1);
    var LLV1 = vDonchian.getValue(DonchianStudy.LOWER,-1);

    if (ATR1 == null || HHV1 == null || LLV1 == null) return;

    var vEntryLine = LLV+(2*ATR);
    var vExitLine = HHV-(2*ATR);
    var c = close(0);
    var vEntryLine1 = LLV1+(2*ATR1);
    var vExitLine1 = HHV1-(2*ATR1);
    var c1 = close(-1);

    if (c > vEntryLine && c1 < vEntryLine1 ||
    c > vEntryLine && c > vExitLine) {
    vColor = Color.blue;
    } else if (c < vExitLine && c1 > vExitLine1 ||
    c < vEntryLine && c < vExitLine) {
    vColor = Color.red;
    }
    setPriceBarColor(vColor);

    //return;
    return new Array(vEntryLine, vExitLine);
    }


    /************************************************** ***************
    Provided By : eSignal (c) Copyright 2004
    Description: Volatility Trailing Stop P15 - by Jim Berg

    Version 2.0

    Notes:
    February 2005 Issue - "The Truth About Volatility"
    This version has been modified to include the reverse logic
    for short positions.

    Formula Parameters: Defaults:
    ATR Periods 10
    Thickness 2
    ************************************************** ***************/

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Volatility Trailing Stop P15 ");
    setCursorLabelName("Long VStop", 0);
    setCursorLabelName("Short VStop", 1);
    setDefaultBarThickness(2, 0);
    setDefaultBarThickness(2, 1);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarFgColor(Color.green, 1);

    setShowTitleParameters(false);

    // Formula Parameters
    var fp1 = new FunctionParameter("nATRlen", FunctionParameter.NUMBER);
    fp1.setName("ATR Periods");
    fp1.setLowerLimit(1);
    fp1.setDefault(10);

    // Study Parameters
    var sp1 = new FunctionParameter("nThick", FunctionParameter.NUMBER);
    sp1.setName("Thickness");
    sp1.setDefault(2);
    }

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

    function main(nATRlen, nThick) {
    if (bEdit == true) {
    vATR = new ATRStudy(nATRlen);
    setDefaultBarThickness(nThick, 0);
    bEdit = false;
    }

    var nState = getBarState();
    if (nState == BARSTATE_NEWBAR) {
    aStopL.pop();
    aStopL.unshift(0);
    aStopS.pop();
    aStopS.unshift(0);
    }

    var ATR = vATR.getValue(ATRStudy.ATR);
    if (ATR == null) return;

    var c = close();
    var vStopL = (c - (2*ATR));
    aStopL[0] = vStopL;
    var vStopS = (c + (2*ATR));
    aStopS[0] = vStopS;

    var vStop15L = vStopL;
    var vStop15S = vStopS;
    for (var i = 0; i < 15; i++) {
    vStop15L = Math.max(aStopL[i], vStop15L);
    vStop15S = Math.min(aStopS[i], vStop15S);
    }

    return new Array(vStop15L, vStop15S);
    }


    #2
    Thanks for posting those, hopefully someone can assist in converting those to NinjaScript, if you haven't done so already please also check into our sharing section in this forum - http://www.ninjatrader-support2.com/...railing&desc=1

    If you need your scripts professionally programmed for you, please check those consultants out - http://www.ninjatrader.com/webnew/pa...injaScript.htm

    Comment


      #3
      Thanks Bertrand, I've been working on that but as you can see, the trailing stop works with an array where the indicator stores the past relevant values... how can i do that in NT?

      thanks

      ...
      var nState = getBarState();
      if (nState == BARSTATE_NEWBAR) {

      aStopL.pop();
      aStopL.unshift(0);
      aStopS.pop();
      aStopS.unshift(0);
      }

      Comment


        #4
        If you refer to a matrix, you can check out this thread here - http://www.ninjatrader-support2.com/...ead.php?t=7501

        For accessing / storing historical values synched by the CurrentBar index we have objects called DataSeries - http://www.ninjatrader-support.com/H...iesObject.html

        Comment


          #5
          thanks again Bertrand, let me check on that!!!

          Comment


            #6
            Did someone ever developed a Volatility Stop for NT? It would be nice to have as one of the indicators in the platform

            Comment


              #7
              You could for example check into the ATR trailing stop sharing here - http://www.ninjatrader.com/support/f...atility&desc=1

              Perhaps not 100% what you're looking for but close...

              Comment


                #8
                I was actually able to find something in a forum in the internet that comes close to what I need, but could you please add this as a 'built-in' indicator for NT? I think it's important enough and the code is readily available that it would be a great addition to the platform.

                Comment


                  #9
                  Thanks for your voice of feedback helping evolve NT even further - I've added your thought into our product management tracking system with id # 1794.

                  Thanks again,

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  579 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  334 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  101 views
                  0 likes
                  Last Post Mindset
                  by Mindset
                   
                  Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                  0 responses
                  554 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by RFrosty, 01-28-2026, 06:49 PM
                  0 responses
                  551 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X