can't align! submit questions again.

Created at 25 Mar 2016, 08:03
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!
AP

apexji

Joined 25.03.2016

can't align! submit questions again.
25 Mar 2016, 08:03


This Forum only supports IE, does not support chrom.I submit questions again.I am a green hand.

I see Ask Bid and Spread the chart shows.in this link /forum/whats-new/1531I added the two symbol, the result can't align.I can't find the reason.Please help me.

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC)]
    public class MultiSymbolMarketInfo : Indicator
    {
        private Symbol symbol1;
        private Symbol symbol2;
        private Symbol symbol3;
        private Symbol symbol4;
        private Symbol symbol5;

        [Parameter(DefaultValue = "EURGBP")]
        public string Symbol1 { get; set; }

        [Parameter(DefaultValue = "GBPUSD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURUSD")]
        public string Symbol3 { get; set; }

        [Parameter(DefaultValue = "EURJPY")]
        public string Symbol4 { get; set; }

        [Parameter(DefaultValue = "AUDJPY")]
        public string Symbol5 { get; set; }

        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);
            symbol2 = MarketData.GetSymbol(Symbol2);
            symbol3 = MarketData.GetSymbol(Symbol3);
            symbol4 = MarketData.GetSymbol(Symbol4);
            symbol5 = MarketData.GetSymbol(Symbol5);
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar)
                return;

            var text = FormatSymbol(symbol1) + "\n" + FormatSymbol(symbol2) + "\n" + FormatSymbol(symbol3) + "\n" + FormatSymbol(symbol4) + "\n" + FormatSymbol(symbol5);

            ChartObjects.DrawText("symbol1", text, StaticPosition.TopLeft, Colors.Lime);
        }

        private string FormatSymbol(Symbol symbol)
        {
            var spread = Math.Round(symbol.Spread / symbol.PipSize, 1);
            return string.Format("{0}\t Ask: {1}\t Bid: {2}\t Spread: {3}", symbol.Code, symbol.Ask, symbol.Bid, spread);

        }
    }
}

 


@apexji
Replies

croucrou
25 Mar 2016, 18:29

The names of the added symbol names are just built of smaller letters and the words are more narrow. You could add one more "/t" after these symbol's codes as they need one more "Tab" to get to the same column. You might want to check that in any text editor.

I am using Chrome and have no issues.


@croucrou

cyfer
25 Mar 2016, 21:08

Save yourself the headache and do this 

 

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = true)]
    public class MultiSymbolMarketInfo : Indicator
    {
        private Symbol symbol1;
        private Symbol symbol2;
        private Symbol symbol3;
        private Symbol symbol4;
        private Symbol symbol5;
        private Symbol symbol6;
        private Symbol symbol7;

        [Parameter(DefaultValue = "EURGBP")]
        public string Symbol1 { get; set; }

        [Parameter(DefaultValue = "GBPUSD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURUSD")]
        public string Symbol3 { get; set; }

        [Parameter(DefaultValue = "EURJPY")]
        public string Symbol4 { get; set; }

        [Parameter(DefaultValue = "AUDJPY")]
        public string Symbol5 { get; set; }

        [Parameter(DefaultValue = "EURCAD")]
        public string Symbol6 { get; set; }

        [Parameter(DefaultValue = "GBPJPY")]
        public string Symbol7 { get; set; }

        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);
            symbol2 = MarketData.GetSymbol(Symbol2);
            symbol3 = MarketData.GetSymbol(Symbol3);
            symbol4 = MarketData.GetSymbol(Symbol4);
            symbol5 = MarketData.GetSymbol(Symbol5);
            symbol6 = MarketData.GetSymbol(Symbol6);
            symbol7 = MarketData.GetSymbol(Symbol7);
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar)
                return;


            var text = FormatSymbol(symbol1) + "\n" + FormatSymbol(symbol2) + "\n" + FormatSymbol(symbol3) + "\n" + FormatSymbol(symbol4) + "\n" + FormatSymbol(symbol5) + "\n" + FormatSymbol(symbol6) + "\n" + FormatSymbol(symbol7);
            ChartObjects.RemoveObject(text);
            ChartObjects.DrawText("symbol1", text, StaticPosition.TopLeft, Colors.Lime);
        }

        private string FormatSymbol(Symbol symbol)
        {
            var spread = Math.Round(symbol.Spread / symbol.PipSize, 1);
            if (symbol.Code.Contains("JPY"))
            {
                return string.Format("{0}\t\t Ask: {1}\t Bid: {2}\t Spread: {3}", symbol.Code, symbol.Ask, symbol.Bid, spread);
            }
            else
                return string.Format("{0}\t Ask: {1}\t Bid: {2}\t Spread: {3}", symbol.Code, symbol.Ask, symbol.Bid, spread);

        }
    }
}

*I have nothing to say about your browser issue , I'm using Opera browser 

 


@cyfer

apexji
26 Mar 2016, 00:44

Thank you very much enthusiastic friends to help

Thank you very much enthusiastic friends to help


@apexji

apexji
26 Mar 2016, 00:52

RE: Again would like to ask a question

cyfer said:Again would like to ask a question, the info list, if spread < 2 font color to yellow, then, how to write?   I am a rookie.Master, can you do me a favor?

Save yourself the headache and do this 

 

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AutoRescale = true)]
    public class MultiSymbolMarketInfo : Indicator
    {
        private Symbol symbol1;
        private Symbol symbol2;
        private Symbol symbol3;
        private Symbol symbol4;
        private Symbol symbol5;
        private Symbol symbol6;
        private Symbol symbol7;

        [Parameter(DefaultValue = "EURGBP")]
        public string Symbol1 { get; set; }

        [Parameter(DefaultValue = "GBPUSD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURUSD")]
        public string Symbol3 { get; set; }

        [Parameter(DefaultValue = "EURJPY")]
        public string Symbol4 { get; set; }

        [Parameter(DefaultValue = "AUDJPY")]
        public string Symbol5 { get; set; }

        [Parameter(DefaultValue = "EURCAD")]
        public string Symbol6 { get; set; }

        [Parameter(DefaultValue = "GBPJPY")]
        public string Symbol7 { get; set; }

        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);
            symbol2 = MarketData.GetSymbol(Symbol2);
            symbol3 = MarketData.GetSymbol(Symbol3);
            symbol4 = MarketData.GetSymbol(Symbol4);
            symbol5 = MarketData.GetSymbol(Symbol5);
            symbol6 = MarketData.GetSymbol(Symbol6);
            symbol7 = MarketData.GetSymbol(Symbol7);
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar)
                return;


            var text = FormatSymbol(symbol1) + "\n" + FormatSymbol(symbol2) + "\n" + FormatSymbol(symbol3) + "\n" + FormatSymbol(symbol4) + "\n" + FormatSymbol(symbol5) + "\n" + FormatSymbol(symbol6) + "\n" + FormatSymbol(symbol7);
            ChartObjects.RemoveObject(text);
            ChartObjects.DrawText("symbol1", text, StaticPosition.TopLeft, Colors.Lime);
        }

        private string FormatSymbol(Symbol symbol)
        {
            var spread = Math.Round(symbol.Spread / symbol.PipSize, 1);
            if (symbol.Code.Contains("JPY"))
            {
                return string.Format("{0}\t\t Ask: {1}\t Bid: {2}\t Spread: {3}", symbol.Code, symbol.Ask, symbol.Bid, spread);
            }
            else
                return string.Format("{0}\t Ask: {1}\t Bid: {2}\t Spread: {3}", symbol.Code, symbol.Ask, symbol.Bid, spread);

        }
    }
}

*I have nothing to say about your browser issue , I'm using Opera browser 

 

 


@apexji

croucrou
27 Mar 2016, 01:55

You can do this like this:

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

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true)]
    public class MultiSymbolMarketInfo : Indicator
    {
        private Symbol symbol1, symbol2, symbol3, symbol4, symbol5, symbol6, symbol7;

        [Parameter(DefaultValue = "EURGBP")]
        public string Symbol1 { get; set; }

        [Parameter(DefaultValue = "GBPUSD")]
        public string Symbol2 { get; set; }

        [Parameter(DefaultValue = "EURUSD")]
        public string Symbol3 { get; set; }

        [Parameter(DefaultValue = "EURJPY")]
        public string Symbol4 { get; set; }

        [Parameter(DefaultValue = "AUDJPY")]
        public string Symbol5 { get; set; }

        [Parameter(DefaultValue = "EURCAD")]
        public string Symbol6 { get; set; }

        [Parameter(DefaultValue = "GBPJPY")]
        public string Symbol7 { get; set; }

        private double spread(Symbol symbol)
        {
            return Math.Round(symbol.Spread / symbol.PipSize, 1);
        }

        private string format(Symbol symbol)
        {
            if (symbol.Code.Contains("JPY"))
                return string.Format("{0}\t\t Ask: {1}\t Bid: {2}\t Spread: {3}", symbol.Code, symbol.Ask, symbol.Bid, spread(symbol));
            else
                return string.Format("{0}\t Ask: {1}\t Bid: {2}\t Spread: {3}", symbol.Code, symbol.Ask, symbol.Bid, spread(symbol));
        }

        private string text(Symbol symbol)
        {
            return format(symbol);
        }

        private Colors color(Symbol symbol)
        {
            if (spread(symbol) >= 2)
                return Colors.Lime;
            else
                return Colors.Yellow;
        }

        private void printText(string newLine, Symbol symbol)
        {
            ChartObjects.RemoveObject(text(Symbol));
            ChartObjects.DrawText(symbol.Code, newLine + text(symbol), StaticPosition.TopLeft, color(symbol));
        }

        protected override void Initialize()
        {
            symbol1 = MarketData.GetSymbol(Symbol1);
            symbol2 = MarketData.GetSymbol(Symbol2);
            symbol3 = MarketData.GetSymbol(Symbol3);
            symbol4 = MarketData.GetSymbol(Symbol4);
            symbol5 = MarketData.GetSymbol(Symbol5);
            symbol6 = MarketData.GetSymbol(Symbol6);
            symbol7 = MarketData.GetSymbol(Symbol7);
        }

        public override void Calculate(int index)
        {
            if (!IsLastBar)
                return;

            printText("", symbol1);
            printText("\n", symbol2);
            printText("\n\n", symbol3);
            printText("\n\n\n", symbol4);
            printText("\n\n\n\n", symbol5);
            printText("\n\n\n\n\n", symbol6);
            printText("\n\n\n\n\n\n", symbol7);
        }
    }
}

 


@croucrou