convert this bot to martingale bot
convert this bot to martingale bot
14 Nov 2022, 18:48
Hello my friends!
I really need help; I want to convert this bot to martingale bot (Open the position just only on my Conditions).
thank you.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo.Robots30
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class FractalsSample : Robot
{
private double _volumeInUnits;
private ExponentialMovingAverage _EMA;
[Parameter("Source")]
public DataSeries SourceSeries { get; set; }
[Parameter("Max Spread", DefaultValue = 1, MinValue = 0, MaxValue = 300)]
public double MaxSpread { get; set; }
[Parameter("Volume (Lots)", DefaultValue = 0.01)]
public double VolumeInLots { get; set; }
[Parameter("Stop Loss (Pips)", DefaultValue = 15)]
public double StopLossInPips { get; set; }
[Parameter("Take Profit (Pips)", DefaultValue = 15)]
public double TakeProfitInPips { get; set; }
[Parameter("Label", DefaultValue = "name")]
public string Label { get; set; }
public Position[] BotPositions
{
get { return Positions.FindAll(Label); }
}
protected override void OnStart()
{
_volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);
_EMA = Indicators.ExponentialMovingAverage (SourceSeries ,100);
}
protected override void OnBar()
{
var cBotPositions = Positions.FindAll(Label);
var lastIndex = MarketSeries.Close.Count - 1;
double EMA = _EMA.Result[lastIndex - 1];
if ( EMA < Bars.ClosePrices.Last(1) &&
Bars.ClosePrices.Last(2) < Bars.ClosePrices.Last(1) &&
cBotPositions.Length == 0
)
{
ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
if ( EMA > Bars.ClosePrices.Last(1) &&
Bars.ClosePrices.Last(2) > Bars.ClosePrices.Last(1) &&
cBotPositions.Length == 0 )
{
ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
}
} }
}
PanagiotisChar
15 Nov 2022, 08:03
Hi there,
If you need professional help, contact us at development@clickalgo.com
Aieden Technologies
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar