Category Other  Published on 29/06/2023

AW set TP-SL percent

Description

this bot set take profit and stop loss for all position by percent based on balance

 

support us for more free indicator and bot by sign up in LiteFinance broker from this link

LiteFinance Signup

 


using System;
using System.Linq;
using cAlgo.API;


namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AWCPStep : Robot
    {

        [Parameter("Modify TP ", DefaultValue = true)]
        public bool TpOption { get; set; }
        [Parameter("Take Profit Percent", DefaultValue = 3)]
        public double TpPercent { get; set; }
        [Parameter("Modify Sl ", DefaultValue = true)]
        public bool SlOption { get; set; }
        [Parameter("Stop Loss Profit Percent", DefaultValue = 3)]
        public double SlPercent { get; set; }





        protected override void OnStart()
        {

            Settpsl();


            Positions.Modified += PositionsOnModified;
            Positions.Opened += PositionsOnOpened;
            Positions.Closed += PositionsOnClosed;
            PendingOrders.Filled += PendingOrdersOnFilled;



        }

        protected override void OnTick()
        {

        }

        private void PositionsOnModified(PositionModifiedEventArgs obj)
        {
            Settpsl();

        }

        private void PositionsOnOpened(PositionOpenedEventArgs args)
        {
            Settpsl();

        }
        private void PositionsOnClosed(PositionClosedEventArgs args)
        {
            Settpsl();
        }
        private void PendingOrdersOnFilled(PendingOrderFilledEventArgs args)
        {
            Settpsl();
        }

        private void Settpsl()
        {
            foreach (var position in Positions)
            {
                var smValue = Symbols.GetSymbol(position.SymbolName).PipValue;
                
                var smSize=Symbols.GetSymbol(position.SymbolName).PipSize;
                          
                double tpcalc = Math.Round((((Account.Balance * (1 + TpPercent / 100)) - Account.Balance)-(2*position.Commissions)+position.Swap) / (smValue * position.VolumeInUnits), 1);

                double slcalc = Math.Round((Account.Balance - (Account.Balance * (1 - SlPercent / 100))+(2*position.Commissions)+position.Swap) / (smValue * position.VolumeInUnits), 1);


                if (position.TradeType == TradeType.Buy)
                {
                    var tp = position.EntryPrice + tpcalc * smSize;
                    var sl = position.EntryPrice - slcalc * smSize;


                    if (TpOption && position.TakeProfit != tp)
                    {
                        ModifyPosition(position, position.StopLoss, tp);
                    }
                    if (SlOption && position.StopLoss != sl)
                    {
                        ModifyPosition(position, sl, position.TakeProfit);
                    }


                }

                if (position.TradeType == TradeType.Sell)
                {
                    var tp = position.EntryPrice - tpcalc * smSize;
                    var sl = position.EntryPrice + slcalc * smSize;


                    if (TpOption && position.TakeProfit != tp)
                    {
                        ModifyPosition(position, position.StopLoss, tp);
                    }
                    if (SlOption && position.StopLoss != sl)
                    {
                        ModifyPosition(position, sl, position.TakeProfit);
                    }
                }
            }

        }


    }
}



IR
IRCtrader

Joined on 17.06.2021

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: Aw set TP-SL percent.algo
  • Rating: 0
  • Installs: 798
  • Modified: 05/05/2023 11:11
Comments
Log in to add a comment.
DA
dajiba1021 · 1 year ago

Oh my goodness! an awesome write-up dude. Thank you However I am experiencing issue with ur rss . Don’t know why Unable to subscribe to it. Is there everyone finding identical rss dilemma? Everyone who knows kindly respond. ThnkxSlot88

HE
hecar35256 · 1 year ago

There are very a lot of details this way to consider. Which is a wonderful denote bring up. I provide you with the thoughts above as general inspiration but clearly there are actually questions like the one you talk about the location where the most essential thing might be doing work in honest great faith. I don?t know if best practices have emerged around things like that, but More than likely that your chosen job is clearly referred to as a reasonable game. Both little ones notice the impact of just a moment’s pleasure, for the rest of their lives.how to be a credit card processor

AR
arhamabdul429 · 1 year ago

the best addition on our garden that we have are those garden swings, the garden swings made our kids very very happy“Packers and Movers Pune