Category Other  Published on 11/04/2021

Risk/Reward Management 2.0

Description

This is the new version of the cBot that I created before! In this new version, it can set multiple take profit points and auto-detects them, and it can also set the break-even, let me show you the new feature as below:

 

Auto Take Profit
There is a new button for “Auto Take Profit” as below:

 

It provide 3 take profit steps as below:

You need to set the take profit 1 and then set the take profit 2 and then 3, it will step by step to execute the take profit with the condition what you set. There are two parameters that needs to set, first is the percentage of the total profit that will be taken, the second is the condition value, there are two type of the condition:

“Percent of Total TP” : That’s mean if the current profit reach the percent of total profit then will execute the take profit action

“Price”: It will take profit when the price reach the setting value

For example:

  1. set take profit 1 value to 50% at 60 with Percent of Total TP
  2. set take profit 2 value to 80% at 1.6175 with price

Then the cBot will take profit 1 when the order profit reach 60% of total profit, and colse the 50% position of the order

And then it will take profit 2 when the price reach 1.6175, and colse the 80% remain position of the order

Set Break Even

If enable this, it will auto set the break even when the condition reach it. For example:

set break even at 50 with percent of total TP

Then the cBot will auto set the stop loss to break even(it will include the spread) when the current profit reach 50% of total profit

After you finish the settings, you can start the take profit, but the last thing that you must input the order lable for trace the take profit action, if you create an order with this cBot, it will auto get the order label, otherwise you need to find the order label in position panel:

if you can see the label column, just right click the position column and show it out

After that, click the green button to Start Take Profit, after start it, you can stop in anytime

Set Default Values by parameter

There are some new parameters in cBot settings, you can set the default values in here so that you don’t need to set it every time when you stop/start the cBot

You can set all of the default value for auto take profit function, if the value is 0, then this item will be in-active by default.

Import

Please note that if you stop the cBot, all of the take profit (break even) settings will be stop and the status will be reset, but if you just stop the take profit, you can start it in anytime and it will continue to work.

 

Download as below: 

Now! You can use the below coupon to get 25% discount!

CODERBLOG-BOT

 

 

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


namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class CoderBlogcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        Border MainBorder;

        protected override void OnStart()
        {
            Init();
        }

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

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

        private void Init()
        {
            StackPanel mainPanel = new StackPanel();


            #region Header
            var headerBorder = new Border 
            {
                BorderThickness = "0 0 0 1",
                Style = Styles.CreateCommonBorderStyle()
            };
            var headerGrid = new Grid(1, 2);
            headerGrid.Columns[1].SetWidthInPixels(60);

            var title = new TextBlock 
            {
                Text = "RS Management (by Winson)",
                Margin = "10 7",
                FontSize = 12,
                Style = Styles.CreateHeaderStyle()
            };
            headerGrid.AddChild(title, 0, 0);

            var closeBtn = new ToggleButton 
            {
                Text = "✖",
                Width = 55,
                Height = 20,
                FontSize = 8,
                Margin = new Thickness(0, 5, 5, 5)
            };
            closeBtn.Click += CloseBtn_Click;
            headerGrid.AddChild(closeBtn, 0, 1);

            headerBorder.Child = headerGrid;

            mainPanel.AddChild(headerBorder);
            #endregion


            #region Content Panel
            var contentBorder = new Border 
            {
                BorderThickness = "0 0 0 1",
                //Height = 340,
                Style = Styles.CreateCommonBorderStyle()
            };
            //var contentGrid = new Grid(1, 2);
            StackPanel contentPanel = new StackPanel();
            contentPanel.Orientation = Orientation.Vertical;
            #endregion


            #region Info Row
            StackPanel InfoRow = new StackPanel();
            InfoRow.Orientation = Orientation.Horizontal;
            InfoRow.VerticalAlignment = VerticalAlignment.Center;
            //InfoRow.HorizontalAlignment = HorizontalAlignment.Center;
            var lbDesc = new TextBlock 
            {
                Text = "It is not possible to download the cBot from the cTrader website. \r\n\r\nPlease go to visit us at \r\n\r\nhttps://www.coderblog.in/rs-bot",
                Margin = "10 7",
                Padding = "10",
                FontSize = 14,
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Style = Styles.CreateHeaderStyle()
            };
            InfoRow.AddChild(lbDesc);

            contentPanel.AddChild(InfoRow);
            #endregion

            #region Button Row
            StackPanel buttonRow = new StackPanel();
            buttonRow.Orientation = Orientation.Horizontal;
            buttonRow.HorizontalAlignment = HorizontalAlignment.Center;
            buttonRow.HorizontalAlignment = HorizontalAlignment.Center;
            var btn = new Button 
            {
                Text = "OK",
                Height = 20,
                Width = 200,
                FontSize = 12,
                //Margin = new Thickness(80, 10, 50, 10),
                Style = Styles.CreateButtonStyle(Color.FromHex("#009345"), Color.FromHex("#10A651"))
            };
            btn.Click += Btn_Click;
            buttonRow.AddChild(btn);

            contentPanel.AddChild(buttonRow);
            #endregion


            contentBorder.Child = contentPanel;
            mainPanel.AddChild(contentBorder);


            MainBorder = new Border 
            {
                VerticalAlignment = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Center,
                Style = Styles.CreatePanelBackgroundStyle(),
                //Margin = "20 40 20 20",
                Margin = new Thickness(20, 40, 20, 20),
                Width = 430,
                Height = 200,
                Child = mainPanel
            };


            Chart.AddControl(MainBorder);
        }

        private void CloseBtn_Click(ToggleButtonEventArgs obj)
        {
            MainBorder.IsVisible = false;
        }

        private void Btn_Click(ButtonClickEventArgs obj)
        {
            MainBorder.IsVisible = false;
        }


    }

    public static class Styles
    {
        public static Style CreatePanelBackgroundStyle()
        {
            var style = new Style();
            style.Set(ControlProperty.CornerRadius, 3);
            style.Set(ControlProperty.BackgroundColor, GetColorWithOpacity(Color.FromHex("#292929"), 0.85m), ControlState.DarkTheme);
            style.Set(ControlProperty.BackgroundColor, GetColorWithOpacity(Color.FromHex("#FFFFFF"), 0.85m), ControlState.LightTheme);
            style.Set(ControlProperty.BorderColor, Color.FromHex("#3C3C3C"), ControlState.DarkTheme);
            style.Set(ControlProperty.BorderColor, Color.FromHex("#C3C3C3"), ControlState.LightTheme);
            style.Set(ControlProperty.BorderThickness, new Thickness(1));

            return style;
        }

        public static Style CreateCommonBorderStyle()
        {
            var style = new Style();
            style.Set(ControlProperty.BorderColor, GetColorWithOpacity(Color.FromHex("#FFFFFF"), 0.12m), ControlState.DarkTheme);
            style.Set(ControlProperty.BorderColor, GetColorWithOpacity(Color.FromHex("#000000"), 0.12m), ControlState.LightTheme);
            return style;
        }

        public static Style CreateHeaderStyle()
        {
            var style = new Style();
            style.Set(ControlProperty.ForegroundColor, GetColorWithOpacity("#FFFFFF", 0.70m), ControlState.DarkTheme);
            style.Set(ControlProperty.ForegroundColor, GetColorWithOpacity("#000000", 0.65m), ControlState.LightTheme);
            return style;
        }

        public static Style CreateInputStyle()
        {
            var style = new Style(DefaultStyles.TextBoxStyle);
            style.Set(ControlProperty.BackgroundColor, Color.FromHex("#1A1A1A"), ControlState.DarkTheme);
            style.Set(ControlProperty.BackgroundColor, Color.FromHex("#111111"), ControlState.DarkTheme | ControlState.Hover);
            style.Set(ControlProperty.BackgroundColor, Color.FromHex("#E7EBED"), ControlState.LightTheme);
            style.Set(ControlProperty.BackgroundColor, Color.FromHex("#D6DADC"), ControlState.LightTheme | ControlState.Hover);
            style.Set(ControlProperty.CornerRadius, 3);
            return style;
        }

        public static Style CreateBuyButtonStyle()
        {
            return CreateButtonStyle(Color.FromHex("#009345"), Color.FromHex("#10A651"));
        }

        public static Style CreateSellButtonStyle()
        {
            return CreateButtonStyle(Color.FromHex("#F05824"), Color.FromHex("#FF6C36"));
        }

        public static Style CreateCloseButtonStyle()
        {
            return CreateButtonStyle(Color.FromHex("#F05824"), Color.FromHex("#FF6C36"));
        }

        public static Style CreateButtonStyle(Color color, Color hoverColor)
        {
            var style = new Style(DefaultStyles.ButtonStyle);
            style.Set(ControlProperty.BackgroundColor, color, ControlState.DarkTheme);
            style.Set(ControlProperty.BackgroundColor, color, ControlState.LightTheme);
            style.Set(ControlProperty.BackgroundColor, hoverColor, ControlState.DarkTheme | ControlState.Hover);
            style.Set(ControlProperty.BackgroundColor, hoverColor, ControlState.LightTheme | ControlState.Hover);
            style.Set(ControlProperty.ForegroundColor, Color.FromHex("#FFFFFF"), ControlState.DarkTheme);
            style.Set(ControlProperty.ForegroundColor, Color.FromHex("#FFFFFF"), ControlState.LightTheme);
            return style;
        }


        public static Style CreateToggleButtonStyle(Color color, Color checkedColor)
        {
            var style = new Style(DefaultStyles.ToggleButtonStyle);
            style.Set(ControlProperty.BackgroundColor, color, ControlState.DarkTheme);
            style.Set(ControlProperty.BackgroundColor, color, ControlState.LightTheme);
            style.Set(ControlProperty.BackgroundColor, checkedColor, ControlState.DarkTheme | ControlState.Checked);
            style.Set(ControlProperty.BackgroundColor, checkedColor, ControlState.LightTheme | ControlState.Checked);
            style.Set(ControlProperty.BackgroundColor, checkedColor, ControlState.DarkTheme | ControlState.Hover);
            style.Set(ControlProperty.BackgroundColor, checkedColor, ControlState.LightTheme | ControlState.Hover);
            style.Set(ControlProperty.ForegroundColor, Color.FromHex("#FFFFFF"), ControlState.DarkTheme);
            style.Set(ControlProperty.ForegroundColor, Color.FromHex("#FFFFFF"), ControlState.LightTheme);
            return style;
        }

        private static Color GetColorWithOpacity(Color baseColor, decimal opacity)
        {
            var alpha = (int)Math.Round(byte.MaxValue * opacity, MidpointRounding.AwayFromZero);
            return Color.FromArgb(alpha, baseColor);
        }
    }

}


WI
winsonet

Joined on 03.01.2021

  • Distribution: Paid
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: CoderBlog cBot.algo
  • Rating: 0
  • Installs: 844
  • Modified: 13/10/2021 09:55
Comments
Log in to add a comment.
NOTGeorgeSoros's avatar
NOTGeorgeSoros · 10 months ago

does it work on mac?