Supertrend for Renko
Supertrend for Renko
07 Oct 2018, 21:08
I need help with this Supertrend cBot, but I do not know how doing it correctly. Any help is very appreciated.
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
[Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class RenkoSupertrend : Robot
{
[Parameter("UpTrend", DefaultValue = 2, MinValue = 0)]
public int UpTrend { get; set; }
[Parameter("DownTrend", DefaultValue = 3, MinValue = 0)]
public int DownTrend { get; set; }
[Parameter("Quantity (Lots)", DefaultValue = 1, MinValue = 0.01, Step = 0.01)]
public double Quantity { get; set; }
private Supertrend cTrend;
protected override void OnStart()
{
cTrend = Indicators.GetIndicator<Supertrend>(UpTrend, DownTrend);
var tradeType = cTrend.Result.LastValue < Symbol.Bid ? TradeType.Buy : TradeType.Sell;
var volumeInUnits = Symbol.QuantityToVolume(Quantity);
ExecuteMarketOrder(tradeType, Symbol, volumeInUnits, "Supertrend");
}
protected override void OnTick()
{
var position = Positions.Find("cTrend", Symbol);
if (position == null)
Stop();
else
{
double newStopLoss = cTrend.Result.LastValue;
bool isProtected = position.StopLoss.HasValue;
if (position.TradeType == TradeType.Buy && isProtected)
{
if (newStopLoss > Symbol.Bid)
return;
if (newStopLoss - position.StopLoss < Symbol.TickSize)
return;
}
if (position.TradeType == TradeType.Sell && isProtected)
{
if (newStopLoss < Symbol.Bid)
return;
if (position.StopLoss - newStopLoss < Symbol.TickSize)
return;
}
ModifyPosition(position, newStopLoss, null);
}
}
}
}
Replies
aw52uk@gmail.com
08 Oct 2018, 11:36
Hi Panagiotis Charalampous.
I am asking for help with this : "cTrend.Result.LastValue".
I basically need to understand how to program the last value of custom indicator.
I am trying to compile this one with errors.
cTrend = Indicators.GetIndicator<Supertrend>(UpTrend, DownTrend);
var tradeType = cTrend.Result.LastValue < Symbol.Bid ? TradeType.Buy : TradeType.Sell;
@aw52uk@gmail.com
PanagiotisCharalampous
08 Oct 2018, 11:42
Hi aw52uk@gmail.com,
Supertrend does not seem to have any output named Result. You can use UpTrend and DownTrend.
Best Regards,
Panagiotis
@PanagiotisCharalampous
PanagiotisCharalampous
08 Oct 2018, 10:12
Hi aw52uk@gmail.com,
What kind of help do you need?
Best Regards,
Panagiotis
@PanagiotisCharalampous