new bar close under movingaverage

Created at 09 May 2017, 13:30
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
ST

stahur

Joined 24.04.2016

new bar close under movingaverage
09 May 2017, 13:30


Please help me, How write line " new bar close under movingaverage then open sell position

 

please, please please


@stahur
Replies

... Deleted by UFO ...

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