- ago
I would like to have 2 Price panes. One for the regular candlesticks and the other for Heiken-Ashi candlesticks, is this possible in WL7? How di I do that?
0
1,629
Solved
13 Replies

Reply

Bookmark

Sort
Glitch8
 ( 11.21% )
- ago
#1
We don't have a method to plot a BarHistory using a specific chart style, but we can add an enhancement to do this for Build 2.
0
Glitch8
 ( 11.21% )
- ago
#2
For Build 2 this will do it ...
CODE:
//Initialize public override void Initialize(BarHistory bars) {          PlotBarHistoryStyle(bars, "BarPane", "Candlestick", Color.Navy); }
0
Best Answer
- ago
#3
I see the Heikin-Ashi indicator now.
If I want to work with the Heikin-Ashi data, do build that my self or is there a way to get that from the chart?
0
Glitch8
 ( 11.21% )
- ago
#4
We don't have anything code-wise to return H/A values, so at least for now you're on your own!
0
- ago
#5
Maybe something like this might help for the time being?
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript5 { public class MyStrategy : UserStrategyBase {       BarHistory ha;           //create indicators and other objects here, this is executed prior to the main trading loop public override void Initialize(BarHistory bars) {          ha = new BarHistory("Heikin Ashi", bars.Scale);          // Create Heikin-Ashi series          TimeSeries HO = bars.Open + 0;          TimeSeries HH = bars.High + 0;          TimeSeries HL = bars.Low + 0;          TimeSeries HC = bars.AveragePriceOHLC + 0;          // Build the Bars object          for (int bar = 0; bar < bars.Count; bar++)          {             if (bar == 0)             {                ha.Add(bars.DateTimes[0], bars.Open[0], bars.Open[0], bars.Open[0], bars.Open[0], bars.Volume[0]);             }             else             {                double o1 = bars.Open[bar - 1];                double c1 = bars.Close[bar - 1];                HO[bar] = (o1 + c1) / 2;                HH[bar] = Math.Max(HO[bar], bars.High[bar]);                HL[bar] = Math.Min(HO[bar], bars.Low[bar]);                ha.Add(bars.DateTimes[bar], HO[bar], HH[bar], HL[bar], HC[bar], bars.Volume[bar]);             }          }          PlotBarHistoryStyle(ha, "HAPane", "Candlestick", Color.Navy);       } //execute the strategy rules here, this is executed once for each bar in the backtest history public override void Execute(BarHistory bars, int idx) { if (!HasOpenPosition(bars, PositionType.Long)) { //code your buy conditions here } else { //code your sell conditions here } } //declare private variables below } }
0
- ago
#6
Yes, I used my own code.
Thank you
0
- ago
#7
Hi,
Using the code above, is there any way to color the individual bars in the HAPane? I'm just looking for a short example.
Thanks,
Mike
0
- ago
#8
You could for example modify the line that does the plotting like this:
CODE:
//PlotBarHistoryStyle(ha, "HAPane", "Candlestick", Color.Navy); PlotBarHistoryStyle(ha, "HAPane", "Candlestick");
0
- ago
#9
Thanks, Eugene.

But is there another way to individually color the bars?
0
Cone8
 ( 5.78% )
- ago
#10
CODE:
SetBarColor
0
- ago
#11
Thanks, Cone.

I've posted my code below. What am I doing wrong? Nothing shows up in the Heiken Ashi pane.


CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript5 {    public class MyStrategy : UserStrategyBase    {       BarHistory ha;       //create indicators and other objects here, this is executed prior to the main trading loop       public override void Initialize(BarHistory bars)       {          ha = new BarHistory("Heikin Ashi", bars.Scale);          // Create Heikin-Ashi series          TimeSeries HO = new EMA(bars.Open, 14);          TimeSeries HH = new EMA(bars.High, 14);          TimeSeries HL = new EMA(bars.Low, 14);          TimeSeries HC = new EMA(bars.Close, 14);          // Build the Bars object          for (int bar = 0; bar < bars.Count; bar++)          {             if (bar == 0)             {                ha.Add(bars.DateTimes[0], bars.Open[0], bars.Open[0], bars.Open[0], bars.Open[0], bars.Volume[0]);             }             else             {                double o1 = bars.Open[bar - 1];                double c1 = bars.Close[bar - 1];                HC[bar] = (HO[bar] +HH[bar] +HL[bar] +HC[bar]) /4.0;                HO[bar] = (o1 + c1) / 2;                HH[bar] = Math.Max(HH[bar], Math.Max(HO[bar], HC[bar]));                HL[bar] = Math.Min(HL[bar], Math.Min(HO[bar], HC[bar]));                ha.Add(bars.DateTimes[bar], HO[bar], HH[bar], HL[bar], HC[bar], bars.Volume[bar]);                if (HC[bar] > HO[bar])                   SetBarColor(ha, bar, WLColor.Green);                else                   SetBarColor(ha, bar, WLColor.Red);                             }          }          //PlotBarHistoryStyle(ha, "HAPane", "Candlestick", WLColor.Navy);          PlotBarHistoryStyle(ha, "HAPane", "Candlestick");       }       //execute the strategy rules here, this is executed once for each bar in the backtest history       public override void Execute(BarHistory bars, int idx)       {          if (!HasOpenPosition(bars, PositionType.Long))          {             //code your buy conditions here          }          else          {             //code your sell conditions here          }       }       //declare private variables below    } }
0
- ago
#12
Just do it the other way round:
CODE:
using WealthLab.Backtest; using System; using WealthLab.Core; using WealthLab.Indicators; using System.Drawing; using System.Collections.Generic; namespace WealthScript5 {    public class MyStrategy : UserStrategyBase    {       BarHistory ha;       public override void Initialize(BarHistory bars)       {          ha = new BarHistory("Heikin Ashi", bars.Scale);          // Create Heikin-Ashi series          TimeSeries HO = new EMA(bars.Open, 14);          TimeSeries HH = new EMA(bars.High, 14);          TimeSeries HL = new EMA(bars.Low, 14);          TimeSeries HC = new EMA(bars.Close, 14);          // Build the Bars object          for (int bar = 0; bar < bars.Count; bar++)          {             if (bar == 0)             {                ha.Add(bars.DateTimes[0], bars.Open[0], bars.Open[0], bars.Open[0], bars.Open[0], bars.Volume[0]);             }             else             {                double o1 = bars.Open[bar - 1];                double c1 = bars.Close[bar - 1];                HC[bar] = (HO[bar] + HH[bar] + HL[bar] + HC[bar]) / 4.0;                HO[bar] = (o1 + c1) / 2;                HH[bar] = Math.Max(HH[bar], Math.Max(HO[bar], HC[bar]));                HL[bar] = Math.Min(HL[bar], Math.Min(HO[bar], HC[bar]));                ha.Add(bars.DateTimes[bar], HO[bar], HH[bar], HL[bar], HC[bar], bars.Volume[bar]);             }          }          PlotBarHistoryStyle(ha, "HAPane", "Candlestick");          for (int bar = 0; bar < bars.Count; bar++)          {             SetBarColor(ha, bar, (HC[bar] > HO[bar]) ? WLColor.Green : WLColor.Red);          }       }       public override void Execute(BarHistory bars, int idx)       {       }    } }
1
- ago
#13
Thanks, Eugene. You guys offer excellent customer support!!
1

Reply

Bookmark

Sort