Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Adjusting EMA not only at State == State.DataLoaded

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

    Adjusting EMA not only at State == State.DataLoaded

    Hi everybody,

    is it possible to adjust the EMA not only at the beginning of the programm?
    If i attach an EMA to a ninjascript strategy i´ll get following code:

    Code:
    else if (State == State.DataLoaded)
    {
    EMA1 = EMA(Close, Convert.ToInt32(EMAValue);
    }
    So if i´ve understood this right, this piece of code will be only once called (at the beginning of the programm).

    Is there a possibility to change the value of the EMA while the programm is running?

    #2
    Hello debleded,

    Thanks for your post.

    That is correct. State.DataLoaded is called only once after all data series have been loaded.

    See this help guide for more information: https://ninjatrader.com/support/help...tatechange.htm

    You could change the value of the EMA in your script by assigning a different value for your EMA variable in OnBarUpdate().

    For example, if you would like to set the EMA to calculate using a period of 5 then in OnBarUpdate() you could call something like EMA1 = EMA(Close, 5);. Now EMA1 is calculated with a period of 5 instead of the initial period that was assigned to it.

    Let us know if we may further assist.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment


      #3
      Thank you for the answer!
      This makes absolute sense.

      So i just define EMA1 new in the OnBarUpdate() Method.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by CarlTrading, 03-31-2026, 09:41 PM
      1 response
      78 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      40 views
      0 likes
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      63 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      63 views
      0 likes
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      54 views
      0 likes
      Last Post CarlTrading  
      Working...
      X