Any code for executing trades after the Bid price crosses the SMA by a number of pips?

Created at 04 Aug 2020, 17:30
PU

puppiebullet1

Joined 11.07.2020

Any code for executing trades after the Bid price crosses the SMA by a number of pips?
04 Aug 2020, 17:30



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 ULTIMATECBOT : Robot
    {
        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("Source", Group = "SMA")]
        public DataSeries Source { get; set; }

        [Parameter("Periods", Group = "SMA", DefaultValue = 20)]
        public int Periods { get; set; }

        private SimpleMovingAverage sma;

        protected override void OnStart()
        {
            sma = Indicators.SimpleMovingAverage(Source, Periods);
        }

        protected override void OnTick()
        {
            var bMA = sma.Result.LastValue;
            double op = bMA + 10 * Symbol.TickSize;
            double pp = bMA - 10 * Symbol.TickSize;
            if (Symbol.Bid == op)
            {
                Close(TradeType.Buy);
                Open(TradeType.Sell);
            }
            else if (Symbol.Bid == pp)
            {
                Close(TradeType.Sell);
                Open(TradeType.Buy);
            }
        }
    }
}


@puppiebullet1