cBot Open a new position after one is closed
cBot Open a new position after one is closed
01 Nov 2020, 19:23
What code should I use to open a new position after any of the opened positions is closed, without affecting the other opened positions.
Replies
pistrituadrian16
02 Nov 2020, 15:05
RE:
PanagiotisCharalampous said:
Hi pistrituadrian16,
You can check the Positions.Count property and open new positions only if the value is 0.
Best Regards,
Panagiotis
can you give me an example of a bot that opens a trade after one of the opened ones is closed( only the part of the script that does that), I mean if there are 3 trades opened and one hits sl or tp, in the moment it closes another one to be opened, I am a biginner and I really don't know much.
@pistrituadrian16
PanagiotisCharalampous
02 Nov 2020, 15:21
Hi pistrituadrian16,
Here you go
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; }
protected override void OnStart()
{
Positions.Closed += OnPositionsClosed;
}
void OnPositionsClosed(PositionClosedEventArgs obj)
{
ExecuteMarketOrder(TradeType.Buy, Symbol.Name, 1000);
}
protected override void OnTick()
{
}
protected override void OnStop()
{
// Put your deinitialization logic here
}
}
}
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
02 Nov 2020, 08:36
Hi pistrituadrian16,
You can check the Positions.Count property and open new positions only if the value is 0.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous