Dallas, Texas
Posts: 43 since Jun 2015
Thanks Given: 2
Thanks Received: 32
|
I have this script for a Median Renko bar I'm trying to get into ToS.... Can anyone help?
{
public class MedianRenkoBarsType : BarsType
{
#pragma warning disable 169
// ReSharper disable InconsistentNaming
private static bool registered = Register(new MedianRenkoBarsType());
// ReSharper restore InconsistentNaming
#pragma warning restore 169
public override void Add(Bars bars, double open, double high, double low, double close, DateTime time,int volume, bool isRealtime){ if (bars.Count < 2){
# AddBar(bars, open, high, low, close, time, volume);
return;
}
# Bar bar = (Bar)bars.Get(bars.Count - 1);
# Bar bar1 = (Bar)bars.Get(bars.Count - 2);
# double tickSize = bars.Instrument.MasterInstrument.TickSize;
double rangeValue = Math.Floor(10000000.0 * bars.Period.Value * tickSize) / 10000000.0;
double mymax = bar1.Close >= bar1.Open ? bar1.Close : bar1.Close + rangeValue;
double mymin = bar1.Close <= bar1.Open ? bar1.Close : bar1.Close - rangeValue;
if (bars.Instrument.MasterInstrument.Compare(close, mymax + rangeValue) >= 0)
{
UpdateBar(bars, open, mymax + rangeValue, low, mymax + rangeValue, time, 0);
bool isLastNewBar = close < mymax + 2 * rangeValue;
double newBarOpen = (mymax + bar.Close) * 0.5;
double newClose = Math.Min(bar.Close + rangeValue, close);
double oldClose = bar.Close;
do
{
AddBar(bars, newBarOpen, newClose, newBarOpen, newClose, time, isLastNewBar ? volume : 0);
newBarOpen = (newClose + oldClose) * 0.5;
oldClose = newClose;
newClose = Math.Min(newClose + rangeValue, close);
isLastNewBar = close == newClose;
}
while (bars.Instrument.MasterInstrument.Compare(close, newClose) > 0);
}
else
if (bars.Instrument.MasterInstrument.Compare(mymin - rangeValue, close) >= 0)
{
UpdateBar(bars, open, high, mymin - rangeValue, mymin - rangeValue, time, 0);
double newClose = Math.Max(bar.Close - rangeValue, close);
double newBarOpen = (mymin + bar.Close) * 0.5;
double oldClose = bar.Close;
bool isLastNewBar = close > mymin - 2 * rangeValue;
do
{
AddBar(bars, newBarOpen, newBarOpen, newClose, newClose, time, isLastNewBar ? volume : 0);
newBarOpen = (newClose + oldClose) * 0.5;
oldClose = newClose;
newClose = Math.Max(newClose - rangeValue, close);
isLastNewBar = close == newClose;
}
while (bars.Instrument.MasterInstrument.Compare(newClose, close) > 0);
}
else
UpdateBar(bars, open, high, low, close, time, volume);
}
public override PeriodType BuiltFrom
{
get { return PeriodType.Tick; }
}
public override string ChartDataBoxDate(DateTime time)
{
return time.ToString(Cbi.Globals.CurrentCulture.DateTimeFormat.ShortDatePattern);
}
public override string ChartLabel(Gui.Chart.ChartControl chartControl, DateTime time)
{
return time.ToString(chartControl.LabelFormatTick, Cbi.Globals.CurrentCulture);
}
public override object Clone()
{
return new MedianRenkoBarsType();
}
public override int DaysBack
{
get { return Gui.Chart.ChartData.DaysBackTick; }
}
public override int DefaultValue
{
get { return 4; }
}
public override string DisplayName
{
get { return "MedianRenko"; }
}
public override bool IsIntraday
{
get { return true; }
}
public override bool IsTimeBased
{
get { return false; }
}
public override int MaxLookBackDays
{
get { return 10; }
}
public override int MaxValue
{
get { return -1; }
}
public override double GetPercentComplete(Bars bars, DateTime now)
{
throw new ApplicationException("GetPercentComplete not supported in " + DisplayName);
}
public MedianRenkoBarsType() : base(PeriodType.Custom5) {}
public override int SortOrder
{
get { return 13007; }
}
public override string ToString(Period period)
{
return String.Format("MedianRenko {0} Ticks", period.Value);
}
}
}
|