Open trades with Percentage (%) of account

Created at 29 Jul 2022, 01:31
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
AL

allan.mn

Joined 01.04.2020

Open trades with Percentage (%) of account
29 Jul 2022, 01:31


This is a suggestion to add the option of opening trades with percentage of account as opposed to only having lot and volume options. Example, being able to open a trade with 2%,5%,10% of account. 


cTrader
@allan.mn
Replies

a.minjabari242
21 Oct 2022, 09:19 ( Updated at: 22 Oct 2022, 06:47 )

I want to know more about that. Because I need that many times ago but I don't get proper answer. Iraqi Dinar Guru


@a.minjabari242

juergen.kral
08 Jan 2023, 18:26

RE:

allan.mn said:

This is a suggestion to add the option of opening trades with percentage of account as opposed to only having lot and volume options. Example, being able to open a trade with 2%,5%,10% of account. 

This is a important aspect for risk-managment. 


@juergen.kral

tomicelius
09 Jan 2023, 15:25

RE:

allan.mn said:

This is a suggestion to add the option of opening trades with percentage of account as opposed to only having lot and volume options. Example, being able to open a trade with 2%,5%,10% of account. 

YES, please, we realy need this feature, would make trading so much easier. Everyone is talking about risking 1-2 percent, its reay a must feature. And when i came first to this software, i was expecting it  to have it, as it does have a lot of features...


@tomicelius

pcarroza91@gmail.com
20 Jan 2023, 00:50

RE:

allan.mn said:

This is a suggestion to add the option of opening trades with percentage of account as opposed to only having lot and volume options. Example, being able to open a trade with 2%,5%,10% of account. 

Si ctrader hace esto sería la primera plataforma que lo implementa.


@pcarroza91@gmail.com

VEI5S6C4OUNT0
15 Feb 2023, 08:50

RE:

allan.mn said:

This is a suggestion to add the option of opening trades with percentage of account as opposed to only having lot and volume options. Example, being able to open a trade with 2%,5%,10% of account. 

this a code I made in a XAUUSD bot that backtested well as a account optimiser sadly the bot its self was not a good one but the position size was great

                  

 

   [Parameter("%", Group = "What", DefaultValue = 3, MinValue = 0.1, Step = 1, MaxValue = 10)]
                     public double Q { get; set; }

 

var volumeInUnits = Symbol.NormalizeVolumeInUnits((Account.Balance * (Q / 2000)), RoundingMode.Down);

 

 

Here is the Full bot if anyone wants to use parts of it or mod it what ever..

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class StochBot2 : Robot
    {

        [Parameter("Open Day", Group = "When", DefaultValue = DayOfWeek.Monday)]
        public DayOfWeek OD { get; set; }

        [Parameter("Close Day", Group = "When", DefaultValue = DayOfWeek.Friday)]
        public DayOfWeek CD { get; set; }

        [Parameter("Start Hour", Group = "When", DefaultValue = 7.0, Step = 1)]     //UTC (LONDON) Summer Time March to October set to 6:00hrs 
        public double SrT { get; set; }

        [Parameter("Stop Hour", Group = "When", DefaultValue = 17.0, Step = 1)]     //UTC (LONDON) Summer Time March to October set to 16:00hrs 
        public double SpT { get; set; }

        [Parameter("%", Group = "What", DefaultValue = 3, MinValue = 0.1, Step = 1, MaxValue = 10)]
        public double Q { get; set; }

        [Parameter("Stop", Group = "What", DefaultValue = 2320, MinValue = 0, Step = 10)]
        public double SL { get; set; }

        [Parameter("Take", Group = "What", DefaultValue = 180, MinValue = 0, Step = 10)]
        public double TP { get; set; }
        [Parameter("Include Trailing Stop", Group = "What", DefaultValue = false)]
        public bool IncludeTrailingStopch { get; set; }
        [Parameter("Trailing Stop Trigger (pips)", Group = "What", DefaultValue = 110)]
        public double TrailingStopTriggerch { get; set; }
        [Parameter("Trailing Stop Step (pips)", Group = "What", DefaultValue = 10)]
        public double TrailingStopStep { get; set; }

        [Parameter("K Periods", Group = "How", DefaultValue = 68)]
        public int KP { get; set; }

        [Parameter("K Slowing", Group = "How", DefaultValue = 68)]
        public int KS { get; set; }

        [Parameter("D Periods", Group = "How", DefaultValue = 16)]
        public int DP { get; set; }
        
        [Parameter("MA", Group = "how",DefaultValue = 142)]
        public int MA {get;set;}
        

        private MovingAverage MA1;
        private StochasticOscillator STC;
        
        
        private const string labels = "StochBOT";
        private const string labelb = "StochBOT";

        protected override void OnStart()
        {
            STC = Indicators.StochasticOscillator(KP,KS,DP,MovingAverageType.Simple);
            MA1 = Indicators.MovingAverage(Bars.ClosePrices,MA,MovingAverageType.Simple);
        }

        protected override void OnBar()
        { 
            
            var sellPositions = Positions.FindAll(labels, SymbolName, TradeType.Sell);
            var buyPositions = Positions.FindAll(labelb, SymbolName, TradeType.Buy);
            var MAV= MA1.Result.Last(1);
            var DAY = Server.Time.DayOfWeek;
            var TIMENOW = Server.Time.TimeOfDay.TotalHours;
            if (DAY > OD && DAY < CD)
            {
                if (TIMENOW > SrT && TIMENOW < SpT)
                
            if (STC.PercentK.Last(1)<60&&STC.PercentK.Last(2)<STC.PercentD.Last(2)&&STC.PercentK.Last(1)>STC.PercentD.Last(1)&& Bars.ClosePrices.Last(1)>MAV)
            {

                Open(TradeType.Buy);
            }
            else if (STC.PercentK.Last(1)>40&&STC.PercentK.Last(2)>STC.PercentD.Last(2)&&STC.PercentK.Last(1)<STC.PercentD.Last(1)&& Bars.ClosePrices.Last(1)<MAV)
            {

                Open(TradeType.Sell);
            }
        }
    
 
            if (IncludeTrailingStopch)
            {
                foreach (Position position in sellPositions)
                {
                    double distance = position.EntryPrice - Symbol.Ask;

                    if (distance < TrailingStopTriggerch * Symbol.PipSize)
                        continue;

                    double newStopLossPrice = Symbol.Ask + TrailingStopStep * Symbol.PipSize;

                    if (position.StopLoss == null || newStopLossPrice < position.StopLoss)
                    {
                        ModifyPosition(position, newStopLossPrice, position.TakeProfit);
                    }
                }
                foreach (Position position in buyPositions)
                {
                    double distance = Symbol.Bid - position.EntryPrice;

                    if (distance < TrailingStopTriggerch * Symbol.PipSize)
                        continue;

                    double newStopLossPrice = Symbol.Bid - TrailingStopStep * Symbol.PipSize;
                    if (position.StopLoss == null || newStopLossPrice > position.StopLoss)
                    {
                        ModifyPosition(position, newStopLossPrice, position.TakeProfit);
                    }
                }
            }
}
        private void Open(TradeType tradeType)
        {
            var position = Positions.Find("StochBOT", SymbolName, tradeType);
            var volumeInUnits = Symbol.NormalizeVolumeInUnits((Account.Balance * (Q / 2000)), RoundingMode.Down);

            if (position==null)
                ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "StochBOT",SL,TP);
                if (Positions.Count < 2) 
                  foreach (var trade in History.OrderByDescending(trade => trade.ClosingTime).Take(1))
            if (trade.NetProfit > 0)
            
                ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits*2, "StochBOT",SL,TP*1.2);
                
        }
    }
}


@VEI5S6C4OUNT0