Trying to display icon / text buy and sell on candlestick chart based on UT Bot indicator
Trying to display icon / text buy and sell on candlestick chart based on UT Bot indicator
25 Dec 2022, 22:17
Hi, I'm trying trying to display icon or text with buy and sell signal on candlestick chart based on UT Bot indicator but I'm not really managing to display the text or icon on the chart ,
so this is what I have by now :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;
namespace cAlgo
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class UTBotCA23 : Indicator
{
[Parameter("Key", DefaultValue = 1)]
public double Key_Value { get; set; }
[Parameter("ATR Period", DefaultValue = 10)]
public int ATR_Period { get; set; }
private AverageTrueRange xATR;
//[Output("UpTrend", PlotType = PlotType.DiscontinuousLine, LineColor = "Green")]
public IndicatorDataSeries XATRTrailingStopGreen { get; set; }
//[Output("Continuos", PlotType = PlotType.DiscontinuousLine, LineColor = "Green")]
public IndicatorDataSeries XATRTrailingStop { get; set; }
//[Output("DownTrend", PlotType = PlotType.DiscontinuousLine, LineColor = "Red")]
public IndicatorDataSeries XATRTrailingStopRed { get; set; }
protected override void Initialize()
{
xATR = Indicators.AverageTrueRange(ATR_Period, MovingAverageType.Exponential);
}
public override void Calculate(int index)
{
double nLoss = Key_Value * xATR.Result[index];
XATRTrailingStop[index] = (Bars.ClosePrices[index] > XATRTrailingStop[index - 1] && Bars.ClosePrices[index - 1] > XATRTrailingStop[index - 1]) ? Math.Max(XATRTrailingStop[index - 1], Bars.ClosePrices[index] - nLoss) : (Bars.ClosePrices[index] < XATRTrailingStop[index - 1] && Bars.ClosePrices[index - 1] < XATRTrailingStop[index - 1]) ? Math.Min(XATRTrailingStop[index - 1], Bars.ClosePrices[index] + nLoss) : (Bars.ClosePrices[index] > XATRTrailingStop[index - 1]) ? Bars.ClosePrices[index] - nLoss : Bars.ClosePrices[index] + nLoss;
XATRTrailingStopGreen[index] = XATRTrailingStop[index] < Bars.ClosePrices[index] ? XATRTrailingStop[index] : double.NaN;
XATRTrailingStopRed[index] = XATRTrailingStop[index] > Bars.ClosePrices[index] ? XATRTrailingStop[index] : double.NaN;
Chart.DrawIcon("Buy", ChartIconType.UpTriangle, Bars.OpenTimes.LastValue, XATRTrailingStopGreen[index] , Color.Green);
Chart.DrawIcon("Sell", ChartIconType.DownTriangle, Bars.OpenTimes.LastValue, XATRTrailingStopRed[index] , Color.Red);
}
}
}
Replies
PanagiotisChar
27 Dec 2022, 12:03
Hi there,
You need to use a different name for each icon else it overrides the previous one.
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar
phaniophrero
27 Dec 2022, 13:55
RE:
PanagiotisChar said:
Hi there,
You need to use a different name for each icon else it overrides the previous one.
Need help? Join us on Telegram
Need premium support? Trade with us
Hi, well I think I'm using different names for each icon, one is called Buy, and the other one is Sell, or what do you mean?
@phaniophrero
phaniophrero
28 Dec 2022, 20:53
( Updated at: 29 Dec 2022, 00:42 )
RE: This is what I want it to look like
PanagiotisChar said:
Hi there,
You need to use a different name for each icon else it overrides the previous one.
Need help? Join us on Telegram
Need premium support? Trade with us
Hi, I want to make this indicator look like this UT-Bot Indicator from TradingView :
https://www.tradingview.com/script/n8ss8BID-UT-Bot-Alerts/
Could you tell me how can I manage to do that ?
Thankyou !
@phaniophrero
PanagiotisChar
29 Dec 2022, 09:35
Hi there,
Each different icon on the chart needs to have a unique name. If you use "Buy" for all Buy icons then you will only have one Buy icon at each time, as the last one overrides the previous ones. Try adding to the name the bar's open price
Chart.DrawIcon("Buy"+ Bars.OpenTimes[index].ToString(), ChartIconType.UpTriangle, Bars.OpenTimes.LastValue, XATRTrailingStopGreen[index] , Color.Green);
Need help? Join us on Telegram
Need premium support? Trade with us
@PanagiotisChar
phaniophrero
25 Dec 2022, 22:28
RE:
phaniophrero said:
Quick update , so it actually shows the icon if I uncomment those 3 outputs at the top , but it's showing a single icon for the last Uptrend , and I want to show the icons for past candles as well and also I'd like to get rid of the lines and only show the icons , how can i do that ?
@phaniophrero