Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Alter EMA to include displacement

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

    Alter EMA to include displacement

    Hi - I use an EMA with a 2 displacement on my chart. When I try to use this as part of a strategy for backtesting the basic EMA is used without displacement.
    Is there a way to " create " a new EMA which includes the Displacement of 2 and then save this as a new Indicator that can be applied to my charts and be used in strategy testing.
    I am new to coding and have only just used the wizard for the first time. Any help will be really appreciated.
    B.

    #2
    Hello,

    Thank you for the question.

    You can both copy the original EMA and then edit what you need.

    To do this you would need to make a copy of the EMA first by doing the following:
    Click Tools -> Edit NinjaScript -> Indicator
    Select the EMA and open it
    Right click in the NinjaScript editor and click Save As.
    Give it a Different Name, EMA2 or anything you wish.
    Click OK and the code editor will be updated to the new file.

    To add displacement from Code you would need to add the following line into the Initialize section

    Displacement = 2;

    It will look like this:
    Code:
    protected override void Initialize()
    {
    	Displacement = 2; //this can be a positive or negative number
    }
    Once this line is added you will need to compile the indicator by pressing F5 or right clicking and selecting Compile.

    This should now be available for use.

    Please let me know if I may be of additional assistance.

    Comment


      #3
      great service thanks Jesse - I will have a go at this after work and let you know outcome.
      Cheers.
      B.

      Comment


        #4
        Originally posted by brian meade View Post
        great service thanks Jesse - I will have a go at this after work and let you know outcome.
        Cheers.
        B.
        Instead of hard-wiring a new indicator, just use OOP principles and syntax. This thread is a duplicate of your question. I gave an answer there.

        ref: http://www.ninjatrader.com/support/f...ad.php?t=65646
        Last edited by koganam; 11-12-2014, 01:54 PM. Reason: Corrected grammar.

        Comment


          #5
          Originally posted by NinjaTrader_Jesse View Post
          Hello,

          Thank you for the question.

          You can both copy the original EMA and then edit what you need.

          To do this you would need to make a copy of the EMA first by doing the following:
          Click Tools -> Edit NinjaScript -> Indicator
          Select the EMA and open it
          Right click in the NinjaScript editor and click Save As.
          Give it a Different Name, EMA2 or anything you wish.
          Click OK and the code editor will be updated to the new file.

          To add displacement from Code you would need to add the following line into the Initialize section

          Displacement = 2;

          It will look like this:
          Code:
          protected override void Initialize()
          {
          	Displacement = 2; //this can be a positive or negative number
          }
          Once this line is added you will need to compile the indicator by pressing F5 or right clicking and selecting Compile.

          This should now be available for use.

          Please let me know if I may be of additional assistance.

          Hi,Jesse,

          how to add this displacement to the conditions?

          Thx

          Comment


            #6
            Hello,

            I am unsure which condition you are referring, Displacement is a int so you can Check it, or Set it, if that is what you are asking.

            Code:
            if(Displacement == 2)
            Can you better explain the question, or is this the answer?

            I look forward to being of further assistance.

            Comment


              #7
              Originally posted by NinjaTrader_Jesse View Post
              Hello,

              I am unsure which condition you are referring, Displacement is a int so you can Check it, or Set it, if that is what you are asking.

              Code:
              if(Displacement == 2)
              Can you better explain the question, or is this the answer?

              I look forward to being of further assistance.
              Hi,Jesse,

              For example, if(Low[0]<LowerBand[0] + Displacement[-1])

              How would it look like in reality?

              Comment


                #8
                I`m going to attache the indicator.Could you please add the displacement part to its conditions?
                Attached Files

                Comment


                  #9
                  Hello,

                  I am still unsure what you mean by add displacement to its conditions, are you asking to add Displacement to Initialize as it was provided in post 2? if so you just need to copy and paste that 1 line into the scripts Initialize and change the number to the value you want.

                  Displacement simply displaces the visual plots by the number you set, this is also meant to be set in initialize. If you are trying to check the value of the displacement, the prior example in post 6 shows that.

                  Please provide a clear description of what you are asking regarding the attached file and I will be happy to assist.

                  Please let me know if I may be of further assistance.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                  0 responses
                  581 views
                  0 likes
                  Last Post Geovanny Suaza  
                  Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                  0 responses
                  338 views
                  1 like
                  Last Post Geovanny Suaza  
                  Started by Mindset, 02-09-2026, 11:44 AM
                  0 responses
                  103 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
                  552 views
                  1 like
                  Last Post RFrosty
                  by RFrosty
                   
                  Working...
                  X