Openning and Closing Orders - Updated
Unfortunately it started to rain hard towards the end of this video. I will be rerecording it.
I have put this video here for you to get the new content until I can rerecord it without the noise from the rain.
Sample Code For Opening and Closing Orders:
// Execute Sell Trade with $2000 (0.02 lots) and label. ExecuteMarketOrder(TradeType.Sell, Symbol, 2000, "Robot One"); // Execute a Buy Trade with $1000 (0.01 lots) and a label, stop loss and take profit values ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "Robot One", 25.0, 50.0); //Close all orders with label "Robot One" var openPositions = Positions.FindAll("Robot One", Symbol); foreach (var order in openPositions) { ClosePosition(order); }
Full Video Source Code:
using System; using System; using System.Linq; using cAlgo.API; using cAlgo.API.Indicators; using cAlgo.API.Internals; using cAlgo.Indicators; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class BlankRobot : Robot { [Parameter("Number", DefaultValue = 0.0)] public double Parameter { get; set; } [Parameter("Dads Name", DefaultValue = "John Doe")] public string StringParameter { get; set; } [Parameter("Is Poor", DefaultValue = false)] public bool BoolParameter { get; set; } protected override void OnStart() { // Put your initialization logic here Print(StringParameter + " Has started the Robot."); var order = ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "Blank Robot"); if (!order.IsSuccessful) { Print("Error checking code here"); } else { // Do success code here. Print("Order done ok -- success code here"); } } protected override void OnTick() { // Put your core logic here Print("A new tick has occured"); ExecuteMarketOrder(TradeType.Buy, Symbol, 1000, "Blank Robot"); ExecuteMarketOrder(TradeType.Sell, Symbol, 2000, "Blank Robot"); } protected override void OnBar() { // Put your core logic here Print("### A new bar has occured ###"); } protected override void OnStop() { // Put your deinitialization logic here Print(StringParameter + " Has stopped the Robot."); var orders = Positions.FindAll("Blank Robot"); foreach (var order in orders) { ClosePosition(order); } } } }