Help with creating a cBot. Parabolic SAR

Created at 08 Mar 2024, 00:01
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!
WassTima's avatar

WassTima

Joined 07.03.2024

Help with creating a cBot. Parabolic SAR
08 Mar 2024, 00:01


Hi I am fairly new to this and I'm very keen on creating a cBot to create trades for me and have done well so far. However I need help with my code if anyone can please help? I have created a cBot to enter a trade when the parabolic SAR is touched meaning the candle is reversing the opposite way. However sometimes the trade starts late and now when the SAR is touched immediately which is what I want (for scalping purposes). Can anyone help?


@WassTima
Replies

firemyst
10 Mar 2024, 03:03

Why don't you post the code you have if you expect any help without having to pay someone?

 


@firemyst

WassTima
10 Mar 2024, 15:03 ( Updated at: 10 Mar 2024, 16:39 )

RE: Help with creating a cBot. Parabolic SAR

firemyst said: 

Why don't you post the code you have if you expect any help without having to pay someone?

 

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    // This cBot enters a position when the price reaches the Parabolic SAR value
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ParabolicSAREntry : Robot
    {
        private double _volumeInUnits;
        private ParabolicSAR _parabolicSAR;

        [Parameter("Volume (Lots)", DefaultValue = 0.1)]
        public double VolumeInLots { get; set; }

        [Parameter("Stop Loss (Pips)", DefaultValue = 150)]
        public double StopLossInPips { get; set; }

        [Parameter("Take Profit (Pips)", DefaultValue = 20)]
        public double TakeProfitInPips { get; set; }

        [Parameter("Label", DefaultValue = "ParabolicSAREntry")]
        public string Label { get; set; }

        protected override void OnStart()
        {
            _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
            _parabolicSAR = Indicators.ParabolicSAR(0.02, 0.2);
        }

        protected override void OnTick()
        {
            // Check if the current price has reached the Parabolic SAR value
            if (Symbol.Ask < _parabolicSAR.Result.LastValue)
            {
                // If the price is below the Parabolic SAR, enter a Buy position
                ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
            else if (Symbol.Bid > _parabolicSAR.Result.LastValue)
            {
                // If the price is above the Parabolic SAR, enter a Sell position
                ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
        }
    }
}

 

 

I would like the buy/sell position to start as soon as the oposite SAR is touched rather than wait and sometimes it opens a position at a random point?

 

Thank you in advance


@WassTima

WassTima
10 Mar 2024, 23:17 ( Updated at: 10 Mar 2024, 23:18 )

RE: RE: Help with creating a cBot. Parabolic SAR

Please can someone help?

 

 

firemyst said: 

Why don't you post the code you have if you expect any help without having to pay someone?

 

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    // This cBot enters a position when the price reaches the Parabolic SAR value
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ParabolicSAREntry : Robot
    {
        private double _volumeInUnits;
        private ParabolicSAR _parabolicSAR;

        [Parameter("Volume (Lots)", DefaultValue = 0.1)]
        public double VolumeInLots { get; set; }

        [Parameter("Stop Loss (Pips)", DefaultValue = 150)]
        public double StopLossInPips { get; set; }

        [Parameter("Take Profit (Pips)", DefaultValue = 20)]
        public double TakeProfitInPips { get; set; }

        [Parameter("Label", DefaultValue = "ParabolicSAREntry")]
        public string Label { get; set; }

        protected override void OnStart()
        {
            _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
            _parabolicSAR = Indicators.ParabolicSAR(0.02, 0.2);
        }

        protected override void OnTick()
        {
            // Check if the current price has reached the Parabolic SAR value
            if (Symbol.Ask < _parabolicSAR.Result.LastValue)
            {
                // If the price is below the Parabolic SAR, enter a Buy position
                ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
            else if (Symbol.Bid > _parabolicSAR.Result.LastValue)
            {
                // If the price is above the Parabolic SAR, enter a Sell position
                ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
        }
    }
}

 

 

I would like the buy/sell position to start as soon as the oposite SAR is touched rather than wait and sometimes it opens a position at a random point?

 

Thank you in advance

 


@WassTima

WassTima
23 Mar 2024, 03:16

RE: RE: Help with creating a cBot. Parabolic SAR

 

Such an amazing and helpful community 

 

 

WassTima said: 

firemyst said: 

Why don't you post the code you have if you expect any help without having to pay someone?

 

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    // This cBot enters a position when the price reaches the Parabolic SAR value
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ParabolicSAREntry : Robot
    {
        private double _volumeInUnits;
        private ParabolicSAR _parabolicSAR;

        [Parameter("Volume (Lots)", DefaultValue = 0.1)]
        public double VolumeInLots { get; set; }

        [Parameter("Stop Loss (Pips)", DefaultValue = 150)]
        public double StopLossInPips { get; set; }

        [Parameter("Take Profit (Pips)", DefaultValue = 20)]
        public double TakeProfitInPips { get; set; }

        [Parameter("Label", DefaultValue = "ParabolicSAREntry")]
        public string Label { get; set; }

        protected override void OnStart()
        {
            _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
            _parabolicSAR = Indicators.ParabolicSAR(0.02, 0.2);
        }

        protected override void OnTick()
        {
            // Check if the current price has reached the Parabolic SAR value
            if (Symbol.Ask < _parabolicSAR.Result.LastValue)
            {
                // If the price is below the Parabolic SAR, enter a Buy position
                ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
            else if (Symbol.Bid > _parabolicSAR.Result.LastValue)
            {
                // If the price is above the Parabolic SAR, enter a Sell position
                ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
        }
    }
}

 

 

I would like the buy/sell position to start as soon as the oposite SAR is touched rather than wait and sometimes it opens a position at a random point?

 

Thank you in advance

 


@WassTima

WassTima
23 Mar 2024, 03:16

RE: RE: Help with creating a cBot. Parabolic SAR

 

Such an amazing and helpful community 

 

 

WassTima said: 

firemyst said: 

Why don't you post the code you have if you expect any help without having to pay someone?

 

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    // This cBot enters a position when the price reaches the Parabolic SAR value
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class ParabolicSAREntry : Robot
    {
        private double _volumeInUnits;
        private ParabolicSAR _parabolicSAR;

        [Parameter("Volume (Lots)", DefaultValue = 0.1)]
        public double VolumeInLots { get; set; }

        [Parameter("Stop Loss (Pips)", DefaultValue = 150)]
        public double StopLossInPips { get; set; }

        [Parameter("Take Profit (Pips)", DefaultValue = 20)]
        public double TakeProfitInPips { get; set; }

        [Parameter("Label", DefaultValue = "ParabolicSAREntry")]
        public string Label { get; set; }

        protected override void OnStart()
        {
            _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
            _parabolicSAR = Indicators.ParabolicSAR(0.02, 0.2);
        }

        protected override void OnTick()
        {
            // Check if the current price has reached the Parabolic SAR value
            if (Symbol.Ask < _parabolicSAR.Result.LastValue)
            {
                // If the price is below the Parabolic SAR, enter a Buy position
                ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
            else if (Symbol.Bid > _parabolicSAR.Result.LastValue)
            {
                // If the price is above the Parabolic SAR, enter a Sell position
                ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
        }
    }
}

 

 

I would like the buy/sell position to start as soon as the oposite SAR is touched rather than wait and sometimes it opens a position at a random point?

 

Thank you in advance

 


@WassTima

PanagiotisCharalampous
23 Mar 2024, 05:56

Hi there,

Your code logic is wrong. Your code does not do the below

I would like the buy/sell position to start as soon as the oposite SAR is touched

Your code just places trades when the price is above or below the current psar value, which is always true. You should check for crosses instead e.g. the close price being above while the open price is below.

Best regards,

Panagiotis 


@PanagiotisCharalampous