- ago
I want to create an indicator that displays values as candlesticks. Now I'm using PlotStyle.BarChart, the most appropriate drawing style for my purposes.

Is there a way to draw the indicator in the form of candles?
1
926
Solved
23 Replies

Reply

Bookmark

Sort
Cone8
 ( 4.98% )
- ago
#1
Probably the lack of response is due to not understanding the goal.

Can you give us an example of "an indicator (a TimeSeries of numbers) that displays values as candlesticks?"
What does that look like exactly? Please post an image, even if you have to draw it by hand.
0
Glitch8
 ( 10.62% )
- ago
#2
Currently the only indicator that does this is VChart:

https://www.wealth-lab.com/Discussion/ValueChart-BarChart-Close-not-inside-High-Low-range-of-bar-on-symbol-change-6964

If you submit a #FeatureRequest we can eventually provide a new plot style that would let you select the chart style to use to render an indicator like VChart.
0
- ago
#3
I clarify what I meant.



Glitch, can you please tag this thread as #FeatureRequest or do I need to create a new one?
0
- ago
#4
Sorry but we cannot tag this as #FeatureRequest since that OHLC vs. Candle comparison (thanks but we do know the difference!) doesn't answer Cone's question in detail. Denis, what does your indicator do exactly? Does it have 4 or more values at a given bar? It's important to understand because there may be a different solution that you just don't know about. And it may not be an indicator.
0
- ago
#5
I need the ability to build an indicator completely similar to VChart. Only for the bar to be displayed as a candle. As far as I understand, the new display mode should not affect the internal operation of the indicator in any way. Since the bar and the candle are built according to four values. I need an indicator. I know how to do it through an adviser.
0
- ago
#6
Denis, you still haven't explained why you think that you need the ability to build an indicator completely similar to VChart. Why not PlotBarHistory, for example? Clarify your task.
0
Glitch8
 ( 10.62% )
- ago
#7
Yes, the idea is it would just be a new plot style that you could use to plot VChart, but select a different chart style, Candle for example, instead of always having to plot it in the Bar style.

We could possibly just add the parameter to the existing plot style, will take a look.
0
- ago
#8
It's just about a new style of drawing the indicator. I don't need a VChart indicator as such. I just want to be able to draw candlesticks for indicators that I will write myself.

Why an indicator? Because I just want to use it as an indicator, it's convenient for me. For example, be able to move it to charts.
0
- ago
#9
QUOTE:
I just want to be able to draw candlesticks for indicators that I will write myself.

You should already able to do it by calling PlotBarHistoryStyle if you pass on "Candlestick" as the ChartStyle name parameter. Just create a BarHistory, assigning your four indicator values to its OHLC.
0
Glitch8
 ( 10.62% )
- ago
#10
We have a way of doing this with an indicator coming in Build 23!
0
- ago
#11
Eugene, did according to your advice. Can't compile code. Please help me implement your method.

CODE:
using WealthLab.Core; using System; using System.Drawing; using WealthLab.Indicators; namespace WealthLab.Indicators {    public class MyStrategy : WealthLab.Backtest.UserStrategyBase    {       public override void Execute(BarHistory bars, int idx)       {                       }    }        //the VChart indicator    public class DOMQuantityAskCandles : IndicatorBase    {       //parameterless constructor       public DOMQuantityAskCandles() : base()       {       }       //for code based construction       public DOMQuantityAskCandles(BarHistory source, PriceComponent pc)          : base()       {                   Parameters[0].Value = source;                   Parameters[1].Value = pc;          Populate();       }       //static method       public static DOMQuantityAskCandles Series(BarHistory source, PriceComponent pc)       {          string key = CacheKey("DOMQuantityAskCandles", pc);          if (source.Cache.ContainsKey(key))             return (DOMQuantityAskCandles)source.Cache[key];          DOMQuantityAskCandles vchart = new DOMQuantityAskCandles(source, pc);          source.Cache[key] = vchart;          return vchart;       }       //Name       public override string Name => "Value Chart";       //Abbreviation       public override string Abbreviation => "DOMQuantityAskCandles";       //description       public override string HelpDescription => "The Value Charts indicator developed by Mark W. Helweg. Applies a volatility based detrending to the source price component.";       //pane       public override string PaneTag => "DOMQuantityAskCandles";       //access price component used       public PriceComponent PriceComponent1 => Parameters[1].AsPriceComponent;       //default color       public override WLColor DefaultColor => WLColor.Red;             //default plot style       public override PlotStyle DefaultPlotStyle => PlotStyle.BarChart;       //populate       public override void Populate()       {          //get parameter values          BarHistory source = Parameters[0].AsBarHistory;          if (source == null)             return;          PriceComponent pc = Parameters[1].AsPriceComponent;          BarHistory quantityAsk = new BarHistory(Bars);          TimeSeries o = Bars.NamedSeries["Open Quantity Ask"];          TimeSeries h = Bars.NamedSeries["High Quantity Ask"];          TimeSeries l = Bars.NamedSeries["Low Quantity Ask"];          TimeSeries c = Bars.NamedSeries["Close Quantity Ask"];          TimeSeries v = Bars.NamedSeries["Vol Quantity Ask"];                for (int bar = 0; bar < Bars.Count; bar++)          {             quantityAsk.Add(Bars.DateTimes[bar], o[bar], h[bar], l[bar], c[bar], v[bar]);          }          MyStrategy sb = new MyStrategy();          sb.PlotBarHistoryStyle(quantityAsk, "quantityAsk", "Candlestick", WLColor.Red);          //DrawHeaderText("Quantity Ask", "quantityAsk");          //set datetimes          DateTimes = source.DateTimes;                 }       //generate parameters       protected override void GenerateParameters()       {          AddParameter("Source", ParameterType.BarHistory, null);                   AddParameter("Price Component", ParameterType.PriceComponent, PriceComponent.Close);       }       //get corresponding bar chart companion indicator       public override IndicatorBase GetBarChartCompanion(PriceComponent pc)       {          if (PriceComponent1 == pc)             return this;          return new DOMQuantityAskCandles(Parameters[0].AsBarHistory, pc);       }    } }
0
- ago
#12
CODE:
         MyStrategy sb = new MyStrategy();          sb.PlotBarHistoryStyle(quantityAsk, "quantityAsk", "Candlestick", WLColor.Red);

I didn't mean you would create a blank strategy with no fields assigned. That won't work without proper initialization.

The idea is to do it the other way round: create a BarHistory object on-the-fly (you're doing it with the quantityAsk object) in your Strategy and plot it using PlotBarHistoryStyle. This is going to work in any WL build.

Or wait for B23.
0
Glitch8
 ( 10.62% )
- ago
#13
No need to wait, Build 23 is released!
0
- ago
#14
Installed assembly 23. Everything works. Thank you!

Please help me to set this default display method in the indicator code.
0
- ago
#15
QUOTE:
Please help me to set this default display method in the indicator code.

I see an issue with plotting the VChart. If a different chart style is selected (e.g. Candlestick) it's still plotted as BarChart. Workaround: change settings (e.g. enable/disable 'Use chart colors' or change to the real BarChart and then re-apply chosen style i.e. Candlestick). We need to get this fixed.
0
- ago
#16
QUOTE:
I see an issue with plotting the VChart.

OK, Dion nailed it for B24.
0
Glitch8
 ( 10.62% )
- ago
#17
To answer your other question, you can plot it in code using the new PlotIndicatorChartStyle method.
0
- ago
#18
I need to set the default display style for the indicator, not build the indicator with the desired style through a strategy.
0
- ago
#19
Aren't you already doing it?
CODE:
//default plot style public override PlotStyle DefaultPlotStyle => PlotStyle.BarChart;
0
- ago
#20
Yes, you are right, I already have such code. But it does not set the drawing style of the candlesticks. By default, bars are always displayed. And every time I install the indicator, I have to change the display style from bars to candles. I want to make it so that I have candles by default. I think that this can be somehow set in the indicator code.

Please advise how to do this.
0
- ago
#21
There is no PlotStyle for candlesticks. But you can use "Candlestick" as the ChartStyle parameter with the VChart indicator. This was the change in B23. Hope this helps.
0
Cone8
 ( 4.98% )
- ago
#22
CODE:
         VChart vChart = VChart.Series(bars, 20, PriceComponent.Close);          PlotIndicatorChartStyle(vChart, WLColor.AliceBlue, 2, true, "Candlestick");
0
Glitch8
 ( 10.62% )
- ago
#23
Hi Denis, unfortunately it’s not possible to change the default value of a plot style parameter. You’ll need to perform that extra click to change it from the default Bar to Candlestick whenever you drop it onto the chart.

If you save a Workspace, you’re choice will be retained though.
0
Best Answer

Reply

Bookmark

Sort