Coding almost finished strategy

Created at 02 Mar 2020
DA

david.sanchez

Joined 07.02.2020

Status

Open


Budget

100.00 USD


Payment Method

Direct Payment

Job Description

Hi,

Somehow when I run the cbot below it does not trade, although there are no error messages.

Can you make this cbot work? 

If you need more information, please send an E-Mail at: david.sanchez@hotmail.ch

using System;
using System.Linq;
using System.Collections.Generic;
using cAlgo.API;
using cAlgo.API.Requests;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Arbitrage1 : Robot
    {


        private BollingerBands boll;

        protected override void OnStart()
        {

            var ticks = MarketData.GetTicks("AUDUSD");
            var series = CreateDataSeries();
            int i = 0;
            foreach (var tick in ticks)
            {
                series[i] = tick.Ask;
                i++;
            }

            var ticks2 = MarketData.GetTicks("EURUSD");
            var series2 = CreateDataSeries();
            int t = 0;
            foreach (var tick in ticks2)
            {
                series2[t] = tick.Bid;
                t++;
            }

            var Spread = CreateDataSeries();

            for (int X = 0; X < 10; X++)
            {

                Spread[X] = series[X] - series2[X];

            }

            boll = Indicators.BollingerBands(Spread, 10, 1, MovingAverageType.Simple);

        }

        protected override void OnTick()
        {

            var ticks = MarketData.GetTicks("AUDUSD");
            var series = CreateDataSeries();
            int i = 0;
            foreach (var tick in ticks)
            {
                series[i] = tick.Ask;
                i++;
            }

            var ticks2 = MarketData.GetTicks("EURUSD");
            var series2 = CreateDataSeries();
            int t = 0;
            foreach (var tick in ticks)
            {
                series2[t] = tick.Bid;
                t++;
            }

            var Spread = CreateDataSeries();

            for (int X = 0; X < 10; X++)
            {

                Spread[X] = series[X] - series2[X];

            }

            boll = Indicators.BollingerBands(Spread, 10, 1, MovingAverageType.Simple);



            if (boll.Top[0] <= Spread[0])
            {

                var openPositions1 = Positions.FindAll("Arbitrage1", "AUDUSD");

                foreach (var order in openPositions1)
                {
                    ClosePosition(order);
                }

                var openPositions2 = Positions.FindAll("Arbitrage1", "EURUSD");

                foreach (var order in openPositions2)
                {
                    ClosePosition(order);
                }

                ExecuteMarketOrder(TradeType.Sell, "AUDUSD", 100000, "Arbitrage1");
                ExecuteMarketOrder(TradeType.Buy, "EURUSD", 100000, "Arbitrage1");

            }

            else if (boll.Bottom[0] >= Spread[0])
            {

                var openPositions1 = Positions.FindAll("Arbitrage1", "AUDUSD");

                foreach (var order in openPositions1)
                {
                    ClosePosition(order);
                }

                var openPositions2 = Positions.FindAll("Arbitrage1", "EURUSD");

                foreach (var order in openPositions2)
                {
                    ClosePosition(order);
                }

                ExecuteMarketOrder(TradeType.Buy, "AUDUSD", 100000);
                ExecuteMarketOrder(TradeType.Sell, "EURUSD", 100000);
            }

        }
    }
}

 

Comments
Log in to add a comment.
bienve.pf's avatar
bienve.pf · 4 years ago

Hi. I can do that. Write me and tell me what do you need exactly.

Email: Bienve.pf@hotmail.com 

Whatsapp: +34654115547

Regards