Replies

stahur
10 May 2017, 23:07

RE:

lucian said:

You can start with this code:

 

 

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 stahur : Robot
    {
        [Parameter("Source")]
        public DataSeries SourceSeries { get; set; }
        [Parameter("Label", DefaultValue = "MA")]
        public string label { get; set; }

        [Parameter("MA Periods", DefaultValue = 14)]
        public int Periods { get; set; }
        [Parameter("MA type")]
        public MovingAverageType matype { get; set; }


        [Parameter("Stop Loss", DefaultValue = 10)]
        public int SL { get; set; }
        [Parameter("Take Profit", DefaultValue = 10)]
        public double TP { get; set; }
        [Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        private MovingAverage ma;



        protected override void OnStart()
        {

            ma = Indicators.MovingAverage(SourceSeries, Periods, matype);


        }

        protected override void OnBar()
        {
           

            if (MarketSeries.Close.LastValue < ma.Result.LastValue)
            {
                ExecuteMarketOrder(TradeType.Sell, Symbol, VolumeInUnits, label, SL, TP);

            }


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

 

Thank you, that was very hepled:)


@stahur