# MoCEMACalculator

View Source: [contracts/MoCEMACalculator.sol](https://github.com/money-on-chain/main-RBTC-contract/blob/master-gitbook/contracts/MoCEMACalculator.sol)

**↗ Extends:** [**Governed**](/main-rbtc-contract/smart-contracts/abis-documentation/governed.md) **↘ Derived Contracts:** [**MoCState**](/main-rbtc-contract/smart-contracts/abis-documentation/mocstate.md)

**MoCEMACalculator** - version: 0.1.12

## Contract Members

**Constants & Variables**

```js
uint256 internal bitcoinMovingAverage;
```

***

```js
uint256 public smoothingFactor;
```

***

```js
uint256 public lastEmaCalculation;
```

***

```js
uint256 public emaCalculationBlockSpan;
```

***

```js
uint256 public constant PRICE_PRECISION;
```

***

```js
uint256 public constant FACTOR_PRECISION;
```

***

```js
uint256[50] private upgradeGap;
```

***

## MovingAverageCalculation

**Parameters**

| Name          | Type    | Description |
| ------------- | ------- | ----------- |
| price         | uint256 |             |
| movingAverage | uint256 |             |

## Functions

* [getBitcoinMovingAverage()](#getbitcoinmovingaverage)
* [getSmoothingFactor()](#getsmoothingfactor)
* [setSmoothingFactor(uint256 factor)](#setsmoothingfactor)
* [getGovernorAddress()](#getgovernoraddress)
* [getEmaCalculationBlockSpan()](#getemacalculationblockspan)
* [setEmaCalculationBlockSpan(uint256 blockSpan)](#setemacalculationblockspan)
* [shouldCalculateEma()](#shouldcalculateema)
* [getLastEmaCalculation()](#getlastemacalculation)
* [initializeMovingAverage(uint256 initialEma, uint256 smoothFactor, uint256 emaBlockSpan)](#initializemovingaverage)
* [setBitcoinMovingAverage(uint256 btcPrice)](#setbitcoinmovingaverage)
* [coefficientComp()](#coefficientcomp)
* [initializeGovernor(address \_governor)](#initializegovernor)
* [\_doSetSmoothingFactor(uint256 factor)](#_dosetsmoothingfactor)

### getBitcoinMovingAverage

```js
function getBitcoinMovingAverage() public view
returns(uint256)
```

**Arguments**

### getSmoothingFactor

```js
function getSmoothingFactor() public view
returns(uint256)
```

**Arguments**

### setSmoothingFactor

```js
function setSmoothingFactor(uint256 factor) public nonpayable onlyAuthorizedChanger 
```

**Arguments**

| Name   | Type    | Description |
| ------ | ------- | ----------- |
| factor | uint256 |             |

### getGovernorAddress

```js
function getGovernorAddress() public view
returns(address)
```

**Arguments**

### getEmaCalculationBlockSpan

```js
function getEmaCalculationBlockSpan() public view
returns(uint256)
```

**Arguments**

### setEmaCalculationBlockSpan

```js
function setEmaCalculationBlockSpan(uint256 blockSpan) public nonpayable onlyAuthorizedChanger 
```

**Arguments**

| Name      | Type    | Description                                                    |
| --------- | ------- | -------------------------------------------------------------- |
| blockSpan | uint256 | Defines how many blocks should pass between BMA calculations\* |

### shouldCalculateEma

```js
function shouldCalculateEma() public view
returns(bool)
```

**Arguments**

### getLastEmaCalculation

```js
function getLastEmaCalculation() public view
returns(uint256)
```

**Arguments**

### initializeMovingAverage

Provides Bitcoin's Price and Moving average. More information of EMA calculation <https://en.wikipedia.org/wiki/Exponential\\_smoothing>

```js
function initializeMovingAverage(uint256 initialEma, uint256 smoothFactor, uint256 emaBlockSpan) internal nonpayable
```

**Arguments**

| Name         | Type    | Description                                 |
| ------------ | ------- | ------------------------------------------- |
| initialEma   | uint256 | Initial ema value                           |
| smoothFactor | uint256 | Weight coefficient for EMA calculation.     |
| emaBlockSpan | uint256 | Block count in a period for EMA calculation |

### setBitcoinMovingAverage

Calculates a EMA of the price. More information of EMA calculation <https://en.wikipedia.org/wiki/Exponential\\_smoothing>

```js
function setBitcoinMovingAverage(uint256 btcPrice) internal nonpayable
```

**Arguments**

| Name     | Type    | Description    |
| -------- | ------- | -------------- |
| btcPrice | uint256 | Current price. |

### coefficientComp

Calculates the smoothing factor complement

```js
function coefficientComp() internal view
returns(uint256)
```

**Arguments**

### initializeGovernor

```js
function initializeGovernor(address _governor) internal nonpayable
```

**Arguments**

| Name       | Type    | Description |
| ---------- | ------- | ----------- |
| \_governor | address |             |

### \_doSetSmoothingFactor

```js
function _doSetSmoothingFactor(uint256 factor) private nonpayable
```

**Arguments**

| Name   | Type    | Description |
| ------ | ------- | ----------- |
| factor | uint256 |             |


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.moneyonchain.com/main-rbtc-contract/smart-contracts/abis-documentation/mocemacalculator.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
