Skip to content

Algo

Summary

The container class for the main cAlgo.API Interfaces.

Signature

1
public class Algo

Namespace

cAlgo.API.Internals

Methods

BeginInvokeOnMainThread

Summary

Invokes asynchronously the specified code on the main cBot or Indicator thread.

Signature

1
public void BeginInvokeOnMainThread(Action action)

Parameters

Name Type Description
action Action The code to invoke on the main cBot/Indicator thread

Return Value

void

RefreshData

Summary

Updates MarketSeries, Positions, PendingOrders, History, etc.And sends postponed events after Thread sleep call.If you put the main thread on sleep by calling Thread sleep methodthen you have to call RefreshData after Thread wakes up to sendthe postponed events while thread was sleeping.

Signature

1
public void RefreshData()

Return Value

void

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
 using cAlgo.API;
 using System.Linq;
 using System.Threading; 
 namespace NewcBot
 {
     [Robot(AccessRights = AccessRights.None)]
     public class NewcBot : Robot
     {
         protected override void OnStart()
         {
             var executionResults = new TradeOperation[50];
             for (var i = 0; i < 50; i++)
             {
                 executionResults[i] = ExecuteMarketOrderAsync(i % 2 == 0 ? TradeType.Buy : TradeType.Sell, SymbolName, Symbol.VolumeInUnitsMin);
             }
             Print("All orders sent");
             while (executionResults.Any(operation => operation.IsExecuting))
             {
                 Print("Waiting...");
                 Thread.Sleep(100);
                 // If you remove the RefreshData method call
                 // cBot main thread will stuck and the rest
                 // of the code will not be executed
                 RefreshData();
             }
             Print("Closing Positions");
             foreach (var position in Positions)
             {
                 if (position.TradeType == TradeType.Sell) continue;
                 _ = ClosePositionAsync(position);
             }
         }
     }

CreateDataSeries

Summary

Initialization of an IndicatorDataSeries.

Signature

1
public IndicatorDataSeries CreateDataSeries()

Return Value

IndicatorDataSeries

Examples

1
2
3
4
5
6
7
8
9
 private IndicatorDataSeries series;
 protected override void Initialize()
 {
     series = CreateDataSeries();
 }
 public override void Calculate(int index)
 {
     series[index] = (MarketSeries.Close[index] + MarketSeries.Open[index]) / 2;
 }

Sleep (3)

Sleep (1 of 3)

Summary

Suspends the algorithm until the specified timespan elapses.

Signature

1
public void Sleep(TimeSpan timespan)

Parameters

Name Type Description
timespan TimeSpan The Timespan during which the algorithm should not react to any events.

Return Value

void

Related Tutorials

Sleep (2 of 3)

Summary

Suspends the algorithm until the specified number of milliseconds elapses.

Signature

1
public void Sleep(int milliseconds)

Parameters

Name Type Description
milliseconds int The number of milliseconds for which the algorithm should be suspended.

Return Value

void

Related Tutorials

Sleep (3 of 3)

Summary

Suspends the algorithm until the specified datetime.

Signature

1
public void Sleep(DateTime dateTime)

Parameters

Name Type Description
dateTime DateTime The DateTime until the algorithm should be suspended.

Return Value

void

Related Tutorials

Print (1 of 3)

Summary

Prints text representation of the specified object to the log.

Signature

1
public void Print(object value)

Parameters

Name Type Description
value object Object to print.

Return Value

void

Examples

1
 Print(Account.Positions.Count);

Print (2 of 3)

Summary

Prints a message to the Log

Signature

1
public void Print(object[] parameters)

Parameters

Name Type Description
parameters object[] Parameters to print

Return Value

void

Examples

1
 Print(Account.Balance, " ", Account.Equity);

Print (3 of 3)

Summary

Prints a message to the Log.

Signature

1
public void Print(string message, object[] parameters)

Parameters

Name Type Description
message string Message to print.
parameters object[] Parameters (optional)

Return Value

void

Examples

1
 Print("Current Balance is {0}, Equity is {1}.", Account.Balance, Account.Equity);

Properties

InstanceId

Summary

Returns unique ID of current running instance.

Signature

1
public string InstanceId {get;}

Return Value

string

LocalStorage

Summary

Access the local storage API.

Signature

1
public LocalStorage LocalStorage {get;}

Return Value

LocalStorage

Related Tutorials

Indicators

Summary

Access to the built-in Indicators.

Signature

1
public IIndicatorsAccessor Indicators {get;}

Return Value

IIndicatorsAccessor

Examples

1
2
3
4
5
 protected override void Initialize()
 {
     //Use MarketSeries price data as parameters to indicators
     _ma = Indicators.SimpleMovingAverage(MarketSeries.Close, 20);
 }

Related Tutorials

Notifications

Summary

Represents the notifications, such as sounds and email.

Signature

1
public INotifications Notifications {get;}

Return Value

INotifications

Examples

1
 Notifications.PlaySound(@"C:\Windows\Media\notify.wav");
1
2
 string emailBody = "this is the message send";
 Notifications.SendEmail("from@example.com", "to@example.com", "my subject", emailBody);

TimeFrame

Summary

Access to the TimeFrame values.

Signature

1
public TimeFrame TimeFrame {get;}

Return Value

TimeFrame

Examples

1
2
3
4
 if(TimeFrame == TimeFrame.Daily)
 {           
    //...
 } 

Server

Summary

Server related information.

Signature

1
public IServer Server {get;}

Return Value

IServer

Examples

1
2
3
4
 protected override void OnTick()
 {
     Print("The server time is: {0}", Server.Time);
 }

TimeZone

Summary

TimeZone of a cBot or an Indicator.

Signature

1
public TimeZoneInfo TimeZone {get;}

Return Value

TimeZoneInfo

Positions

Summary

The list of all open positions of the account.

Signature

1
public Positions Positions {get;}

Return Value

Positions

Examples

1
2
3
4
5
 foreach (var position in Positions)
 {
     if (position.StopLoss == null)
         ModifyPosition(position, 10, position.TakeProfit);
 }

PendingOrders

Summary

The array of all Pending Orders of the account.

Signature

1
public PendingOrders PendingOrders {get;}

Return Value

PendingOrders

Examples

1
2
3
4
5
6
 foreach (var order in PendingOrders)
 {
     if (order.StopLossPips == null)
         ModifyPendingOrder(order, order.TargetPrice, 10, order.TakeProfit,
                             order.ExpirationTime);
 }

History

Summary

Represents the collection of all historical trades of the account.

Signature

1
public History History {get;}

Return Value

History

Examples

1
2
3
4
 foreach (HistoricalTrade trade in History)
 {
     Print(trade.EntryTime);
 }

Timer

Summary

Access to the Timer object.

Signature

1
public Timer Timer {get;}

Return Value

Timer

Examples

1
2
3
4
5
6
7
8
 protected override void OnStart()
 {
     Timer.Start(1);//start timer with 1 second interval
 }
 protected override void OnTimer()
 {
     ChartObjects.DrawText("time", Time.ToString("HH:mm:ss"), StaticPosition.TopLeft);
 }

Time

Summary

Returns the current server time. The shortcut to the Server.Time property.

Signature

1
public DateTime Time {get;}

Return Value

DateTime

Examples

1
2
3
4
 protected override void OnTick()
 {
     Print("The Server Time is: {0}", Time);
 }

TimeInUtc

Summary

Returns the current server time in UTC. The shortcut to the Server.TimeInUtc property.

Signature

1
public DateTime TimeInUtc {get;}

Return Value

DateTime

Examples

1
2
3
4
 protected override void OnTick()
 {
     Print("The Server Time in UTC is: {0}", TimeInUtc);
 }

RunningMode

Summary

Defines if a cBot is running in real time, in the silent backtesting mode, in the visual backtesting mode, or inthe optimization mode.

Signature

1
public RunningMode RunningMode {get;}

Return Value

RunningMode

IsBacktesting

Summary

True if a cBot is in the Backtesting mode, otherwise False.

Signature

1
public bool IsBacktesting {get;}

Return Value

bool

Examples

1
2
3
4
 if(IsBacktesting)
 {
    Print(MarketSeries.OpenTime.LastValue);
 }

Application

Summary

Represents the application.

Signature

1
public Application Application {get;}

Return Value

Application

AssetConverter

Summary

Converts an asset to another asset.

Signature

1
public IAssetConverter AssetConverter {get;}

Return Value

IAssetConverter

Related Tutorials

MarketSessions

Summary

Returns current market sessions.

Signature

1
public MarketSession MarketSessions {get;}

Return Value

MarketSession

Related Tutorials

Chart

Summary

Represents the chart where cBot or Indicator is launched.

Signature

1
public Chart Chart {get;}

Return Value

Chart

Assets

Summary

Returns list of all available assets.

Signature

1
public Assets Assets {get;}

Return Value

Assets

SymbolName

Summary

Gets or sets the symbol name.

Signature

1
public string SymbolName {get;}

Return Value

string

Symbols

Summary

Gets the symbol names.

Signature

1
public Symbols Symbols {get;}

Return Value

Symbols

Symbol

Summary

Represents the current symbol provides access to its properties and certain methods

Signature

1
public Symbol Symbol {get;}

Return Value

Symbol

Examples

1
2
3
4
5
6
 var ask = Symbol.Ask;
 var bid = Symbol.Bid;
 var digits = Symbol.Digits;
 var pip = Symbol.PipSize;
 var maxVolume = Symbol.VolumeMax;
 var minVolume = Symbol.VolumeMin;
1
 ExecuteMarketOrder(TradeType.Buy, Symbol, 10000, "myLabel", 10, 10);  
1
 volume = Symbol.NormalizeVolume(volume, RoundingMode.Down);

Bid

Summary

Gets the symbol bid price.

Signature

1
public double Bid {get;}

Return Value

double

Ask

Summary

Gets the symbol ask price.

Signature

1
public double Ask {get;}

Return Value

double

Watchlists

Summary

Gets the watchlist.

Signature

1
public Watchlists Watchlists {get;}

Return Value

Watchlists

Bars

Summary

The collection of Bar objects.

Signature

1
public Bars Bars {get;}

Return Value

Bars

Related Tutorials

MarketData

Summary

Provides access to the Depth of Market Data.

Signature

1
public MarketData MarketData {get;}

Return Value

MarketData

Examples

1
2
 private MarketDepth _md;
 _md = MarketData.GetMarketDepth("GBPUSD");

Http

Summary

Send HTTP requests.

Signature

1
public Http Http {get;}

Return Value

Http

Related Tutorials

ChartObjects

Signature

1
public ChartObjects ChartObjects {get;}

Return Value

ChartObjects

MarketSeries

Signature

1
public MarketSeries MarketSeries {get;}

Return Value

MarketSeries

Events

MarketSessionsChanged

Summary

Occurs when market sessions change.

Signature

1
public event Action<MarketSessionChangedEventArgs> MarketSessionsChanged;