c# display command

Created at 12 Oct 2020, 06:21
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!
TA

tatorzth

Joined 20.09.2020

c# display command
12 Oct 2020, 06:21


Hello,

 

I need to show my calculation variable (int or double) on the chart. 

can anyone show me a simple command for it ?

please suggest

 

WB


@tatorzth
Replies

PanagiotisCharalampous
12 Oct 2020, 08:47

HI WB,

You can use the DrawText() method.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

tatorzth
12 Oct 2020, 09:27

RE:

PanagiotisCharalampous said:

HI WB,

You can use the DrawText() method.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis

something wrong with my code please help me review this

VBuy = Convert.ToInt32((10000 * (Ma.Result.LastValue - Symbol.Ask)));
VSell = Convert.ToInt32((10000 * (Symbol.Bid - Ma.Result.LastValue)));
Chart.DrawText("text1", "High is here", VBuy, VSell, Color.Red);

text.VerticalAlignment = VerticalAlignment.Bottom;
text.HorizontalAlignment = HorizontalAlignment.Center;

please advise

 


@tatorzth

PanagiotisCharalampous
12 Oct 2020, 09:35

HI WB,

You need to provide the complete code and let us know what is the problem.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

tatorzth
12 Oct 2020, 09:49

RE:

PanagiotisCharalampous said:

HI WB,

You need to provide the complete code and let us know what is the problem.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis

my idea is just want to replace Print() by DrawText() function

please see my code below

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

namespace WBX
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class WBX : Robot
    {
        [Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
        public double Quantity { get; set; }

        [Parameter("MA Type", Group = "Moving Average")]
        public MovingAverageType MAType { get; set; }

        [Parameter("Source", Group = "Moving Average")]
        public DataSeries SourceSeries { get; set; }

        [Parameter("Periods", Group = "Moving Average", DefaultValue = 10)]
        public int Periods { get; set; }

        [Parameter("Range", DefaultValue = 3)]
        public int Range { get; set; }

        [Parameter("Multiorder range", DefaultValue = 3)]
        public int MultiRange { get; set; }

        [Parameter("TP", DefaultValue = 3)]
        public int TP { get; set; }

        [Parameter("SL", DefaultValue = 3)]
        public int SL { get; set; }

        [Parameter("Max Trade", DefaultValue = 3, MinValue = 1, Step = 1)]
        public int MaxTrade { get; set; }

        [Parameter("Trade direction : Buy", DefaultValue = false)]
        public bool Buy { get; set; }

        [Parameter("Trade direction : Sell", DefaultValue = false)]
        public bool Sell { get; set; }

        public int NumberofTrade;
        public int VBuy;
        public int VSell;
        public double NextOrderAllow;
        private MovingAverage Ma;
        private const string label = "MA Trend cBot";
        

        protected override void OnStart()
        {
            Ma = Indicators.MovingAverage(SourceSeries, Periods, MAType);
            var Position = Positions.Find("SampleMA", SymbolName);
            VBuy = Convert.ToInt32((10000 * (Ma.Result.LastValue - Symbol.Ask)));
            VSell = Convert.ToInt32((10000 * (Symbol.Bid - Ma.Result.LastValue)));
            var highPrice = VBuy;
            var openTime = MarketSeries.OpenTime.LastValue;
            var text = Chart.DrawText("text1", "High is here", openTime, highPrice, Color.Red);
            Chart.DrawText("text1", "High is here", VBuy, VSell, Color.Red);
            if (Position == null)
            {
                NextOrderAllow = 0;
            }
            else if (VBuy > 0)
            {
                NextOrderAllow = Symbol.Ask - (MultiRange * 0.0001);
            }
            else if (VSell > 0)
            {
                NextOrderAllow = Symbol.Bid + (MultiRange * 0.0001);
            }
        }

        protected override void OnTick()
        {

            Ma = Indicators.MovingAverage(SourceSeries, Periods, MAType);
            VBuy = Convert.ToInt32((10000 * (Ma.Result.LastValue - Symbol.Ask)));
            VSell = Convert.ToInt32((10000 * (Symbol.Bid - Ma.Result.LastValue)));

            Chart.DrawText("text1", "Value", VBuy, VSell, Color.Red);

            text.VerticalAlignment = VerticalAlignment.Bottom;
            text.HorizontalAlignment = HorizontalAlignment.Center;


            if (Buy == true)
            {
                if (VBuy > Range)
                {
                    if (NextOrderAllow == 0)
                    {
                        Open(TradeType.Buy);
                        NextOrderAllow = Symbol.Ask - (MultiRange * 0.0001);
                    }
                    else if (Symbol.Ask < NextOrderAllow)
                    {
                        Open(TradeType.Buy);
                        NextOrderAllow = Symbol.Ask - (MultiRange * 0.0001);
                    }
                }
                if (VBuy > 0)
                {
                    Print("Trade direction : Buy ", VBuy);
                    Print("Next entry order allow : ", NextOrderAllow);
                }
            }
            if (Sell == true)
            {
                if (VSell > Range)
                {
                    if (NextOrderAllow == 0)
                    {
                        Open(TradeType.Sell);
                        NextOrderAllow = Symbol.Bid + (MultiRange * 0.0001);
                    }
                    else if (Symbol.Bid > NextOrderAllow)
                    {
                        Open(TradeType.Sell);
                        NextOrderAllow = Symbol.Bid + (MultiRange * 0.0001);
                    }

                }
                if (VSell > 0)
                {
                    Print("Trade direction : Sell ", VSell);
                    Print("Next entry order allow : ", NextOrderAllow);
                }
            }
        }
        private void Open(TradeType tradeType)
        {
            var Position = Positions.Find("SampleMA", SymbolName, tradeType);
            var volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
            if (Position == null)
            {
                NextOrderAllow = 0;
                ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleMA", SL, TP);
                NumberofTrade = 1;
            }
            else if (MaxTrade > NumberofTrade)
            {
                ExecuteMarketOrder(tradeType, SymbolName, volumeInUnits, "SampleMA", SL, TP);
                NumberofTrade = NumberofTrade + 1;
            }
        }
    }
}


@tatorzth

PanagiotisCharalampous
12 Oct 2020, 09:58

HI WB,

There are several issues in your code

1) text variable is not declared.

2) For the x coordinate, the method takes as input the date or the bar index. The VBuy input you are using doesn't make much sense.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

tatorzth
12 Oct 2020, 10:12

RE:

PanagiotisCharalampous said:

HI WB,

There are several issues in your code

1) text variable is not declared.

2) For the x coordinate, the method takes as input the date or the bar index. The VBuy input you are using doesn't make much sense.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

 

thanks for your help.

please advise to me the correct code to show VBuy value on the chart.

 

Regards,

WB


@tatorzth

PanagiotisCharalampous
12 Oct 2020, 10:16

HI WB,

You first need to explain what are you trying to do since your code does not make sense to me.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

tatorzth
12 Oct 2020, 10:28

RE:

PanagiotisCharalampous said:

HI WB,

You first need to explain what are you trying to do since your code does not make sense to me.

Best Regards,

Panagiotis 

Join us on Telegram

Hi Panagiotis,

 

i just want to convert my Print() function to show all value on the graph. 

c# is new to me, sorry for this inconvenience. 

 

Regards,

WB


@tatorzth

PanagiotisCharalampous
12 Oct 2020, 10:35

HI WB,

Try the below

 Chart.DrawText("text1", VBuy.ToString(), Server.Time, Symbol.Bid, Color.Red);

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous