Category Trend  Published on 08/07/2019

BE Calculator

Description

Follow my cTrader Telegram group at https://t.me/cTraderCommunity; it's a new community but it will grow fast, plus everyone can talk about cTrader indicators and algorithm without restrictions, though it is not allowed to spam commercial indicators to sell them. There's also a Discord Server now @ https://discord.gg/5GAPMtp

This indi calculates BE levels for both long and short position and orders open on the chart.

For any bug report or suggestion, follow my telegram group or comment below


using System;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
using System.Collections.Generic;

namespace cAlgo
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class BECalculator : Indicator
    {
        [Parameter("Show Long BreakEven", DefaultValue = true)]
        public bool showBuyBE { get; set; }
        [Parameter("Show Short BreakEven", DefaultValue = true)]
        public bool showSellBE { get; set; }

        [Parameter("Show Orders BreakEven", DefaultValue = true)]
        public bool showOrdBE { get; set; }

        private List<Position> Longs = new List<Position>();
        private List<Position> Shorts = new List<Position>();

        private List<PendingOrder> LongOrds = new List<PendingOrder>();
        private List<PendingOrder> ShortOrds = new List<PendingOrder>();

        protected override void Initialize()
        {
        }

        public override void Calculate(int index)
        {
            populateLists();
            CalculateBE();
        }

        private void CalculateBE()
        {
            double LongBE = 0, ShortBE = 0, LongVolSum = 0, ShortVolSum = 0;
            Longs.ForEach(delegate(Position pos)
            {
                LongBE += pos.EntryPrice * pos.VolumeInUnits;
                LongVolSum += pos.VolumeInUnits;
            });
            Shorts.ForEach(delegate(Position pos)
            {
                ShortBE += pos.EntryPrice * pos.VolumeInUnits;
                ShortVolSum += pos.VolumeInUnits;
            });

            if (showBuyBE)
                Chart.DrawHorizontalLine("LongBE", LongBE / LongVolSum, Color.Green);
            if (showSellBE)
                Chart.DrawHorizontalLine("ShortBE", ShortBE / ShortVolSum, Color.DarkRed);

            if (showOrdBE)
            {
                double LongOrdBE = 0, ShortOrdBE = 0, LongOrdVolSum = 0, ShortOrdVolSum = 0;
                LongOrds.ForEach(delegate(PendingOrder ord)
                {
                    LongOrdBE += ord.TargetPrice * ord.VolumeInUnits;
                    LongOrdVolSum += ord.VolumeInUnits;
                });
                ShortOrds.ForEach(delegate(PendingOrder ord)
                {
                    ShortOrdBE += ord.TargetPrice * ord.VolumeInUnits;
                    ShortOrdVolSum += ord.VolumeInUnits;
                });

                if (showBuyBE)
                    Chart.DrawHorizontalLine("LongOrdBE", LongOrdBE / LongOrdVolSum, Color.Green, 1, LineStyle.DotsRare);
                if (showSellBE)
                    Chart.DrawHorizontalLine("ShortOrdBE", ShortOrdBE / ShortOrdVolSum, Color.DarkRed, 1, LineStyle.DotsRare);
            }
        }

        private void populateLists()
        {
            Longs.RemoveAll(x => true);
            Shorts.RemoveAll(x => true);

            LongOrds.RemoveAll(x => true);
            ShortOrds.RemoveAll(x => true);

            foreach (var pos in Positions)
            {
                if (pos.SymbolName == Symbol.Name)
                    if (pos.TradeType == TradeType.Buy)
                        Longs.Add(pos);
                    else
                        Shorts.Add(pos);
            }

            foreach (var ord in PendingOrders)
            {
                if (ord.SymbolCode == Symbol.Name)
                    if (ord.TradeType == TradeType.Buy)
                        LongOrds.Add(ord);
                    else
                        ShortOrds.Add(ord);
            }
        }
    }
}


CY
cysecsbin.01

Joined on 10.11.2018 Blocked

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: BECalculator.algo
  • Rating: 0
  • Installs: 1443
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
VK
vkhunt · 1 year ago

Hi guys. The only thing I really love and what gives me real pleasure. I'm talking about sports betting, check italian serie b predictions . By the way, in addition to pleasure, it also brings good money. So everything that is not done, everything is for the best. Moreover, with these predictions I earn much more than at my previous job.

PO
polinazinkk · 1 year ago

I often watch sports broadcasts when I bet on sports