CBots to Recognize the start of Trend
CBots to Recognize the start of Trend
03 Jan 2020, 06:46
All
I am using the supertrend indicator found on this site https://ctrader.com/algos/indicators/show/136 , is it possible for Cbots to recognizes only the start of the trend/change of trend and disregard proceeding trend plots
see figure below
Replies
michaelocampo1104@gmail.com
07 Jan 2020, 09:05
RE:
Dear Panagoitis
Please see below my draft code or should i do it on the indicator itself? if so does the IsLast bar can do the job?
Thank you 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 SuperTrendBot : Robot
{
#region Declarations
private Supertrend _supertrend;
#endregion
#region Indicator Parameters
//Super Trend
[Parameter("STPeriod", DefaultValue = 10)]
public int Period { get; set; }
[Parameter("SuperTrend Multiplier", DefaultValue = 3)]
public int Multiplier { get; set; }
#endregion
//SuperTrend
#region Indicator Output
[Output("UpTrend")]
public IndicatorDataSeries UpTrend { get; set; }
[Output("Downtrend")]
public IndicatorDataSeries DownTrend { get; set; }
#endregion
#region Risk management
[Parameter("Stop Loss", DefaultValue = 30)]
public double _SL { get; set; }
[Parameter("Take Profit", DefaultValue = 60)]
public double _TP { get; set; }
private int _volume;
#endregion
#region Initialize
protected override void OnStart()
{
_supertrend = Indicators.GetIndicator<Supertrend>(Period, Multiplier);
}
#endregion
#region Bot Logic
protected override void OnBar()
{
if (!double.IsNaN(_supertrend.UpTrend.LastValue))
{
ExecuteMarketOrder(TradeType.Buy, Symbol, _volume, "Buy1", _SL, _TP);
}
if (!double.IsNaN(_supertrend.DownTrend.LastValue))
{
ExecuteMarketOrder(TradeType.Sell, Symbol, _volume, "Sell1", _SL, _TP);
}
}
#endregion
protected override void OnTick()
{
}
#region On Stop
protected override void OnStop()
{
}
#endregion
}
PanagiotisCharalampous said:
Hi there,
Yes this is possible. You need to detect at which bar does the trend change happen.
Best Regards,
Panagiotis
@michaelocampo1104@gmail.com
michaelocampo1104@gmail.com
17 Jan 2020, 04:00
RE: RE: HI All, much appreciate on your help below
michaelocampo1104@gmail.com said:
Dear Panagoitis
Please see below my draft code or should i do it on the indicator itself? if so does the IsLast bar can do the job?
Thank you 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 SuperTrendBot : Robot
{
#region Declarationsprivate Supertrend _supertrend;
#endregion#region Indicator Parameters
//Super Trend
[Parameter("STPeriod", DefaultValue = 10)]
public int Period { get; set; }[Parameter("SuperTrend Multiplier", DefaultValue = 3)]
public int Multiplier { get; set; }#endregion
//SuperTrend
#region Indicator Output
[Output("UpTrend")]
public IndicatorDataSeries UpTrend { get; set; }[Output("Downtrend")]
public IndicatorDataSeries DownTrend { get; set; }
#endregion#region Risk management
[Parameter("Stop Loss", DefaultValue = 30)]
public double _SL { get; set; }[Parameter("Take Profit", DefaultValue = 60)]
public double _TP { get; set; }private int _volume;
#endregion
#region Initialize
protected override void OnStart()
{_supertrend = Indicators.GetIndicator<Supertrend>(Period, Multiplier);
}
#endregion
#region Bot Logic
protected override void OnBar()
{
if (!double.IsNaN(_supertrend.UpTrend.LastValue))
{
ExecuteMarketOrder(TradeType.Buy, Symbol, _volume, "Buy1", _SL, _TP);
}if (!double.IsNaN(_supertrend.DownTrend.LastValue))
{
ExecuteMarketOrder(TradeType.Sell, Symbol, _volume, "Sell1", _SL, _TP);
}}
#endregion
protected override void OnTick()
{
}
#region On Stop
protected override void OnStop()
{
}
#endregion}
PanagiotisCharalampous said:
Hi there,
Yes this is possible. You need to detect at which bar does the trend change happen.
Best Regards,
Panagiotis
@michaelocampo1104@gmail.com
PanagiotisCharalampous
07 Jan 2020, 08:53
Hi there,
Yes this is possible. You need to detect at which bar does the trend change happen.
Best Regards,
Panagiotis
Join us on Telegram
@PanagiotisCharalampous