global variable

Created at 28 Apr 2020, 10:14
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

global variable
28 Apr 2020, 10:14


 

how do I put symbol as global variable?

var symbol must be taken from OnTick ()

 

protected override void OnStart()
        {
            Inizio:
            RefreshData();

            string EURUSD = Symbols[random.Next(Symbols.Count)];
            Symbols.GetSymbol("EURUSD");
            Print(EURUSD);

            var symbol = MarketData.GetSymbol(EURUSD);

....

...

...

        }

protected override void OnTick()
        {
            var position = Positions.Find("MyLabel");
            

            if (position.TradeType == TradeType.Buy)
            {
                var newSLprice = Symbol.Ask - (Symbol.PipSize * 1);
                if (newSLprice > position.StopLoss)
                {
                    ModifyPosition(position, newSLprice, null);
                }
            }
            else
            {
                var newSLprice = Symbol.Bid + (Symbol.PipSize * 1);
                if (newSLprice < position.StopLoss)
                {
                    ModifyPosition(position, newSLprice, null);
                }
            }
        }
    }
}

 

Thanks


@luca.tocchi
Replies

PanagiotisCharalampous
28 Apr 2020, 11:10

Hi Luca,

See an example below

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; }

        Symbol _symbol;
        protected override void OnStart()
        {
            _symbol = Symbols.GetSymbol("EURUSD");
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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

Best Regards,

Panagiotis 

Join us on Telegram

 


@PanagiotisCharalampous

luca.tocchi
28 Apr 2020, 11:14

RE:

PanagiotisCharalampous said:

Hi Luca,

See an example below

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; }

        Symbol _symbol;
        protected override void OnStart()
        {
            _symbol = Symbols.GetSymbol("EURUSD");
        }

        protected override void OnTick()
        {
            // Put your core logic here
        }

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

Best Regards,

Panagiotis 

Join us on Telegram

thanks

 


@luca.tocchi