mohsabry.ms
mohsabry.ms's avatar

Info

Username:mohsabry.ms
Name:mohsabry.ms
Member since: 15 Sep 2021

About

None

Signature

None

Last Forum Posts

@Need Help How I use a specific value form indicator inside my CBot:  18 Nov 2021, 11:59


amusleh said:

Hi,

Did you checked the API references example: cAlgo API Reference - IndicatorDataSeries Interface (ctrader.com)

You have to store your calculation result inside an IndicatorDataSeries, then you can use that data series on your cBots.

Thank you for your advice it works well

Regards,

@Need Help How I use a specific value form indicator inside my CBot:  15 Nov 2021, 14:47


PanagiotisCharalampous said:

Hi mohsabry.ms,

To be able to access your indicator's values from a cBot, you first need to expose them in a public variable, preferably an IndicatorDataSeries.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook 

Appreciate your valuable help,

Forgive me as just a begineer

But I tired trying expose  "a" variable to be an output as a IndicatorDataSeries.

The calculation made as a series not index

I search how to make series type deals with IndicatorDataSeries but I really can't find a way

 private void LinearRegression(DataSeries series) 

   // Linear regresion

            double sum_x = 0, sum_x2 = 0, sum_y = 0, sum_xy = 0;

            int start = series.Count - Bars;
            int end = series.Count - 1;

            for (int i = start; i <= end; i++)
            {
                sum_x += 1.0 * i;
                sum_x2 += 1.0 * i * i;
                sum_y += series[i];
                sum_xy += series[i] * i;
            }

            double a = (Bars * sum_xy - sum_x * sum_y) / (Bars * sum_x2 - sum_x * sum_x);

}

and there is no output 

Thank you in Advance

Regards,

@Need Help How I use a specific value form indicator inside my CBot:  14 Nov 2021, 22:13


Hi there,

I'm just a beginner

How I use a specific value form indicator inside my CBot

How can I use a value of (double a) from indicator to my CBot

I called Linear Regression Channel  Indicator  in CBot and check it in manage references

I use Linear Regression Channel  Indicator 

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class LinearRegressionChannel : Indicator
    {
        [Parameter(DefaultValue = 200)]
        public int Bars { get; set; }

        [Parameter(DefaultValue = "Yellow")]
        public string Color { get; set; }

        [Parameter(DefaultValue = 1.0)]
        public double LineThickness { get; set; }

        [Parameter("Center", DefaultValue = true)]
        public bool ShowCenter { get; set; }

        [Parameter("Channel", DefaultValue = true)]
        public bool ShowChannel { get; set; }

        [Parameter("Standard deviation", DefaultValue = true)]
        public bool ShowDeviantion { get; set; }




        private Colors color;

        protected override void Initialize()
        {

            // Parse color from string, e.g. "Yellow", "Green", "Red". string must start with large letter, "Red" is valid, "red" - not.
            if (!Enum.TryParse(Color, out color))
                color = Colors.Yellow;
        }


        public override void Calculate(int index)
        {
            if (IsLastBar)
                LinearRegression(MarketSeries.Close);

        }

        private void LinearRegression(DataSeries series)
        {
            // Linear regresion

            double sum_x = 0, sum_x2 = 0, sum_y = 0, sum_xy = 0;

            int start = series.Count - Bars;
            int end = series.Count - 1;

            for (int i = start; i <= end; i++)
            {
                sum_x += 1.0 * i;
                sum_x2 += 1.0 * i * i;
                sum_y += series[i];
                sum_xy += series[i] * i;
            }

            double a = (Bars * sum_xy - sum_x * sum_y) / (Bars * sum_x2 - sum_x * sum_x);
            double b = (sum_y - a * sum_x) / Bars;




   
            // Calculate maximum and standard devaitions

            double maxDeviation = 0;
            double sumDevation = 0;

            for (int i = start; i <= end; i++)
            {
                double price = a * i + b;
                maxDeviation = Math.Max(Math.Abs(series[i] - price), maxDeviation);
                sumDevation += Math.Pow(series[i] - price, 2.0);
            }

            double stdDeviation = Math.Sqrt(sumDevation / Bars);

            // draw in future
            end += 20;

            double pr1 = a * start + b;
            double pr2 = a * end + b;

            if (ShowCenter)
            {
                ChartObjects.DrawLine("center", start, pr1, end, pr2, color, LineThickness, LineStyle.Lines);

            }

            if (ShowChannel)
            {
                ChartObjects.DrawLine("top", start, pr1 + maxDeviation, end, pr2 + maxDeviation, color, LineThickness, LineStyle.Solid);
                ChartObjects.DrawLine("bottom", start, pr1 - maxDeviation, end, pr2 - maxDeviation, color, LineThickness, LineStyle.Solid);
            }

            if (ShowDeviantion)
            {
                ChartObjects.DrawLine("dev-top", start, pr1 + stdDeviation, end, pr2 + stdDeviation, color, LineThickness, LineStyle.DotsVeryRare);
                ChartObjects.DrawLine("dev-bottom", start, pr1 - stdDeviation, end, pr2 - stdDeviation, color, LineThickness, LineStyle.DotsVeryRare);
            }



        }

    }
}

Thank You in Advance


 

@Need Help sum net profit for all closed Position:  08 Nov 2021, 20:41


Thank you for your valuable helping

Best Regards;

@Need Help sum net profit for all closed Position:  06 Nov 2021, 01:29


Hi,

If I wanna to choose from history some specific closed trades that i labeled it before as "sell_today"

how to modify this code to select them only;

var netProfit = History.Sum(trade => trade.NetProfit);

Forgive me I'm just a beginner

Thank you in advace

Best Regards,

@Need Help sum net profit for all closed Position:  05 Nov 2021, 14:41


amusleh said:

Hi,

You can use history to sum the net profit of all your closed positions (trades):

var netProfit = History.Sum(trade => trade.NetProfit);

To get net profit of all your open positions you can use Positions:

var netProfit = Positions.Sum(position => position.NetProfit);

It works well,

Appreciate your help

Regards,

@Need Help sum net profit for all closed Position:  04 Nov 2021, 21:41


I tired to sum every closed Position

every time it rest the value to the last net profit

I try both " lastTrade.NetProfit" and " LastResult.Position.NetProfit"

I'm working on cBot that stop at certain Netprofit

could you help me please,

Thank you in advance

Regards;

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.

No uploaded.

Warning! Executing cBots downloaded from this section may result in loss of funds. Use them at your own risk.

No uploaded.