martinagle
martinagle
14 Oct 2022, 15:00
Hi help me please!
I want to add the martingale method to this robot
And I also want to not double the volume after 3 more losing.
Thank you.
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 FractalsSample : Robot
{
private double _volumeInUnits;
private RelativeStrengthIndex _rsi;
[Parameter("Source")]
public DataSeries SourceSeries { get; set; }
[Parameter("Volume (Lots)", DefaultValue = 0.01)]
public double VolumeInLots { get; set; }
[Parameter("Stop Loss (Pips)", DefaultValue = 0)]
public double StopLossInPips { get; set; }
[Parameter("Take Profit (Pips)", DefaultValue = 0)]
public double TakeProfitInPips { get; set; }
[Parameter("Label", DefaultValue = "X")]
public string Label { get; set; }
public Position[] BotPositions
{
get { return Positions.FindAll(Label); }
}
protected override void OnStart()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
_rsi = Indicators.RelativeStrengthIndex(SourceSeries, 14);
}
protected override void OnBar()
{
var cBotPositions = Positions.FindAll(Label);
if (_rsi.Result.LastValue < 30)
{
ClosePositions(TradeType.Sell);
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
}
else if (_rsi.Result.LastValue > 70)
{
ClosePositions(TradeType.Buy);
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
}
}
private void ClosePositions(TradeType tradeType)
{
foreach (var position in BotPositions)
{
if (position.TradeType != tradeType)
continue;
ClosePosition(position);
}
}
}
}
PanagiotisChar
15 Oct 2022, 10:13
Hi there,
If you need professional help with this, reach out to me at development@clickalgo.com.
Aieden Technologies
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar