open random instance

Created at 26 Mar 2020, 10:51
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

open random instance
26 Mar 2020, 10:51


how to open a random instance at the beginning of the program? 

without any conditions occurring


@luca.tocchi
Replies

PanagiotisCharalampous
26 Mar 2020, 12:02

Hi Luca,

Check the Sample Martingale cBot. It has an example on how to execute random orders.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

luca.tocchi
26 Mar 2020, 12:04

RE:

PanagiotisCharalampous said:

Hi Luca,

Check the Sample Martingale cBot. It has an example on how to execute random orders.

Best Regards,

Panagiotis 

Join us on Telegram

the sample Martingale cBot does not open assets. The "Sample Martingale cBot" creates a random Sell or Buy order only

maybe I got confused.

with instance I mean asset


@luca.tocchi

PanagiotisCharalampous
26 Mar 2020, 13:51

Hi Luca,

Indeed it is not very clear what do you mean. But whatever you are trying to do, you should check the example that gives you an idea on how to make random choices using the Random class. You just need to adjust it to your needs. If you want to select a random symbol, then use the Random class to generate a random index for the Symbols collection.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

luca.tocchi
26 Mar 2020, 14:11

RE:

PanagiotisCharalampous said:

Hi Luca,

Indeed it is not very clear what do you mean. But whatever you are trying to do, you should check the example that gives you an idea on how to make random choices using the Random class. You just need to adjust it to your needs. If you want to select a random symbol, then use the Random class to generate a random index for the Symbols collection.

Best Regards,

Panagiotis 

Join us on Telegram

"If you want to select a random symbol, then use the Random class to generate a random index for the Symbols collection."

 

is what I'm looking for ... could I have the code? and a small explanation


@luca.tocchi

PanagiotisCharalampous
26 Mar 2020, 14:50

Hi Luca,

Here is something quick

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            Print(Symbols[random.Next(Symbols.Count)]);
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

luca.tocchi
26 Mar 2020, 15:08

RE:

PanagiotisCharalampous said:

Hi Luca,

Here is something quick

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            Print(Symbols[random.Next(Symbols.Count)]);
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram

but in this case the print only. I need the symbol to open, and see his chart


@luca.tocchi

luca.tocchi
26 Mar 2020, 15:15

RE:

PanagiotisCharalampous said:

Hi Luca,

Here is something quick

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private Random random = new Random();

        protected override void OnStart()
        {
            // Put your initialization logic here
        }

        protected override void OnTick()
        {
            Print(Symbols[random.Next(Symbols.Count)]);
        }

        protected override void OnStop()
        {
            // Put your deinitialization logic here
        }
    }
}

Best Regards,

Panagiotis 

Join us on Telegram

this is part of the code

....

 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

PanagiotisCharalampous
26 Mar 2020, 15:19

Hi Luca,

You can use Symbols.GetSymbol() to get another symbol to check the spread and open a position.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

luca.tocchi
26 Mar 2020, 15:25

RE:

PanagiotisCharalampous said:

Hi Luca,

You can use Symbols.GetSymbol() to get another symbol to check the spread and open a position.

Best Regards,

Panagiotis 

Join us on Telegram

can you put it in my part of the program? So to open a random one?


@luca.tocchi