following bot free

by al-n in category Trend at 03/08/2022
Description
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 TrailingStopLossSample : Robot
    {
        [Parameter("VolumeInLots", DefaultValue = 1)]
        public double VolumeInLots { get; set; }
        [Parameter("Buy")]
        public bool Buy { get; set; }
        [Parameter("Stop Loss", DefaultValue = 5)]
        public double StopLoss { get; set; }
        [Parameter("Trigger When Gaining", DefaultValue = 1)]
        public double TriggerWhenGaining { get; set; }
        [Parameter("Trailing Stop Loss Distance", DefaultValue = 1)]
        public double TrailingStopLossDistance { get; set; }
        [Parameter("Step (pips)", DefaultValue = 5)]
        public double Step { get; set; }

        private double _highestGain;
        private bool _isTrailing;



        protected override void OnStart()
        {
        }



        protected override void OnTick()
        {
            // Schaut nach ob Positionen offen sind =)
            if (Positions.Count == 0)
            {

                //Execute a market order based on the direction parameter
                ExecuteMarketOrder(Buy ? TradeType.Buy : TradeType.Sell, Symbol, VolumeInLots * 100000, "SampleTrailing", StopLoss, null);
                //Set the position's highest gain in pips
                _highestGain = Positions[0].Pips;

            }

            {
                var position = Positions.Find("SampleTrailing");

                if (position == null)
                {
                    Stop();
                    return;
                }
                //If the trigger is reached, the robot starts trailing
                if (position.Pips >= TriggerWhenGaining)
                {
                    //Based on the position's direction, we calculate the new stop loss price and we modify the position
                    if (position.TradeType == TradeType.Buy)
                    {
                        var newSLprice = Symbol.Ask - (Symbol.PipSize * TrailingStopLossDistance);
                        if (newSLprice > position.StopLoss)
                        {
                            ModifyPosition(position, newSLprice, null);
                        }
                    }
                    else
                    {
                        var newSLprice = Symbol.Bid + (Symbol.PipSize * TrailingStopLossDistance);
                        if (newSLprice < position.StopLoss)
                        {
                            ModifyPosition(position, newSLprice, null);
                        }
                    }
                    TriggerWhenGaining += Step;
                }
            }
        }

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

 

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
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class TrailingStopLossSample : Robot
    {
        [Parameter("VolumeInLots", DefaultValue = 1)]
        public double VolumeInLots { get; set; }
        [Parameter("Buy")]
        public bool Buy { get; set; }
        [Parameter("Stop Loss", DefaultValue = 5)]
        public double StopLoss { get; set; }
        [Parameter("Trigger When Gaining", DefaultValue = 1)]
        public double TriggerWhenGaining { get; set; }
        [Parameter("Trailing Stop Loss Distance", DefaultValue = 1)]
        public double TrailingStopLossDistance { get; set; }
        [Parameter("Step (pips)", DefaultValue = 5)]
        public double Step { get; set; }

        private double _highestGain;
        private bool _isTrailing;



        protected override void OnStart()
        {
        }



        protected override void OnTick()
        {
            // Schaut nach ob Positionen offen sind =)
            if (Positions.Count == 0)
            {

                //Execute a market order based on the direction parameter
                ExecuteMarketOrder(Buy ? TradeType.Buy : TradeType.Sell, Symbol, VolumeInLots * 100000, "SampleTrailing", StopLoss, null);
                //Set the position's highest gain in pips
                _highestGain = Positions[0].Pips;

            }

            {
                var position = Positions.Find("SampleTrailing");

                if (position == null)
                {
                    Stop();
                    return;
                }
                //If the trigger is reached, the robot starts trailing
                if (position.Pips >= TriggerWhenGaining)
                {
                    //Based on the position's direction, we calculate the new stop loss price and we modify the position
                    if (position.TradeType == TradeType.Buy)
                    {
                        var newSLprice = Symbol.Ask - (Symbol.PipSize * TrailingStopLossDistance);
                        if (newSLprice > position.StopLoss)
                        {
                            ModifyPosition(position, newSLprice, null);
                        }
                    }
                    else
                    {
                        var newSLprice = Symbol.Bid + (Symbol.PipSize * TrailingStopLossDistance);
                        if (newSLprice < position.StopLoss)
                        {
                            ModifyPosition(position, newSLprice, null);
                        }
                    }
                    TriggerWhenGaining += Step;
                }
            }
        }

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

sila160222 - August 12, 2022 @ 09:57

I recently came across your blog and have been reading along. I thought I would leave my first comment. I don’t know what to say except that I have enjoyed reading. Nice blog, I will keep visiting this blog very often. Octordle

osamashoukat48 - August 12, 2022 @ 14:56

Stainless steel spring manufacturers and suppliers necessitate a unique design based on mechanical and strength calculations.

lanchris004 - August 19, 2022 @ 21:23

I do have the same problem and same question. looking for the solution and order panel should be more user friendly and option to synchronize the Order Panel. 

 

tg macro not working

supertechnologies18 - August 26, 2022 @ 09:41

I think that the following bot is the best. I like to follow the people who are doing great things in the world. I appreciate their work, and I try to do better than them. But I am not so good at it yet, so I don't know if this will work for me. A good bot will even ask you if it should follow other accounts on Twitter, like tech blogs or news sites or politicians' official accounts. Visit this https://masterbundles.com/templates/presentations/powerpoint/webinar/ site to download webinar templates. That way you can see what their followers are like, and whether they deserve your attention as well (after all, if the account has a lot of followers already then it probably does).

jennikim266 - August 30, 2022 @ 10:20

This is an excellent article. This is, in my opinion, one of the best posts ever written. Your work is excellent and inspiring. Thank you very much.This is an excellent article.  rocket bot royale game

williamjameschar - August 31, 2022 @ 15:39

Web development, also known as website development, refers to the tasks involved in the creation, construction, and maintenance of websites and web applications that are accessible via a browser. I'm familiar with development because I work at a logoistic agency that also creates websites.

yangruflo - November 22, 2022 @ 06:52

From August, surprised it didn't archived unlike other posts made earlier.
https://www.carpetcleaningdunedinpros.kiwi/

0