cBot to stop after 4 continuous Stop Loss.
cBot to stop after 4 continuous Stop Loss.
22 Jan 2021, 08:00
Hi Friends,
Can someone please modify the below Robot to stop after 4 continuous Stop Loss is triggered?
Thanks in Advance...
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
MR : Robot
{
[Parameter(
"Initial Volume"
, DefaultValue = 10000, MinValue = 0)]
public
int
InitialVolume {
get
;
set
; }
[Parameter(
"Stop Loss"
, DefaultValue = 40)]
public
int
StopLoss {
get
;
set
; }
[Parameter(
"Take Profit"
, DefaultValue = 40)]
public
int
TakeProfit {
get
;
set
; }
private
Random random =
new
Random();
protected
override
void
OnStart()
{
Positions.Closed += OnPositionsClosed;
ExecuteOrder(InitialVolume, GetRandomTradeType());
}
private
void
ExecuteOrder(
long
volume, TradeType tradeType)
{
var result = ExecuteMarketOrder(tradeType, Symbol, volume,
"MR"
, StopLoss, TakeProfit);
if
(result.Error == ErrorCode.NoMoney)
Stop();
}
private
void
OnPositionsClosed(PositionClosedEventArgs args)
{
Print(
"Closed"
);
var position = args.Position;
if
(position.Label !=
"MR"
|| position.SymbolCode != Symbol.Code)
return
;
if
(position.GrossProfit > 0)
{
ExecuteOrder(InitialVolume, GetRandomTradeType());
}
else
{
ExecuteOrder((
int
)position.Volume * 2, position.TradeType);
}
}
private
TradeType GetRandomTradeType()
{
return
random.Next(2) == 0 ? TradeType.Buy : TradeType.Sell;
}
}
}
PanagiotisCharalampous
22 Jan 2021, 10:09
Hi steel.export,
If you need somebody to implement a new feature for your cBot, you can also consider posting a Job
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous