Category Trend  Published on 19/08/2020

Sample PARABOLIC SAR

Description

1.Buy order if the parabolic SAR of the previous bar is below the candlestick.

2. A Sell order will be created if the parabolic SAR of the previous bar is above the candlestick.  

3. If SAR change position  from below to above or vice versa Close position

 

 

 


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

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class DragonPSAR : Robot
    {
        [Parameter("Min AF", DefaultValue = 0.02, MinValue = 0)]
        public double MinAF { get; set; }

        [Parameter("Max AF", DefaultValue = 0.2, MinValue = 0)]
        public double MaxAF { get; set; }

        [Parameter("Initial Volume Percent", DefaultValue = 1, MinValue = 0)]
        public double InitialVolumePercent { get; set; }

        private ParabolicSAR parabolicSAR;

        protected override void OnStart()
        {
            parabolicSAR = Indicators.ParabolicSAR(MinAF, MaxAF);
        }

        protected override void OnBar()
        {
            var volumne = Math.Floor(Account.Balance * 10 * InitialVolumePercent / 1000) * 1000;

            var position = Positions.Find("DragonPSAR");
            if (parabolicSAR.Result.Last(1) < Bars.Last(1).Close)
            {
                if (position != null && position.TradeType == TradeType.Sell)
                {
                    position.Close();
                }

                if (Positions.Count == 0)
                {
                    ExecuteMarketOrder(TradeType.Buy, Symbol.Name, volumne, "DragonPSAR", 0, 0);
                }

            }
            if (parabolicSAR.Result.Last(1) > Bars.Last(1).Close)
            {
                if (position != null && position.TradeType == TradeType.Buy)
                {
                    position.Close();
                }

                if (Positions.Count == 0)
                {
                    ExecuteMarketOrder(TradeType.Sell, Symbol.Name, volumne, "DragonPSAR", 0, 0);
                }


            }
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}


nghiand.amz's avatar
nghiand.amz

Joined on 06.07.2020

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: DragonPSAR.algo
  • Rating: 0
  • Installs: 1963
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
RI
rickbeeke84 · 3 years ago

Is it possible with a stoploss and a takeprofit of a view pips?

RI
rickbeeke84 · 3 years ago

Is it possible with a stoploss and a takeprofit of a view pips?