Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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
    BertrandNinjaTrader Customer Service

    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

        BertrandNinjaTrader Customer Service

        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...
              BertrandNinjaTrader Customer Service

              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,
                  BertrandNinjaTrader Customer Service

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by kevinenergy, 02-17-2023, 12:42 PM
                  115 responses
                  2,699 views
                  1 like
                  Last Post kevinenergy  
                  Started by prdecast, Today, 06:07 AM
                  1 response
                  4 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by Christopher_R, Today, 12:29 AM
                  1 response
                  14 views
                  0 likes
                  Last Post NinjaTrader_LuisH  
                  Started by chartchart, 05-19-2021, 04:14 PM
                  3 responses
                  577 views
                  1 like
                  Last Post NinjaTrader_Gaby  
                  Started by bsbisme, Yesterday, 02:08 PM
                  1 response
                  15 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Working...
                  X