Category Other  Published on 29/06/2023

AW CP Daily

Description

AW Close Position.

this bot close all position and cancel all order after get daily profit percent.

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

LiteFinance Signup

update: NET 6

 


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


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


        [Parameter("Take Profit Percent", DefaultValue = 3.1)]
        public double tpPercent { get; set; }

        protected override void OnStart()
        {

        }

        protected override void OnTick()
        {
            double DailyNet1 = Positions.Sum(p => p.NetProfit);
            double DailyNet2 = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit);
            double DailyNet = Math.Round(DailyNet1 + DailyNet2, 2);

            // get Starting Balance
            var oldTrades = History.Where(x => x.ClosingTime.Date != Time.Date).OrderBy(x => x.ClosingTime).ToArray();
            double StartingBalance;

            if (oldTrades.Length == 0)
            {
                StartingBalance = History.Count == 0 ? Account.Balance : History.OrderBy(x => x.ClosingTime).First().Balance;
            }
            else
            {
                StartingBalance = oldTrades.Last().Balance;
            }


            //calc Daily Percent Profit

            double DailyPercent = DailyNet / StartingBalance * 100;

            foreach (var position in Positions)
            {
                if (DailyPercent > tpPercent)
                {
                    ClosePositionAsync(position);
                }

            }

            foreach (var order in PendingOrders)
            {
                if (DailyPercent > tpPercent)
                {
                    CancelPendingOrder(order);
                }
            }

        }

    }


}



IR
IRCtrader

Joined on 17.06.2021

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: AW CP Daily.algo
  • Rating: 0
  • Installs: 1557
  • Modified: 08/07/2022 06:32
Comments
Log in to add a comment.
No comments found.