βœ–

Home Forums General Questions EMA/SMA giving wrong values in live trading

EMA/SMA giving wrong values in live trading

  • Author
    Posts
    • πŸ“ Question Details

      EMA/SMA values not matching chart in my algo (using 1-min candles)

      I’m calculating EMA and SMA in my algo using 1-minute candles built from ticks.

      But when I compare it with broker/chart values, the numbers don’t match exactly.

      I’ve checked my candle data (OHLC looks correct), still indicator values are slightly off.

      Is there something I’m missing in EMA/SMA calculation?

    • Yes, this may be the issue of data consistency.

      See may be the problem because of these factors:

      Calculation on incomplete candles
      Missing initial historical data.
      Candle mismatch because of timing

      See we need the both the live and historical data to get the accurate values in EMA and SMA.

      Below is the code that you can refer:

      def calculate_ema(prices, period=5):
          ema = []
          k = 2 / (period + 1)
      
          for i, price in enumerate(prices):
              if i == 0:
                  ema.append(price)
              else:
                  ema.append(price * k + ema[-1] * (1 - k))
      
          return ema
      
      # This prices should be have the both live and historical data
      prices = [100, 102, 101, 105, 107, 110]
      
      ema_values = calculate_ema(prices, period=3)
      print(ema_values)
    • Yes, this may be the issue of data consistency.

      See may be the problem because of these factors:
      Calculation on incomplete candles
      Missing initial historical data.
      Candle mismatch because of timing
      See we need the both the live and historical data to get the accurate values in EMA and SMA.

      Below is the code that you can refer:

      def calculate_ema(prices, period=5):
          ema = []
          k = 2 / (period + 1)
      
          for i, price in enumerate(prices):
              if i == 0:
                  ema.append(price)
              else:
                  ema.append(price * k + ema[-1] * (1 - k))
      
          return ema
      
      # This prices should be have the both live nad historical data
      prices = [100, 102, 101, 105, 107, 110]
      
      ema_values = calculate_ema(prices, period=3)
      print(ema_values)
Viewing 2 reply threads
×

Start a Discussion

Get help from the AlgoDelta community.

×

Welcome Back!

Enter your email to sign in or create an account. No passwords needed.

⏳

Pending Approval

⚠️

Delete This?

Are you sure you want to delete this? This action is permanent and cannot be undone.

Scroll to Top