Replies

nguyendan81985
26 Oct 2018, 05:23

RE:

Panagiotis Charalampous said:

Hi arismac,

Thanks for posting in our forum! It is possible to program a cBot that will alert you on ema crossovers. The following resources might be helpful for you.

/api/reference/functions/hascrossedabove

/api/reference/functions/hascrossedbelow

/api/reference/internals/inotifications

Let me know if you need any additional help.

Best Regards,

Panagiotis

hi Panagiotis,

could you give me one example like: the last close price cross above EMA34 then Buy position, and last price cross below EMA34 then Sell position

thanks

 


@nguyendan81985

nguyendan81985
26 Oct 2018, 05:20

RE:

matt_graham_92@hotmail.com said:

Does anyone know where I can download a cbot for instance #2 mentioned above.. price close above ema, auto(bot) long, till price close below ema, auto(bot) close long, and then takes the short?

just copy and paste. hihi


@nguyendan81985

nguyendan81985
24 Oct 2018, 13:19

my coding as below, but it is not working.

 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class CCIROBOT : Robot
    {
        [Parameter(DefaultValue = 14)]
        public int cciPeriod { get; set; }


        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }


        private CommodityChannelIndex cci;
        private const string name = "CCIROBOT";

        protected override void OnStart()
        {
            cci = Indicators.CommodityChannelIndex(cciPeriod);

        }

        protected override void OnBar()
        {

            var longPos = Positions.Find(name, Symbol, TradeType.Buy);
            var shortPos = Positions.Find(name, Symbol, TradeType.Sell);

            if ((cci.Result.HasCrossedAbove(0.0, 1) && longPos == null))
            {
                if (shortPos != null)
                {
                    ClosePosition(shortPos);
                    ExecuteMarketOrder(TradeType.Buy, Symbol, VolumeInUnits, name);
                }

                Print("Open Buy");

                {
                    if (cci.Result.HasCrossedBelow(100.0, 1) && longPos != null)
                        ClosePosition(longPos);

                    Print("Closed Buy");
                }

            }
            else if ((cci.Result.HasCrossedAbove(0.0, 1) && longPos == null))
            {
                if (longPos != null)
                {
                    ClosePosition(longPos);
                    ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, name);
                }

                Print("Open Sell");

                {
                    if (cci.Result.HasCrossedAbove(-100.0, 1) && shortPos != null)
                        ClosePosition(longPos);

                    Print("Closed Sell");
                }
            }
        }


        private long VolumeInUnits
        {
            get { return Symbol.QuantityToVolume(Quantity); }
        }


    }



}

 


@nguyendan81985