Topics
26 Mar 2016, 19:49
 3512
 4
Replies

badger.cook
17 Mar 2016, 13:50

Sorry for the delay. I used (0) and (1) because I saw it on another robot based on MA and EMA, and which was working.

What I want to do here is to create a kind of "index" that moves with the bar return of the currency. Based on the value of the two indices calculated by the robot (one for EURUSD and one for USDCHF), I want to make buy and sell orders for these two currency pairs.

I first have no idea how to create the "indices" and second have no idea how I could specify I want the last value of the index or the value 1 or 2 bars ago. 

Could somebody help with that ? 

Thanks a lot,

B.


@badger.cook

badger.cook
15 Mar 2016, 13:35

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

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class MacdBot : Robot
    {

	[Indicator(IsOverlay = false, TimeZone = TimeZones.UTC, ScalePrecision = 5)]

        [Parameter("Source EURUSD")]
        public DataSeries Source1 { get; set; }

        [Parameter("Source USDCHF")]
        public DataSeries Source2 { get; set; }

	[Parameter(DefaultValue = 1)]
	public int Period { get; set; }

        [Parameter("Take Profit (pips)", DefaultValue = 5)]
        public int TakeProfit { get; set; }

        [Parameter("Stop Loss (pips)", DefaultValue = 5)]
        public int StopLoss { get; set; }


	private PriceROC priceROCEURUSD;
	private PriceROC priceROCUSDCHF;


        private const string label = "BOT";


        protected override void OnStart()
        {

	m1EURUSD = MarketData.GetSeries(Source1, TimeFrame.Minute1);
	m1USDCHF = MarketData.GetSeries(Source2, TimeFrame.Minute1);

    	priceROCEURUSD = Indicators.PriceROC(Source1, Period);
    	priceROCUSDCHF = Indicators.PriceROC(Source2, Period);

        }


	public override void Calculate(int index)
        {

	ResultEURUSD[index] = (1 + priceROCEURUSD.Result.Last(0)) * 100
	ResultUSDCHF[index] = (1 + priceROCUSDCHF.Result.Last(0)) * 100

        }


        protected override void OnBar()
        {

            var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
            var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);


            if (ResultEURUSD[index].Result(0) > ResultUSDCHF[index].Result(0) && ResultEURUSD[index].Result(1) < ResultUSDCHF[index].Result(1))
            {
                ExecuteMarketOrder(TradeType.Buy, Symbol1);
                ExecuteMarketOrder(TradeType.Sell, Symbol2);
            }

            if (ResultEURUSD[index].Result(0) < ResultUSDCHF[index].Result(0) && ResultEURUSD[index].Result(1) > ResultUSDCHF[index].Result(1))
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol1);
                ExecuteMarketOrder(TradeType.Buy, Symbol2);
            }


        }

    }
}

This is what I currently have but I'm sure I'm missing something. Thanks for your help.


@badger.cook

badger.cook
26 Feb 2016, 10:42

RE: RE:

croucrou said:

See this:

/forum/calgo-reference-samples/543

 

Exactly what I needed ! Thanks a lot !


@badger.cook