CO
Renko Close EMA
25 Dec 2016, 18:10
Hello,
Can anyone help me to change my cBot EMA indicator from the normal candle stick EMA Close to a EMA that is used on a Renko Chart which uses a EMA
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 martingale : Robot
{
[Parameter("MA Type")]
public MovingAverageType MAType { get; set; }
[Parameter("Source")]
public DataSeries SourceSeries { get; set; }
[Parameter("Stop Loss", DefaultValue = 50)]
public int StopLoss { get; set; }
[Parameter("Take Profit", DefaultValue = 60)]
public int TakeProfit { get; set; }
[Parameter("MA_Slow_Period", DefaultValue = 200)]
public int _MA_Slow_Period { get; set; }
[Parameter("MA_Fast_Period", DefaultValue = 50)]
public int _MA_Fast_Period { get; set; }
[Parameter(DefaultValue = 1000, MinValue = 0)]
public int Volume { get; set; }
private ExponentialMovingAverage i_Moving_Average;
private ExponentialMovingAverage i_Moving_Average_1;
private ExponentialMovingAverage i_Moving_Average_2;
private ExponentialMovingAverage i_Moving_Average_3;
private const string label = "Martingale";
bool _Compare;
bool _Compare_1;
bool _MA_cross_down;
bool _MA_cross_up;
DateTime LastTradeExecution = new DateTime(0);
protected override void OnStart()
{
Positions.Closed += OnPositionsClosed;
i_Moving_Average = Indicators.ExponentialMovingAverage(MarketSeries.Close, (int)_MA_Slow_Period);
i_Moving_Average_1 = Indicators.ExponentialMovingAverage(MarketSeries.Close, (int)_MA_Fast_Period);
i_Moving_Average_2 = Indicators.ExponentialMovingAverage(MarketSeries.Close, (int)_MA_Slow_Period);
i_Moving_Average_3 = Indicators.ExponentialMovingAverage(MarketSeries.Close, (int)_MA_Fast_Period);
}
protected override void OnTick()
{
if (Trade.IsExecuting)
return;
var longPosition = Positions.Find(label, Symbol, TradeType.Buy);
var shortPosition = Positions.Find(label, Symbol, TradeType.Sell);
_Compare = (i_Moving_Average_3.Result.Last(0) >= i_Moving_Average_2.Result.Last(0));
_Compare_1 = (i_Moving_Average_1.Result.Last(1) >= i_Moving_Average.Result.Last(1));
_MA_cross_down = (!_Compare && _Compare_1);
_MA_cross_up = (_Compare && !_Compare_1);
if (_MA_cross_up && longPosition == null)
{
if (shortPosition != null)
ClosePosition(shortPosition);
ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label, StopLoss, TakeProfit);
}
else if (_MA_cross_down && shortPosition == null)
{
if (longPosition != null)
ClosePosition(longPosition);
ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label, StopLoss, TakeProfit);
}
}
private void OnPositionsClosed(PositionClosedEventArgs args)
{
var position = args.Position;
if (position.GrossProfit < 0)
{
TradeType tt = TradeType.Sell;
if (position.TradeType == TradeType.Sell)
tt = TradeType.Buy;
ExecuteMarketOrder(tt, Symbol, Symbol.NormalizeVolume(position.Volume * 2), "Martingale", StopLoss, TakeProfit);
}
}
}
}
RenkoChart close value to plot the EMA line.

collinganesh
25 Dec 2016, 18:15
Hello,
Can anyone help me to change my cBot EMA indicator from the normal candle stick EMA Close to a EMA that is used on a Renko Chart which uses a EMA RenkoChart close value to plot the EMA line. Sorry for the duplicate post.
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 martingale : Robot { [Parameter("MA Type")] public MovingAverageType MAType { get; set; } [Parameter("Source")] public DataSeries SourceSeries { get; set; } [Parameter("Stop Loss", DefaultValue = 50)] public int StopLoss { get; set; } [Parameter("Take Profit", DefaultValue = 60)] public int TakeProfit { get; set; } [Parameter("MA_Slow_Period", DefaultValue = 200)] public int _MA_Slow_Period { get; set; } [Parameter("MA_Fast_Period", DefaultValue = 50)] public int _MA_Fast_Period { get; set; } [Parameter(DefaultValue = 1000, MinValue = 0)] public int Volume { get; set; } private ExponentialMovingAverage i_Moving_Average; private ExponentialMovingAverage i_Moving_Average_1; private ExponentialMovingAverage i_Moving_Average_2; private ExponentialMovingAverage i_Moving_Average_3; private const string label = "Martingale"; bool _Compare; bool _Compare_1; bool _MA_cross_down; bool _MA_cross_up; DateTime LastTradeExecution = new DateTime(0); protected override void OnStart() { Positions.Closed += OnPositionsClosed; i_Moving_Average = Indicators.ExponentialMovingAverage(MarketSeries.Close, (int)_MA_Slow_Period); i_Moving_Average_1 = Indicators.ExponentialMovingAverage(MarketSeries.Close, (int)_MA_Fast_Period); i_Moving_Average_2 = Indicators.ExponentialMovingAverage(MarketSeries.Close, (int)_MA_Slow_Period); i_Moving_Average_3 = Indicators.ExponentialMovingAverage(MarketSeries.Close, (int)_MA_Fast_Period); } protected override void OnTick() { if (Trade.IsExecuting) return; var longPosition = Positions.Find(label, Symbol, TradeType.Buy); var shortPosition = Positions.Find(label, Symbol, TradeType.Sell); _Compare = (i_Moving_Average_3.Result.Last(0) >= i_Moving_Average_2.Result.Last(0)); _Compare_1 = (i_Moving_Average_1.Result.Last(1) >= i_Moving_Average.Result.Last(1)); _MA_cross_down = (!_Compare && _Compare_1); _MA_cross_up = (_Compare && !_Compare_1); if (_MA_cross_up && longPosition == null) { if (shortPosition != null) ClosePosition(shortPosition); ExecuteMarketOrder(TradeType.Buy, Symbol, Volume, label, StopLoss, TakeProfit); } else if (_MA_cross_down && shortPosition == null) { if (longPosition != null) ClosePosition(longPosition); ExecuteMarketOrder(TradeType.Sell, Symbol, Volume, label, StopLoss, TakeProfit); } } private void OnPositionsClosed(PositionClosedEventArgs args) { var position = args.Position; if (position.GrossProfit < 0) { TradeType tt = TradeType.Sell; if (position.TradeType == TradeType.Sell) tt = TradeType.Buy; ExecuteMarketOrder(tt, Symbol, Symbol.NormalizeVolume(position.Volume * 2), "Martingale", StopLoss, TakeProfit); } } } }@collinganesh