control open trades
Created at 15 Nov 2022, 20:17
control open trades
15 Nov 2022, 20:17
Good afternoon, I am new to c.bots and I am working with a free c.bots called ON BARD SELL. I would like to be able to modify it to control the number of open operations. I found help in this forum to have only one open operation this is the code
Positions.Count(x => x.TradeType == TradeType.Buy) == 0
the problem is that due to my ignorance I don't know where it should be located I would be very grateful if you advise me thanks
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 ONBARDSELL : Robot
{
[Parameter("Quantity (Lots)", Group = "Volume", DefaultValue = 0.01, MinValue = 0.001, Step = 111)]
public double Quantity { get; set; }
[Parameter("Enable TakeProfit?", Group = "TakeProfit", DefaultValue = true)]
public bool useTakeProfit { get; set; }
[Parameter("Take Profit", Group = "TakeProfit", DefaultValue = 6.6, MinValue = 0.1, Step = 0.1)]
public double takeProfit { get; set; }
[Parameter("Enable Stop Loss?", Group = "StopLoss", DefaultValue = true)]
public bool useStopLoss { get; set; }
[Parameter("Stop Loss", Group = "StopLoss", DefaultValue = 0.1, MinValue = 0.1, Step = 0.1)]
public double stopLoss { get; set; }
private MovingAverage tenMinimum;
private MovingAverage tenMaximum;
private double volumeInUnits;
protected override void OnStart()
{
volumeInUnits = Symbol.QuantityToVolumeInUnits(Quantity);
tenMaximum = Indicators.MovingAverage(Bars.LowPrices, 2, MovingAverageType.Simple);
tenMinimum = Indicators.MovingAverage(Bars.HighPrices, 1, MovingAverageType.Simple);
}
protected override void OnBar()
{
if (Positions.Count() < 2)
{
if (Bars.LastBar.High <= tenMaximum.Result.LastValue && !useTakeProfit)
{
foreach (var position in Positions)
{
ClosePosition(position);
}
}
}
if (Bars.LastBar.Close <= tenMinimum.Result.LastValue)
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, volumeInUnits, "TenMov", (useStopLoss ? stopLoss : double.MaxValue), (useTakeProfit ? takeProfit : double.MaxValue));
}
}
}
}
PanagiotisChar
16 Nov 2022, 09:08
Hi there,
Try this
Aieden Technologies
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar