CommodityChannelIndex
interface cAlgo.API.Indicators
DesktopCLICloud
The Commodity Channel Index interface.
Definition
public interface CommodityChannelIndex
Namespace: cAlgo.API.Indicators · Group: Indicators · Implements: StandardIndicator
Remarks
The Commodity Channel Index is used to determine overbought and oversold conditions relating to a symbol. The Commodity Channel Index can be used to forecast changes in price direction.
Examples
Example 1
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo
{
public partial class CommodityChannelIndexReferenceExample:Indicator
{
private CommodityChannelIndex _commodityChannelIndex;
protected override void Initialize()
{
_commodityChannelIndex = Indicators.CommodityChannelIndex(Periods);
}
public override void Calculate(int index)
{
// Display Result of Indicator
Result[index] = _commodityChannelIndex.Result[index];
}
}
}
import clr
clr.AddReference("cAlgo.API")
from cAlgo.API import *
class Test():
def initialize(self):
self.commodityChannelIndex = api.Indicators.CommodityChannelIndex(api.Periods)
def calculate(self, index):
api.Result[index] = self.commodityChannelIndex.Result[index]
{
"Parameters": [
{
"Name": "Periods",
"Type": "Integer",
"DefaultValue": 14
}
],
"LineOutputs": [
{
"Name": "Result",
"DisplayName": "Main"
}
]
}
Example 2
using cAlgo.API;
using cAlgo.API.Indicators;
namespace cAlgo.Robots
{
// This sample cBot shows how to use the Commodity Channel Index indicator
public partial class CommodityChannelIndexSample : Robot
{
private double _volumeInUnits;
private CommodityChannelIndex _commodityChannelIndex;
public Position[] BotPositions
{
get
{
return Positions.FindAll(Label);
}
}
protected override void OnStart()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
_commodityChannelIndex = Indicators.CommodityChannelIndex(14);
}
protected override void OnBar()
{
if (_commodityChannelIndex.Result.Last(1) > 100 && _commodityChannelIndex.Result.Last(2) <= 100)
{
ClosePositions(TradeType.Sell);
ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
else if (_commodityChannelIndex.Result.Last(1) < -100 && _commodityChannelIndex.Result.Last(2) >= -100)
{
ClosePositions(TradeType.Buy);
ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
}
private void ClosePositions(TradeType tradeType)
{
foreach (var position in BotPositions)
{
if (position.TradeType != tradeType) continue;
ClosePosition(position);
}
}
}
}
import clr
clr.AddReference("cAlgo.API")
# Import cAlgo API types
from cAlgo.API import *
# Import trading wrapper functions
from robot_wrapper import *
class CommodityChannelIndexSample():
def on_start(self):
self.volumeInUnits = api.Symbol.QuantityToVolumeInUnits(api.VolumeInLots)
self.commodityChannelIndex = api.Indicators.CommodityChannelIndex(14)
def on_bar_closed(self):
if self.commodityChannelIndex.Result.Last(0) > 100 and self.commodityChannelIndex.Result.Last(1) <= 100:
self.close_positions(TradeType.Sell)
api.ExecuteMarketOrder(TradeType.Buy, api.SymbolName, self.volumeInUnits, api.Label)
elif self.commodityChannelIndex.Result.Last(0) < -100 and self.commodityChannelIndex.Result.Last(1) >= -100:
self.close_positions(TradeType.Buy)
api.ExecuteMarketOrder(TradeType.Sell, api.SymbolName, self.volumeInUnits, api.Label)
def get_bot_positions(self):
return api.Positions.FindAll(api.Label)
def close_positions(self, tradeType):
for position in self.get_bot_positions():
if position.TradeType != tradeType:
continue
api.ClosePosition(position)
{
"AccessRights": "None",
"TimeZone": "UTC",
"Parameters": [
{
"Name": "VolumeInLots",
"DisplayName": "Volume (Lots)",
"Type": "Double",
"DefaultValue": 0.01
},
{
"Name": "StopLossInPips",
"DisplayName": "Stop Loss (Pips)",
"Type": "Double",
"DefaultValue": 10
},
{
"Name": "TakeProfitInPips",
"DisplayName": "Take Profit (Pips)",
"Type": "Double",
"DefaultValue": 10
},
{
"Name": "Label",
"Type": "String",
"DefaultValue": "Sample"
}
]
}
Properties
| Name | Description |
|---|---|
ResultDesktopCLICloudIndicatorDataSeries | Commodity Channel Index Result Series. |
Inherited members
From StandardIndicator: AddToChart, Symbol, TimeFrame, Bars