Adaptive Center of Gravity Robot free

by kkostaki in category Trend at 24/08/2012
Description

Adaptive Center of Gravity Robot. Based on Adaptive CG Indicator. Similar to Stochastic Center of Gravity.
The algorithm references Cycle Period Indicator.

 

/algos/indicators/show/128

Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgo
//#reference: ..\Indicators\AdaptiveCG.algo
using cAlgo.API;
using cAlgo.Indicators;

namespace cAlgo.Robots
{
    [Robot()]
    public class AdaptiveCGRobot : Robot
    {
        private AdaptiveCG _adaptiveCG;
        private Position _position;

        [Parameter(DefaultValue = 10000, MinValue = 0)]
        public int Volume { get; set; }

        [Parameter(DefaultValue = 0.07)]
        public double Alpha { get; set; }

        protected override void OnStart()
        {
            _adaptiveCG = Indicators.GetIndicator<AdaptiveCG>(Alpha);
        }

        protected override void OnBar()
        {
            if (Trade.IsExecuting)
                return;

            bool isLongPositionOpen = _position != null && _position.TradeType == TradeType.Buy;
            bool isShortPositionOpen = _position != null && _position.TradeType == TradeType.Sell;

            if (_adaptiveCG.Result.HasCrossedAbove(_adaptiveCG.Trigger, 0) && !isLongPositionOpen)
            {
                ClosePosition();
                Buy();
            }
            if (_adaptiveCG.Result.HasCrossedBelow(_adaptiveCG.Trigger, 0) && !isShortPositionOpen)
            {
                ClosePosition();
                Sell();
            }

        }

        private void ClosePosition()
        {
            if (_position != null)
            {
                Trade.Close(_position);
                _position = null;
            }
        }

        private void Buy()
        {
            Trade.CreateBuyMarketOrder(Symbol, Volume);
        }

        private void Sell()
        {
            Trade.CreateSellMarketOrder(Symbol, Volume);
        }

        protected override void OnPositionOpened(Position openedPosition)
        {
            _position = openedPosition;
        }


    }
}
Comments

abtraderdemo - August 13, 2013 @ 23:33

where is source of adaptiveCG Indicators

 

0