symbol

Created at 26 Mar 2020, 17:35
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!
LU

luca.tocchi

Joined 25.03.2020

symbol
26 Mar 2020, 17:35


can anyone insert the part of code in bold?

the program checks the spread, if the spread is greater than max spred then it must add a random symbol and check otherwise it must continue.

please help me

 

....

 private Random random = new Random();


        protected override void OnStart()
        {
            _stochastic = Indicators.StochasticOscillator(K_Period, Slow_K, D_Period, maType);

            var spread = Symbol.Ask - Symbol.Bid;

            while (spread > MaxSpread)
            {
                Print("Spread suck, go in other asset");
                Print(Symbols[random.Next(Symbols.Count)]);
                //must open another symbol and verify that the condition of spread> maxspread is true or false
            }

            Print("Spread Ok");

is this my problem

....


@luca.tocchi
Replies

firemyst
28 Mar 2020, 11:16

RE:

luca.tocchi said:

can anyone insert the part of code in bold?

the program checks the spread, if the spread is greater than max spred then it must add a random symbol and check otherwise it must continue.

please help me

 

....

 private Random random = new Random();


        protected override void OnStart()
        {
            _stochastic = Indicators.StochasticOscillator(K_Period, Slow_K, D_Period, maType);

            var spread = Symbol.Ask - Symbol.Bid;

            while (spread > MaxSpread)
            {
                Print("Spread suck, go in other asset");
                Print(Symbols[random.Next(Symbols.Count)]);
                //must open another symbol and verify that the condition of spread> maxspread is true or false
            }

            Print("Spread Ok");

is this my problem

....

I would do it a completely different way.

Something along the lines of:

bool spreadOK = false;
double spread = 0;
int numberOfSymbols = Symbols.Count
int numberOfSymbolsChecked = 0;

while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols)
{
  Symbol s = Symbols[random.Next(Symbols.Count)];
  spread = s.Ask - s.Bid;
  if (spread <= MaxSpread)
    spreadOk = true;
  numberOfSymbolsChecked += 1;
}

if (!spreadOk)
  Print("Could not find any valid symbols with a good spread.");

 


@firemyst

luca.tocchi
29 Mar 2020, 11:24

RE: RE:

firemyst ha detto:

luca.tocchi ha detto:

pot la parte del codice in grassetto?

il programma controlla lo spread, se lo spread è maggiore di max spred deve è aggiunta un ispere e controlla altrimenti deve.

aiutatemi vi prego

 

....

casuale privato - nuovo Random();


protected
override void OnStart() -
_stochastic - Indicators.StochasticOscillator(K_Period,
Slow_K, D_Period, maType);
spread di var - Symbol.Ask - Symbol.Bid; while (spread > MaxSpread) -
Stampa("Spread suck, go in other asset");



Stampa([casuale. Simboli di SuoNeri(Conta)]);
deve aprire un altro punto e che la di spread> verifica sia falsa o stampa:


("Spread Ok");

è questo il mio problema

....

Lo farei in modo non altro'.

Qualcosa lungo le linee di:

bool spreadOK = false;
double spread = 0;
int numberOfSymbols = Symbols.Count
int numberOfSymbolsChecked = 0;

while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols)
{
  Symbol s = Symbols[random.Next(Symbols.Count)];
  spread = s.Ask - s.Bid;
  if (spread <= MaxSpread)
    spreadOk = true;
  numberOfSymbolsChecked += 1;
}

if (!spreadOk)
  Print("Could not find any valid symbols with a good spread.");

 

I did it. But it gives me this error: Error CS0029: Could not implicitly convert type 'string' to 'cAlgo.API.Internals.Symbol'.

what's the problem?

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


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class spread : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Parameter("Max Spread", DefaultValue = 1, MinValue = -5.0)]
        public double MaxSpread { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            bool spreadOk = false;
            double spread = 0;
            int numberOfSymbols = Symbols.Count;
            int numberOfSymbolsChecked = 0;


            while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols)
            {
                Symbol s = Symbols[random.Next(Symbols.Count)];
                spread = s.Ask - s.Bid;
                if (spread <= MaxSpread)
                    spreadOk = true;
                numberOfSymbolsChecked += 1;
            }

            if (!spreadOk)
                Print("Could not find any valid symbols with a good spread.");

        }
    }
}

 


@luca.tocchi

firemyst
29 Mar 2020, 16:31

RE: RE: RE:

luca.tocchi said:

firemyst ha detto:

luca.tocchi ha detto:

pot la parte del codice in grassetto?

il programma controlla lo spread, se lo spread è maggiore di max spred deve è aggiunta un ispere e controlla altrimenti deve.

aiutatemi vi prego

 

....

casuale privato - nuovo Random();


protected
override void OnStart() -
_stochastic - Indicators.StochasticOscillator(K_Period,
Slow_K, D_Period, maType);
spread di var - Symbol.Ask - Symbol.Bid; while (spread > MaxSpread) -
Stampa("Spread suck, go in other asset");



Stampa([casuale. Simboli di SuoNeri(Conta)]);
deve aprire un altro punto e che la di spread> verifica sia falsa o stampa:


("Spread Ok");

è questo il mio problema

....

Lo farei in modo non altro'.

Qualcosa lungo le linee di:

bool spreadOK = false;
double spread = 0;
int numberOfSymbols = Symbols.Count
int numberOfSymbolsChecked = 0;

while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols)
{
  Symbol s = Symbols[random.Next(Symbols.Count)];
  spread = s.Ask - s.Bid;
  if (spread <= MaxSpread)
    spreadOk = true;
  numberOfSymbolsChecked += 1;
}

if (!spreadOk)
  Print("Could not find any valid symbols with a good spread.");

 

I did it. But it gives me this error: Error CS0029: Could not implicitly convert type 'string' to 'cAlgo.API.Internals.Symbol'.

what's the problem?

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


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class spread : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Parameter("Max Spread", DefaultValue = 1, MinValue = -5.0)]
        public double MaxSpread { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            bool spreadOk = false;
            double spread = 0;
            int numberOfSymbols = Symbols.Count;
            int numberOfSymbolsChecked = 0;


            while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols)
            {
                Symbol s = Symbols[random.Next(Symbols.Count)];
                spread = s.Ask - s.Bid;
                if (spread <= MaxSpread)
                    spreadOk = true;
                numberOfSymbolsChecked += 1;
            }

            if (!spreadOk)
                Print("Could not find any valid symbols with a good spread.");

        }
    }
}

 

The problem is the line:

Symbol s = Symbols[random.Next(Symbols.Count)];

That lines doesn't return a Symbol object, but a string that's the name of the symbol.

You will need to use

Symbols.GetSymbol

to convert the string name to an actual Symbol object.

So first change the line to:

string symbolName = Symbols[random.Next(Symbols.Count)];

and then you need to add in and complete the line:

Symbol s = Symbols.GetSymbol....

 

 

 


@firemyst

luca.tocchi
29 Mar 2020, 16:50

RE: RE: RE: RE:

firemyst said:

luca.tocchi said:

firemyst ha detto:

luca.tocchi ha detto:

pot la parte del codice in grassetto?

il programma controlla lo spread, se lo spread è maggiore di max spred deve è aggiunta un ispere e controlla altrimenti deve.

aiutatemi vi prego

 

....

casuale privato - nuovo Random();


protected
override void OnStart() -
_stochastic - Indicators.StochasticOscillator(K_Period,
Slow_K, D_Period, maType);
spread di var - Symbol.Ask - Symbol.Bid; while (spread > MaxSpread) -
Stampa("Spread suck, go in other asset");



Stampa([casuale. Simboli di SuoNeri(Conta)]);
deve aprire un altro punto e che la di spread> verifica sia falsa o stampa:


("Spread Ok");

è questo il mio problema

....

Lo farei in modo non altro'.

Qualcosa lungo le linee di:

bool spreadOK = false;
double spread = 0;
int numberOfSymbols = Symbols.Count
int numberOfSymbolsChecked = 0;

while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols)
{
  Symbol s = Symbols[random.Next(Symbols.Count)];
  spread = s.Ask - s.Bid;
  if (spread <= MaxSpread)
    spreadOk = true;
  numberOfSymbolsChecked += 1;
}

if (!spreadOk)
  Print("Could not find any valid symbols with a good spread.");

 

I did it. But it gives me this error: Error CS0029: Could not implicitly convert type 'string' to 'cAlgo.API.Internals.Symbol'.

what's the problem?

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


namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class spread : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Parameter("Max Spread", DefaultValue = 1, MinValue = -5.0)]
        public double MaxSpread { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            bool spreadOk = false;
            double spread = 0;
            int numberOfSymbols = Symbols.Count;
            int numberOfSymbolsChecked = 0;


            while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols)
            {
                Symbol s = Symbols[random.Next(Symbols.Count)];
                spread = s.Ask - s.Bid;
                if (spread <= MaxSpread)
                    spreadOk = true;
                numberOfSymbolsChecked += 1;
            }

            if (!spreadOk)
                Print("Could not find any valid symbols with a good spread.");

        }
    }
}

 

The problem is the line:

Symbol s = Symbols[random.Next(Symbols.Count)];

That lines doesn't return a Symbol object, but a string that's the name of the symbol.

You will need to use

Symbols.GetSymbol

to convert the string name to an actual Symbol object.

So first change the line to:

string symbolName = Symbols[random.Next(Symbols.Count)];

and then you need to add in and complete the line:

Symbol s = Symbols.GetSymbol....

 

 

 

   there is still errors...

I didn't understand this very much

 

 [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class spread : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        [Parameter("Max Spread", DefaultValue = 1, MinValue = -5.0)]
        public double MaxSpread { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            bool spreadOk = false;
            double spread = 0;
            int numberOfSymbols = Symbols.Count;
            int numberOfSymbolsChecked = 0;


            while (!spreadOk && numberOfSymbolsChecked < numberOfSymbols)
            {
                string symbolName = Symbols[random.Next(Symbols.Count)];
                Symbol s = Symbols.GetSymbols(string symbolName);
                spread = s.Ask - s.Bid;
                if (spread <= MaxSpread)
                    spreadOk = true;
                numberOfSymbolsChecked += 1;
            }

            if (!spreadOk)
                Print("Could not find any valid symbols with a good spread.");

        }
    }
}


@luca.tocchi