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

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

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

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

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by Waxavi, 04-19-2024, 02:10 AM
                  3 responses
                  41 views
                  0 likes
                  Last Post gaz0001
                  by gaz0001
                   
                  Started by Max238, Today, 01:28 AM
                  2 responses
                  26 views
                  0 likes
                  Last Post NinjaTrader_ChristopherJ  
                  Started by Shansen, 08-30-2019, 10:18 PM
                  25 responses
                  949 views
                  0 likes
                  Last Post NinjaTrader_BrandonH  
                  Started by JonesJoker, 04-22-2024, 12:23 PM
                  8 responses
                  42 views
                  0 likes
                  Last Post JonesJoker  
                  Started by timko, Today, 06:45 AM
                  0 responses
                  7 views
                  0 likes
                  Last Post timko
                  by timko
                   
                  Working...
                  X