Sample PARABOLIC SAR free

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

 

 

 

Warning! Executing the following cBot may result in loss of funds. Use it at your own risk.
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgo
´╗┐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
        }
    }
}
Comments
0