Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Amend EMA to reset at each session

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

    Amend EMA to reset at each session

    Hello,

    How do I amend the EMA indicator to make it reset its calculation at the start of each session?

    Currently if there is a gap up / gap down, the EMA becomes distorted because it is still using values from the previous day.

    The EMA indicator now has only 1 line.

    Code:
    Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);
    Thanks.

    #2
    You can use the FirstBarOfSession Property to reset the the value at that time. This works from the SessionTemplate you have applied to the chart.

    Code:
    if(Bars.FirstBarOfSession)
    			{
    				Value.Reset();
    			}
    			else
    			Value.Set(CurrentBar == 0 ? Input[0] : Input[0] * (2.0 / (1 + Period)) + (1 - (2.0 / (1 + Period))) * Value[1]);
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks that seems to work =)

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by kinfxhk, 07-14-2026, 09:39 AM
      0 responses
      125 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 10:18 AM
      0 responses
      105 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 09:50 AM
      0 responses
      84 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-13-2026, 07:21 AM
      0 responses
      104 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Started by kinfxhk, 07-11-2026, 02:11 AM
      0 responses
      83 views
      0 likes
      Last Post kinfxhk
      by kinfxhk
       
      Working...
      X