Ninjatrader BetterRenko
Forums › ProRealTime English forum › ProBuilder support › Ninjatrader BetterRenko
- This topic has 6 replies, 3 voices, and was last updated 2 years ago by MnA.
-
-
09/23/2019 at 3:08 PM #108274
Hi Nicolas,
Was wondering if you could convert a Ninjatrader script to PRT?
I like using this Renko indicator on Ninjatrader when I trade futures.
I have attached the code below that I obtained from the CS file and also a Pic as to how it looks like.
Thanks, I appreciate your help.Regards
Better Renko123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199#region Using declarationsusing System;using System.Collections.Generic;using System.ComponentModel;using System.ComponentModel.DataAnnotations;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Input;using System.Windows.Media;using System.Xml.Serialization;using NinjaTrader.Cbi;using NinjaTrader.Gui;using NinjaTrader.Gui.Chart;using NinjaTrader.Gui.SuperDom;using NinjaTrader.Data;using NinjaTrader.NinjaScript;using NinjaTrader.Core.FloatingPoint;#endregion//// BetterRenkoBarsType//// written by aslan//// 20100807 - created BetterRenko to address issues with other types of Renko bars// 20101118 - changed initial brick alignment to brick size// 20150719 - DaleBru converted to NT8// 20160508 - antonma fixed the SessionIterator compiler error NJ8 8.0.0.9////This namespace holds Bars types in this folder and is required. Do not change it.namespace NinjaTrader.NinjaScript.BarsTypes{public class BetterRenkoBarsType : BarsType{private enum RenkoState { BarComplete, BarAccumulating };private RenkoState barRenkoState = RenkoState.BarComplete;private double renkoHigh;private double renkoLow;protected override void OnStateChange(){if (State == State.SetDefaults){Description = @"NT8 translation of BetterRenko by aslan";Name = "BetterRenko";BarsPeriod = new BarsPeriod { BarsPeriodType = (BarsPeriodType) 17, BarsPeriodTypeName = "BetterRenko(17)", Value = 1 };BuiltFrom = BarsPeriodType.Tick;DaysToLoad = 3;IsIntraday = true;DefaultChartStyle = Gui.Chart.ChartStyleType.CandleStick;}else if (State == State.Configure){Name = string.Format(Core.Globals.GeneralOptions.CurrentCulture, "{0} BetterRenko{1}", BarsPeriod.Value, (BarsPeriod.MarketDataType != MarketDataType.Last ? string.Format(" - {0}", Core.Globals.ToLocalizedObject(BarsPeriod.MarketDataType, Core.Globals.GeneralOptions.CurrentUICulture)) : string.Empty));Properties.Remove(Properties.Find("BaseBarsPeriodType", true));Properties.Remove(Properties.Find("BaseBarsPeriodValue", true));Properties.Remove(Properties.Find("PointAndFigurePriceType", true));Properties.Remove(Properties.Find("ReversalType", true));Properties.Remove(Properties.Find("Value2", true));SetPropertyName("Value", "BrickSize");}}public override int GetInitialLookBackDays(BarsPeriod barsPeriod, TradingHours tradingHours, int barsBack){return 3;}protected override void OnDataPoint(Bars bars, double open, double high, double low, double close, DateTime time, long volume, bool isBar, double bid, double ask){var brickSize = bars.Instrument.MasterInstrument.RoundToTickSize(bars.BarsPeriod.Value * bars.Instrument.MasterInstrument.TickSize); // #ticks per brick * tickSize// build a session iterator from the bars object being updatedif (SessionIterator == null)SessionIterator = new SessionIterator(bars);if (SessionIterator.IsNewSession(time, isBar)){SessionIterator.GetNextSession(time, isBar);}if (bars.Count == 0 || bars.IsResetOnNewTradingDay && SessionIterator.IsNewSession(time, isBar)){if (bars.Count > 0){// Close out last bar in session and set open == closedouble lastBarClose = bars.GetClose(bars.Count - 1);DateTime lastBarTime = bars.GetTime(bars.Count - 1);long lastBarVolume = bars.GetVolume(bars.Count - 1);bars.RemoveLastBar();AddBar(bars, lastBarClose, lastBarClose, lastBarClose, lastBarClose, lastBarTime, lastBarVolume);}barRenkoState = RenkoState.BarAccumulating;double mod = bars.Instrument.MasterInstrument.RoundToTickSize(close % brickSize);double mid = bars.Instrument.MasterInstrument.Compare(mod, brickSize) == 0 ? close : close - mod;renkoHigh = mid + brickSize;renkoLow = mid - brickSize;AddBar(bars, close, close, close, close, time, volume);bars.LastPrice = close;return;}if (barRenkoState == RenkoState.BarComplete){// this tick creates a new barAddBar(bars, close, close, close, close, time, volume);if (RangeExceeded(bars.Instrument.MasterInstrument, close)){MoveLimits(bars.Instrument.MasterInstrument, close, brickSize);}}else{if (RangeExceeded(bars.Instrument.MasterInstrument, close)){AddBar(bars, close, close, close, close, time, volume);MoveLimits(bars.Instrument.MasterInstrument, close, brickSize);}else{var barHigh = bars.GetHigh(bars.Count - 1);var barLow = bars.GetLow(bars.Count - 1);UpdateBar(bars, (close > barHigh ? close : barHigh), (close < barLow ? close : barLow), close, time, volume);}}CheckBarComplete(bars.Instrument.MasterInstrument, close, brickSize);bars.LastPrice = close;}public override void ApplyDefaultBasePeriodValue(BarsPeriod period){}public override void ApplyDefaultValue(BarsPeriod period){period.BarsPeriodTypeName = "BetterRenko";period.Value = 2;}public override string ChartLabel(DateTime dateTime){return dateTime.ToString("T", Core.Globals.GeneralOptions.CurrentCulture);}public override double GetPercentComplete(Bars bars, DateTime now){return 1.0d; //replace with your bar percent logic}private void MoveLimits(MasterInstrument masterInstrument, double price, double brickSize){if (masterInstrument.Compare(price, renkoHigh) >= 0){do{renkoHigh += brickSize;renkoLow = renkoHigh - 3.0 * brickSize;} while (masterInstrument.Compare(price, renkoHigh) > 0); // stops if price in range, including edge}else{do{renkoLow -= brickSize;renkoHigh = renkoLow + 3.0 * brickSize;} while (masterInstrument.Compare(price, renkoLow) < 0);}}private void CheckBarComplete(MasterInstrument masterInstrument, double price, double brickSize){int cmpHi = masterInstrument.Compare(price, renkoHigh);int cmpLo = masterInstrument.Compare(price, renkoLow);if (cmpHi == 0 || cmpLo == 0){barRenkoState = RenkoState.BarComplete;MoveLimits(masterInstrument, price, brickSize); // will move limits once since equal}else barRenkoState = RenkoState.BarAccumulating;}private bool RangeExceeded(MasterInstrument masterInstrument, double price){int cmpHi = masterInstrument.Compare(price, renkoHigh);int cmpLo = masterInstrument.Compare(price, renkoLow);return (cmpHi > 0 || cmpLo < 0);}}}09/23/2019 at 3:09 PM #10827509/23/2019 at 3:57 PM #10828302/24/2022 at 7:36 PM #188792VicariOus, quick one for you…In Ninja trader…are you able to trade from alerts?
…I create the signal, attach an alert which triggers a market order.done.
But proreal is fairly slow to hit the market and I get alot of slippage.
Can you trade off alerts when using Ninja Trader? I dont think so but maybe you know otherwise?
02/27/2022 at 11:06 AM #188948You cannot call the native Renko chart in an Automated Trading System. I tried my best to convert a code found on TradingView, which you can embed in a Strategy. Here is the link https://www.prorealcode.com/topic/renk-prt-renko-prc/
1 user thanked author for this post.
02/28/2022 at 9:17 AM #188978Same exact renko bricks as the one from the platform, but on a regular chart, that you can CALL to create automated strategies: https://market.prorealcode.com/product/prt-renko/
03/03/2022 at 9:36 AM #189227£100 is not too bad a price to pay if it works….Im sure it can paint the chart like a renko chart but can it be used to trade..I mean…I think proreal sends auto trading orders only at the close of a bar…I want to send the order as soon as a brick changes colour (for example)…immediately. not at the next close price.. I want to use it to buy or sell at the change of brick colour …like attaching a market order to an alert. Is this possible with the indicator you mentioned? Thank you v much .alex
-
AuthorPosts
Find exclusive trading pro-tools on