ClickEntry free

by ajinori in category Other at 30/03/2021
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)

 

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 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; }
    }
}
Comments
0