Description
Download Link:
I have created an indicator for risk and reward management, but that’s an indicator so can’t open the order, at this post, I will introduce a cBot version and you can open the order base on the stop-loss, take-profit and risk amount setup.
We can take a look the cBot screen capture:
It’s almost the same as the indicator but with a few more features!
In this cBot, you can create a new order, add the comments and set whether want to use the trailing stop. I will describe the following functions and usage in detail:
Base Buttons:
Buy This is the buy order, so the stop-loss should be less than the entry price, and the take-profit greater than the entry price.
Sell This is the sell order, so the stop-loss should be greater than the entry price, and the take profit less than the entry price. When you click the “Sell” button, the cBot will auto calculate the SL & TP and change them
Buy Stop This is the buy stop order, that’s mean you can set an entry price above current price and wait for the market to reach it. It will auto open the buy order when the market reaches it. It’s useful when you want to open orders when the market breakout.
Sell Stop This is the sell stop order, it’s the same as a buy stop order, but just wait for the market to fall down to your setup price and open a sell order.
Hide This can hide the panel, when you want to see more chart information and you can hide the panel.
Create Order Create the order base the above setting values
Risk and reward values:
You can change all of these values just edit the input. When you change the values, the edit button(Pencil icon) will be enabled, after you changed you need to click the button to update the values. The cBot will auto calculate other related values base on your update:
Volumes Setup how many volumes do you want to take in this order.
Stop Loss Setup the stop-loss price, it will auto-update the Risk/Reward Rate and Volumes (base on risk amount), you also can drag the stop-loss line(default is green) to update it.
Take Profit Setup the take-profit price, it will auto-update the Risk/Reward Rate, you also can drag the take-profit line(default is red) to update it.
Risk/Reward Rate Setup the risk and reward rate, for example, set the value to 2, which means the take-profit pips will be double with stop-loss pips. It will auto-update the Take Profit value
Risk Amount Setup the amount you want to take in this order, which means the money you will lose if this trade is failed, this is a very important part to control your money in your trading. This is a fixed amount value by default, if you tick “Use Percentage“, it will calculate the percentage base on your account balance value.
Has Trailing Stop Setup whether to use the trailing stop in this order. It will use the cTrader default trailing stop feature.
Comments Setup the comments for this order. It will auto mark the current time frame and risk/reward rate value in comments if you didn’t input anything.
The Parameters
Panel alignment Setup the default position for cBot panel. You also can setup the shortcut key for move the panel
Style Settings Setup the SL,TP and entry price line’s color
RS Management Setup the default values when startup the cBot
In the end, this cBot is not free, I just only charge a small fee so that I can create more better indicator or cBot in the future. So, if you like it, please purchase it, thanks for your support
Download Link:
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);
}
}
}
winsonet
Joined on 03.01.2021
- Distribution: Paid
- Language: C#
- Trading platform: cTrader Automate
- File name: CoderBlog cBot.algo
- Rating: 5
- Installs: 902
- Modified: 13/10/2021 09:55