Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

LSMA with hi and low

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

    LSMA with hi and low

    Hi

    I have been using E signal before and I got a LSMA indicator with Hi and low, I have found the code below but I don´t know how to add the code to a new indicator, please help me out! I don´t think these codes are everything needed, but maybe only the "standard" text is missing. I would appreciate if someone can make it complete and as a zip (or rar file) so it is easy to import into NT

    Thanks

    Michael
    Sweden

    #2
    Hello Michael,

    Welcome to the NinjaTrader forums. You will not be able to simply copy - paste esignal code into a NinjaScript file. To convert you would need some familiarity with both platforms, and then convert the logic into NinjaScript. Hopefully a community member can help assist with this. You may also consider one of our 3rd party NinjaScript consultants. Many offer translation services from one platform to another.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      The code below is for ninjatrader, not esignal, I hope someone could make it complete and as an zip file.

      Michael

      LEAST SQUARE MOVING AVERAGE:

      Description: Calculates the Least Square Moving Average (LSMA)
      off the high and also off the low to create a channel.


      Version Control:

      */



      function preMain()
      {
      setPriceStudy(true);
      setStudyTitle("LSMA Channel");
      setCursorLabelName("LSMA Hi",0);
      setCursorLabelName("LSMA Lo",1);
      setDefaultBarThickness(2,0);
      setDefaultBarThickness(2,1);

      var fp1 = new FunctionParameter("HiLength", FunctionParameter.NUMBER);
      fp1.setName("Length of LSMA(High)");
      fp1.setDefault(25);

      var fp2 = new FunctionParameter("LoLength", FunctionParameter.NUMBER);
      fp2.setName("Length of LSMA(Low)");
      fp2.setDefault(25);

      var fp3 = new FunctionParameter("HiOffset", FunctionParameter.NUMBER);
      fp3.setName("Offset of LSMA(High)");
      fp3.setDefault(0);

      var fp4 = new FunctionParameter("LoOffset", FunctionParameter.NUMBER);
      fp4.setName("Offset of LSMA(Low)");
      fp4.setDefault(0);

      var fp5 = new FunctionParameter("HiColor", FunctionParameter.COLOR);
      fp5.setName("Color of LSMA(High)");
      fp5.setDefault(Color.blue);

      var fp6 = new FunctionParameter("LoColor", FunctionParameter.COLOR);
      fp6.setName("Color of LSMA(Low)");
      fp6.setDefault(Color.red);
      }


      var aHigh = null;
      var aLow = null;
      var aHiLSMA = null;
      var aLoLSMA = null;
      var vInit = false;
      var LSMA_Array = new Array();


      function main(HiLength,LoLength,HiOffset,LoOffset,HiColor,L oColor)
      {


      if (vInit == false) {
      aHigh = new Array(HiLength);
      aLow = new Array(LoLength);
      aHiLSMA = new Array(HiLength);
      aLoLSMA = new Array(LoLength);
      setDefaultBarFgColor(HiColor,0);
      setDefaultBarFgColor(LoColor,1);
      preMain();
      vInit = true;
      }

      vHigh = high();
      vLow = low();

      if (vHigh == null) return;
      if (vLow == null) return;

      if (getBarState() == BARSTATE_NEWBAR) {
      if (aHigh[HiLength-1] != null) aHigh.pop();
      aHigh.unshift(vHigh);
      if (aLow[LoLength-1] != null) aLow.pop();
      aLow.unshift(vLow);
      }

      aHigh[0] = vHigh;
      aLow[0] = vLow;

      if (aHigh[HiLength-1] == null || aLow[LoLength-1] == null) return;

      // get LSMA values and assign to arrays
      var vHiLSMA = getLSMA(aHigh, HiLength);
      var vLoLSMA = getLSMA(aLow, LoLength);

      if (getBarState() == BARSTATE_NEWBAR) {
      if (aHiLSMA[HiLength-1] != null) aHiLSMA.pop();
      aHiLSMA.unshift(vHiLSMA);
      if (aLoLSMA[LoLength-1] != null) aLoLSMA.pop();
      aLoLSMA.unshift(vLoLSMA);
      }

      aHiLSMA[0] = vHiLSMA;
      aLoLSMA[0] = vLoLSMA;


      return new Array (aHiLSMA[HiOffset], aLoLSMA[LoOffset]);
      }


      // ------------------------------------
      // Get a LSMA value
      function getLSMA(aPrice, nLength) {
      var Num1 = 0.0;
      var Num2 = 0.0;
      var SumBars = nLength * (nLength - 1) * 0.5;
      var SumSqrBars = (nLength - 1) * nLength * (2 * nLength - 1) / 6;
      var SumY = 0.0;
      var Sum1 = 0.0;
      var Sum2 = 0.0;
      var Slope = 0.0;
      var Intercept = 0.0;

      for (i = 0; i < nLength; ++i) {
      SumY += aPrice[i];
      Sum1 += i * aPrice[i];
      }
      Sum2 = SumBars * SumY;
      Num1 = nLength * Sum1 - Sum2;
      Num2 = SumBars * SumBars - nLength * SumSqrBars;
      if (Num2 != 0) Slope = Num1 / Num2;
      Intercept = (SumY - Slope * SumBars) / nLength;
      var LinearRegValue = Intercept + Slope * (nLength - 1);


      return LinearRegValue;
      }

      Comment


        #4
        Michael,

        LSMA is a bit of a misnomer, it is just the LinReg indicator in NT.

        Comment


          #5
          Originally posted by lefevreed View Post
          Michael,

          LSMA is a bit of a misnomer, it is just the LinReg indicator in NT.
          I want LSMA with high and low setting, You can´t do that in LinReg or how do you change to high and low, I want with 25 settings on both?

          Michael

          Comment


            #6
            Maybe it´s called LSMA channel?
            M

            Comment


              #7
              Michael,

              Here's a quick core indicator to get you started. It can be modified to meet your needs, but you can see what needs to be done. Off the top of my head, you may want to figure out what you want for an Offset. I included a variable for it, but it's not used in the code itself, that will have to be added.

              Let me know if you have any questions about it.
              Attached Files

              Comment


                #8
                Thank you , I will try it....

                M

                Comment


                  #9
                  Thank you lefevreed, it worked perfect!

                  You don´t have an MACD crossover indicator with dots in the graph?

                  M

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by DJ888, 04-16-2024, 06:09 PM
                  4 responses
                  12 views
                  0 likes
                  Last Post DJ888
                  by DJ888
                   
                  Started by terofs, Today, 04:18 PM
                  0 responses
                  7 views
                  0 likes
                  Last Post terofs
                  by terofs
                   
                  Started by nandhumca, Today, 03:41 PM
                  0 responses
                  6 views
                  0 likes
                  Last Post nandhumca  
                  Started by The_Sec, Today, 03:37 PM
                  0 responses
                  3 views
                  0 likes
                  Last Post The_Sec
                  by The_Sec
                   
                  Started by GwFutures1988, Today, 02:48 PM
                  1 response
                  9 views
                  0 likes
                  Last Post NinjaTrader_Clayton  
                  Working...
                  X