Description
Run this tool and click on the chart price you want to set as a stop loss and an entry order with a stop loss will be sent.
Other tools can be downloaded from Gumroad. (for free)
using cAlgo.API;
using cAlgo.API.Internals;
using System;
//===========================================================================================================================================
// ClickEntry
//===========================================================================================================================================
namespace cAlgo.Robots {
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class ClickEntry : Robot {
// --- min lots
[Parameter("Min Lots", DefaultValue = 0.01, MinValue = 0.01, Step = 0.1)]
public double MinLots { get; set; }
// --- max lots
[Parameter("Max Lots", DefaultValue = 100, MinValue = 0.01, Step = 0.1)]
public double MaxLots { get; set; }
// --- risk%
[Parameter("Risk Percnet", DefaultValue = 0.5, MinValue = 0.001, MaxValue = 20, Step = 0.1)]
public double RiskPercent { get; set; }
// --- risk amount
[Parameter("Risk Amount", DefaultValue = 1000, MinValue = 1, Step = 0.5)]
public double RiskAmount { get; set; }
// --- RRR
[Parameter("Risk Reward Ratio", DefaultValue = 2, MinValue = 0.01)]
public double RiskRewardRatio { get; set; }
//---------
// OnStart
protected override void OnStart() {
var sltpSetter = new ClickEntrySupport(Chart, RiskRewardRatio);
sltpSetter.Fixed += (obj, args) => Order(args.StopLoss, args.TakeProfit);
}
//--------
// order
private void Order(double stopPrice, double limitPrice) {
TradeType tt = (stopPrice < limitPrice ? TradeType.Buy : TradeType.Sell);
var price = (tt == TradeType.Buy ? Ask : Bid);
var digit = (int)(Math.Log10(Symbol.PipSize) - Math.Log10(Symbol.TickSize));
var stopPips = Math.Round(Math.Abs(price - stopPrice) / Symbol.PipSize, digit);
var limitPips = Math.Round(Math.Abs(price - limitPrice) / Symbol.PipSize, digit);
// --- calc volume
var permitalbleLoss = Math.Min((Account.Balance) * RiskPercent / 100, RiskAmount);
var volume = permitalbleLoss / stopPips / Symbol.PipValue;
volume = Symbol.NormalizeVolumeInUnits(volume);
if (volume < Symbol.QuantityToVolumeInUnits(MinLots)) volume = Symbol.QuantityToVolumeInUnits(MinLots);
if (volume > Symbol.QuantityToVolumeInUnits(MaxLots)) volume = Symbol.QuantityToVolumeInUnits(MaxLots);
// --- order
var res = ExecuteMarketOrder(tt, SymbolName, volume, ToString(), stopPips, limitPips);
if (!res.IsSuccessful) {
Print(res.Error.ToString());
}
// --- stop
Stop();
}
}
//==================================================
// ClickEntrySupport
// for decide SL and TP at intaractive
//==================================================
internal class ClickEntrySupport :IDisposable {
public event EventHandler<PriceFixecEventArgs> Fixed;
public double RiskRewardRatio { get; set; }
private Point _mouseDown = new Point(0, 0);
private ChartHorizontalLine _stopLine;
private ChartHorizontalLine _limitLine;
private const string STOP_LINE_NAME = "EasyEntryStopLine";
private const string LIMIT_LINE_NAME = "EasyEntryLimitLine";
private Chart _chart;
public ClickEntrySupport(Chart chart, double riskRewardRatio) {
RiskRewardRatio = riskRewardRatio;
_chart = chart;
_stopLine = _chart.DrawHorizontalLine(STOP_LINE_NAME, 0, Color.Red, 1, LineStyle.Dots);
_limitLine = _chart.DrawHorizontalLine(LIMIT_LINE_NAME, 0, Color.Green, 1, LineStyle.Dots);
_chart.MouseMove += OnMove;
_chart.MouseDown += OnDown;
_chart.MouseUp += OnUp;
}
//----------
// Dispose
public void Dispose() {
_chart.RemoveObject(_stopLine.Name);
_chart.RemoveObject(_limitLine.Name);
_chart.MouseUp -= OnUp;
_chart.MouseDown -= OnDown;
_chart.MouseMove -= OnMove;
}
//-----------
// for event
private void OnUp(ChartMouseEventArgs args) {
if (_mouseDown == new Point(args.MouseX, args.MouseY)) {
Fixed(this, new PriceFixecEventArgs(_stopLine.Y, _limitLine.Y));
Dispose();
}
}
private void OnDown(ChartMouseEventArgs args) {
_mouseDown = new Point(args.MouseX, args.MouseY);
}
private void OnMove(ChartMouseEventArgs args) {
_stopLine.Y = args.YValue;
var bid = _chart.Bars.LastBar.Close;
_limitLine.Y = bid + (bid - args.YValue) * RiskRewardRatio;
}
}
//============
// EventArgs
//============
internal class PriceFixecEventArgs : EventArgs {
public double StopLoss, TakeProfit;
public PriceFixecEventArgs(double sl, double tp) { StopLoss = sl; TakeProfit = tp; }
}
}
![ajinori's avatar](/uploads/user-39593/avatar/6f901c26938966e68a640ef2804648b87b861765.png)
ajinori
Joined on 06.10.2020
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: ClickEntry.algo
- Rating: 5
- Installs: 1505
Comments
Hello. Installed. Thank you. Everything is clear, my colleagues and I like it. The only thing that is not clear is what is meant with the following: There is a Risk Percent line and there is a Risk Amount line. The first is clear that I set the risk percentage, and in the second case I need to set the amount in dollars, and what amount should I set? The amount that I have in total on deposit and the % of risk will be calculated from the Risk Amount?
Привет. Установил. Спасибо. Всё чётко, мне и коллегам нравится. Единственное не понятно что имеется ввиду следующее:
Есть строка Risk Percent и есть строка Risk Amount. Первое это понятно что я устанавлию процент риска, а вот второе там нужно указывать сумму в долларах, а что за сумму нужно указывать? Так которая у меня в общем на депозите и риск % будет высчитывать из Risk Amount?
I am using it, but the bot doesn't calculate the total amount considering the commissions.
For example: I want to risk 100$ and the bot put 2 lots. If I have 5$ for each lot (in+out), I will risk 110$, but I always want 100$ in total.
Can you fix it? thanks
Thanks for this, a quick question about the risk amount, where do we get this number from?
Does this tool not work out the volume automatically?
thank you brother, God bless you !!
![CnicholasdownieLive's avatar](https://social-images-215c11ee-be56.s3.eu-west-2.amazonaws.com/user-2071931/avatars/bigAvatarFileUrl-2071931-1692488541.png)
YOU ARE A GOD< THANK YOU
doesn't work on Mac( error