NexusFi: Find Your Edge


Home Menu

 





Convert NinjaScript to ThinkScript Help


Discussion in ThinkOrSwim

Updated
    1. trending_up 2,702 views
    2. thumb_up 0 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread

Convert NinjaScript to ThinkScript Help

  #1 (permalink)
devildriver6
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);
}
}
}

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
REcommedations for programming help
Sierra Chart
Exit Strategy
NinjaTrader
ZombieSqueeze
Platforms and Indicators
Better Renko Gaps
The Elite Circle
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #2 (permalink)
tangerine
albuquerque nm/usa
 
Posts: 29 since Aug 2015
Thanks Given: 3
Thanks Received: 9


devildriver6 View Post
I have this script for a Median Renko bar I'm trying to get into ToS.... Can anyone help?...

Well, I can't read Ninja but this should help you get started. I became interested in Renko bars awhile back and wrote several TS scripts. BTW, you do know that you can set TOS to display Renko bars? STYLE>>AGGREGATION>>RANGE, then go back and STYLE>>SETTINGS>>TIME_AXIS>>RANGE_TYPE>>RENKO_BARS.
 
Code
#RENKO HILO 1 CANDLE (combo 2 CANDLES h-h and l-l)
declare lower;
input renkosizeup = .0005;
input renkosizedown = .0005;
input renkoHIGHrange = 1;
input renkoLOWrange = 2;
def renko1 = high-low[renkoLOWrange]>=renkosizeup;
def renko1a = high-low[renkoLOWrange]>=renkosizeup AND 
high[renkoHIGHrange]-low[renkoLOWrange]>=renkosizeup;
def renko2 = low[renkoLOWrange]-high>=renkosizedown;
def renko2a = low[renkoLOWrange]-high>=renkosizedown AND
low[renkoLOWrange]-high[renkoHIGHrange]<=renkosizedown;;

plot Above = renko1a;
Above.SetDefaultColor(Color.UPTICK);
Above.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);

plot Below = renko2a;
Below.SetDefaultColor(Color.DOWNTICK);
BELOW.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
plot zeroline = 0;
my "renkosizeup" and "renkosizedown" .0005 input settings are for forex. if you trade something else, you might want more convenient default settings. The above code won't display bricks but the advantage is that you'll be able to see price/time on the chart and in the lower study (arrows) detect bricks forming. Best of both worlds, I think.

Reply With Quote
  #3 (permalink)
brucehank
ottawa canada
 
Posts: 20 since Oct 2015
Thanks Given: 0
Thanks Received: 2


You have to Give it up, TOS doesn't support custom chart type.

Reply With Quote




Last Updated on October 16, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts