Chidiroglou Posted 13 hours ago Report Posted 13 hours ago #region Using declarations using System; using System.Windows.Media; using NinjaTrader.NinjaScript; using NinjaTrader.NinjaScript.Indicators; using NinjaTrader.NinjaScript.DrawingTools; using NinjaTrader.Data; using NinjaTrader.Cbi; #endregion namespace NinjaTrader.NinjaScript.Indicators { public class AutoFibIndicator : Indicator { private int lookback = 20; private double swingHigh; private double swingLow; private MAX maxIndicator; private MIN minIndicator; // Farben frei wählbar [NinjaScriptProperty] public Brush Fib382Color { get; set; } [NinjaScriptProperty] public Brush Fib50Color { get; set; } [NinjaScriptProperty] public Brush Fib618Color { get; set; } [NinjaScriptProperty] public Brush LongColor { get; set; } [NinjaScriptProperty] public Brush ShortColor { get; set; } protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "AutoFibIndicator"; Calculate = Calculate.OnBarClose; IsOverlay = true; IsSuspendedWhileInactive = true; Fib382Color = Brushes.DodgerBlue; Fib50Color = Brushes.Gray; Fib618Color = Brushes.Gold; LongColor = Brushes.Lime; ShortColor = Brushes.Red; } else if (State == State.Configure) { // Hier können Konfigurationen vorgenommen werden } else if (State == State.DataLoaded) { // MAX und MIN Indikatoren initialisieren maxIndicator = MAX(High, lookback); minIndicator = MIN(Low, lookback); } } protected override void OnBarUpdate() { if (CurrentBar < lookback) return; if (maxIndicator == null || minIndicator == null) return; // Aktuelle Swing High und Low abrufen swingHigh = maxIndicator[0]; swingLow = minIndicator[0]; double range = swingHigh - swingLow; double fib382 = swingHigh - range * 0.382; double fib50 = swingHigh - range * 0.5; double fib618 = swingHigh - range * 0.618; int startBar = CurrentBar - lookback; // Bestehende Linien löschen, um Überlappungen zu vermeiden string fib382Tag = "Fib382"; string fib50Tag = "Fib50"; string fib618Tag = "Fib618"; RemoveDrawObject(fib382Tag); RemoveDrawObject(fib50Tag); RemoveDrawObject(fib618Tag); // === FIB LINIEN === Draw.Line(this, fib382Tag, false, startBar, fib382, CurrentBar, fib382, Fib382Color, DashStyleHelper.Solid, 2); Draw.Line(this, fib50Tag, false, startBar, fib50, CurrentBar, fib50, Fib50Color, DashStyleHelper.Dash, 2); Draw.Line(this, fib618Tag, false, startBar, fib618, CurrentBar, fib618, Fib618Color, DashStyleHelper.Solid, 3); // === SIGNAL LOGIK === string longTag = "Long" + CurrentBar; string shortTag = "Short" + CurrentBar; // LONG (Bounce über 61.8) if (Close[0] > fib618 && Close[1] <= fib618) { Draw.ArrowUp(this, longTag, false, 0, Low[0] - (2 * TickSize), LongColor); } // SHORT (Reject unter 61.8) if (Close[0] < fib618 && Close[1] >= fib618) { Draw.ArrowDown(this, shortTag, false, 0, High[0] + (2 * TickSize), ShortColor); } } protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { // Optional: Hier kann zusätzliches Rendering durchgeführt werden base.OnRender(chartControl, chartScale); } } }
Ninja_On_The_Roof Posted 12 hours ago Report Posted 12 hours ago 1 minute ago, Chidiroglou said: #region Using declarations using System; using System.Windows.Media; using NinjaTrader.NinjaScript; using NinjaTrader.NinjaScript.Indicators; using NinjaTrader.NinjaScript.DrawingTools; using NinjaTrader.Data; using NinjaTrader.Cbi; #endregion namespace NinjaTrader.NinjaScript.Indicators { public class AutoFibIndicator : Indicator { private int lookback = 20; private double swingHigh; private double swingLow; private MAX maxIndicator; private MIN minIndicator; // Farben frei wählbar [NinjaScriptProperty] public Brush Fib382Color { get; set; } [NinjaScriptProperty] public Brush Fib50Color { get; set; } [NinjaScriptProperty] public Brush Fib618Color { get; set; } [NinjaScriptProperty] public Brush LongColor { get; set; } [NinjaScriptProperty] public Brush ShortColor { get; set; } protected override void OnStateChange() { if (State == State.SetDefaults) { Name = "AutoFibIndicator"; Calculate = Calculate.OnBarClose; IsOverlay = true; IsSuspendedWhileInactive = true; Fib382Color = Brushes.DodgerBlue; Fib50Color = Brushes.Gray; Fib618Color = Brushes.Gold; LongColor = Brushes.Lime; ShortColor = Brushes.Red; } else if (State == State.Configure) { // Hier können Konfigurationen vorgenommen werden } else if (State == State.DataLoaded) { // MAX und MIN Indikatoren initialisieren maxIndicator = MAX(High, lookback); minIndicator = MIN(Low, lookback); } } protected override void OnBarUpdate() { if (CurrentBar < lookback) return; if (maxIndicator == null || minIndicator == null) return; // Aktuelle Swing High und Low abrufen swingHigh = maxIndicator[0]; swingLow = minIndicator[0]; double range = swingHigh - swingLow; double fib382 = swingHigh - range * 0.382; double fib50 = swingHigh - range * 0.5; double fib618 = swingHigh - range * 0.618; int startBar = CurrentBar - lookback; // Bestehende Linien löschen, um Überlappungen zu vermeiden string fib382Tag = "Fib382"; string fib50Tag = "Fib50"; string fib618Tag = "Fib618"; RemoveDrawObject(fib382Tag); RemoveDrawObject(fib50Tag); RemoveDrawObject(fib618Tag); // === FIB LINIEN === Draw.Line(this, fib382Tag, false, startBar, fib382, CurrentBar, fib382, Fib382Color, DashStyleHelper.Solid, 2); Draw.Line(this, fib50Tag, false, startBar, fib50, CurrentBar, fib50, Fib50Color, DashStyleHelper.Dash, 2); Draw.Line(this, fib618Tag, false, startBar, fib618, CurrentBar, fib618, Fib618Color, DashStyleHelper.Solid, 3); // === SIGNAL LOGIK === string longTag = "Long" + CurrentBar; string shortTag = "Short" + CurrentBar; // LONG (Bounce über 61.8) if (Close[0] > fib618 && Close[1] <= fib618) { Draw.ArrowUp(this, longTag, false, 0, Low[0] - (2 * TickSize), LongColor); } // SHORT (Reject unter 61.8) if (Close[0] < fib618 && Close[1] >= fib618) { Draw.ArrowDown(this, shortTag, false, 0, High[0] + (2 * TickSize), ShortColor); } } protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { // Optional: Hier kann zusätzliches Rendering durchgeführt werden base.OnRender(chartControl, chartScale); } } } I recall, DTB has autofib indicator in its package. TDU also has autofib. Just another idea, maybe useful to you.
Chidiroglou Posted 12 hours ago Author Report Posted 12 hours ago I know what you mean; this code should include entry signals, targets and stop-loss levels
Ninja_On_The_Roof Posted 12 hours ago Report Posted 12 hours ago (edited) 5 minutes ago, Chidiroglou said: I know what you mean; this code should include entry signals, targets and stop-loss levels Then the ARC-Neurostreet has this auto fib with entry and exit.😇And stoploss, I should add. Edited 12 hours ago by Ninja_On_The_Roof
swiattrader Posted 11 hours ago Report Posted 11 hours ago Find below the Revised AutoFibIndicator Script. Attached is a screen shot showing the compiled script (NT8 version: 8.1.6.3 64-bit). Enjoy! #region Using declarations using 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.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.DrawingTools; #endregion namespace NinjaTrader.NinjaScript.Indicators { public class AutoFibIndicator : Indicator { private MAX maxIndicator; private MIN minIndicator; [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="Lookback", Order=1, GroupName="Parameters")] public int Lookback { get; set; } #region Color Properties [XmlIgnore] [Display(Name="Fib 38.2 Color", Order=2, GroupName="Colors")] public Brush Fib382Color { get; set; } [Browsable(false)] public string Fib382ColorSerializable { get { return Serialize.BrushToString(Fib382Color); } set { Fib382Color = Serialize.StringToBrush(value); } } [XmlIgnore] [Display(Name="Fib 50.0 Color", Order=3, GroupName="Colors")] public Brush Fib50Color { get; set; } [Browsable(false)] public string Fib50ColorSerializable { get { return Serialize.BrushToString(Fib50Color); } set { Fib50Color = Serialize.StringToBrush(value); } } [XmlIgnore] [Display(Name="Fib 61.8 Color", Order=4, GroupName="Colors")] public Brush Fib618Color { get; set; } [Browsable(false)] public string Fib618ColorSerializable { get { return Serialize.BrushToString(Fib618Color); } set { Fib618Color = Serialize.StringToBrush(value); } } [XmlIgnore] [Display(Name="Long Signal Color", Order=5, GroupName="Colors")] public Brush LongColor { get; set; } [Browsable(false)] public string LongColorSerializable { get { return Serialize.BrushToString(LongColor); } set { LongColor = Serialize.StringToBrush(value); } } [XmlIgnore] [Display(Name="Short Signal Color", Order=6, GroupName="Colors")] public Brush ShortColor { get; set; } [Browsable(false)] public string ShortColorSerializable { get { return Serialize.BrushToString(ShortColor); } set { ShortColor = Serialize.StringToBrush(value); } } #endregion protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Automatically plots Fibonacci levels based on a lookback period."; Name = "AutoFibIndicator"; Calculate = Calculate.OnBarClose; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = true; IsSuspendedWhileInactive = true; Lookback = 20; Fib382Color = Brushes.DodgerBlue; Fib50Color = Brushes.Gray; Fib618Color = Brushes.Gold; LongColor = Brushes.Lime; ShortColor = Brushes.Red; } else if (State == State.DataLoaded) { maxIndicator = MAX(High, Lookback); minIndicator = MIN(Low, Lookback); } } protected override void OnBarUpdate() { if (CurrentBar < Lookback) return; double swingHigh = maxIndicator[0]; double swingLow = minIndicator[0]; double range = swingHigh - swingLow; if (range <= 0) return; double fib382 = swingHigh - (range * 0.382); double fib50 = swingHigh - (range * 0.5); double fib618 = swingHigh - (range * 0.618); // Using static tags for lines ensures they "move" with the lookback rather than creating new ones Draw.Line(this, "Fib382", false, Lookback, fib382, 0, fib382, Fib382Color, DashStyleHelper.Solid, 2); Draw.Line(this, "Fib50", false, Lookback, fib50, 0, fib50, Fib50Color, DashStyleHelper.Dash, 2); Draw.Line(this, "Fib618", false, Lookback, fib618, 0, fib618, Fib618Color, DashStyleHelper.Solid, 3); // Signal Logic // Long: Close crosses above 61.8% if (CrossAbove(Close, fib618, 1)) { Draw.ArrowUp(this, "Long" + CurrentBar, true, 0, Low[0] - (5 * TickSize), LongColor); } // Short: Close crosses below 61.8% if (CrossBelow(Close, fib618, 1)) { Draw.ArrowDown(this, "Short" + CurrentBar, true, 0, High[0] + (5 * TickSize), ShortColor); } } } } misalto and Ninja_On_The_Roof 2
Chidiroglou Posted 9 hours ago Author Report Posted 9 hours ago swiattrader Thanks a lot, I'll give it a go
Ninja_On_The_Roof Posted 1 hour ago Report Posted 1 hour ago (edited) 9 hours ago, swiattrader said: Find below the Revised AutoFibIndicator Script. Attached is a screen shot showing the compiled script (NT8 version: 8.1.6.3 64-bit). Enjoy! #region Using declarations using 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.Data; using NinjaTrader.NinjaScript; using NinjaTrader.Core.FloatingPoint; using NinjaTrader.NinjaScript.DrawingTools; #endregion namespace NinjaTrader.NinjaScript.Indicators { public class AutoFibIndicator : Indicator { private MAX maxIndicator; private MIN minIndicator; [NinjaScriptProperty] [Range(1, int.MaxValue)] [Display(Name="Lookback", Order=1, GroupName="Parameters")] public int Lookback { get; set; } #region Color Properties [XmlIgnore] [Display(Name="Fib 38.2 Color", Order=2, GroupName="Colors")] public Brush Fib382Color { get; set; } [Browsable(false)] public string Fib382ColorSerializable { get { return Serialize.BrushToString(Fib382Color); } set { Fib382Color = Serialize.StringToBrush(value); } } [XmlIgnore] [Display(Name="Fib 50.0 Color", Order=3, GroupName="Colors")] public Brush Fib50Color { get; set; } [Browsable(false)] public string Fib50ColorSerializable { get { return Serialize.BrushToString(Fib50Color); } set { Fib50Color = Serialize.StringToBrush(value); } } [XmlIgnore] [Display(Name="Fib 61.8 Color", Order=4, GroupName="Colors")] public Brush Fib618Color { get; set; } [Browsable(false)] public string Fib618ColorSerializable { get { return Serialize.BrushToString(Fib618Color); } set { Fib618Color = Serialize.StringToBrush(value); } } [XmlIgnore] [Display(Name="Long Signal Color", Order=5, GroupName="Colors")] public Brush LongColor { get; set; } [Browsable(false)] public string LongColorSerializable { get { return Serialize.BrushToString(LongColor); } set { LongColor = Serialize.StringToBrush(value); } } [XmlIgnore] [Display(Name="Short Signal Color", Order=6, GroupName="Colors")] public Brush ShortColor { get; set; } [Browsable(false)] public string ShortColorSerializable { get { return Serialize.BrushToString(ShortColor); } set { ShortColor = Serialize.StringToBrush(value); } } #endregion protected override void OnStateChange() { if (State == State.SetDefaults) { Description = @"Automatically plots Fibonacci levels based on a lookback period."; Name = "AutoFibIndicator"; Calculate = Calculate.OnBarClose; IsOverlay = true; DisplayInDataBox = true; DrawOnPricePanel = true; IsSuspendedWhileInactive = true; Lookback = 20; Fib382Color = Brushes.DodgerBlue; Fib50Color = Brushes.Gray; Fib618Color = Brushes.Gold; LongColor = Brushes.Lime; ShortColor = Brushes.Red; } else if (State == State.DataLoaded) { maxIndicator = MAX(High, Lookback); minIndicator = MIN(Low, Lookback); } } protected override void OnBarUpdate() { if (CurrentBar < Lookback) return; double swingHigh = maxIndicator[0]; double swingLow = minIndicator[0]; double range = swingHigh - swingLow; if (range <= 0) return; double fib382 = swingHigh - (range * 0.382); double fib50 = swingHigh - (range * 0.5); double fib618 = swingHigh - (range * 0.618); // Using static tags for lines ensures they "move" with the lookback rather than creating new ones Draw.Line(this, "Fib382", false, Lookback, fib382, 0, fib382, Fib382Color, DashStyleHelper.Solid, 2); Draw.Line(this, "Fib50", false, Lookback, fib50, 0, fib50, Fib50Color, DashStyleHelper.Dash, 2); Draw.Line(this, "Fib618", false, Lookback, fib618, 0, fib618, Fib618Color, DashStyleHelper.Solid, 3); // Signal Logic // Long: Close crosses above 61.8% if (CrossAbove(Close, fib618, 1)) { Draw.ArrowUp(this, "Long" + CurrentBar, true, 0, Low[0] - (5 * TickSize), LongColor); } // Short: Close crosses below 61.8% if (CrossBelow(Close, fib618, 1)) { Draw.ArrowDown(this, "Short" + CurrentBar, true, 0, High[0] + (5 * TickSize), ShortColor); } } } } @swiattrader, you beat me to it. 🤣 But here is the AutoFib from ARC-Neurostreet, just for comparison between the two. The ARC also comes with the automated strategy as a bot. You can certainly adjust the internal settings for stoplosses and targets to suite your own trading style. I only added the ARC-UniZone, as I always think it is a good thing, if not critical, knowing where your S/R/Supply/Demand zones are, so you don't trade all buck naked.🤪 The main concept here is when price hits the blue Fib, you should initiate a long position and vice versa, when price hits the red Fib, you should initiate a short position. P.S: I do like the ARC stuff. They are good. However, noted that their stuff is heavy and they tend to eat up a whole lot of your PC's energy, thus, it sometimes takes a bit of time to load up. Edited 1 hour ago by Ninja_On_The_Roof
KJs Posted 14 minutes ago Report Posted 14 minutes ago @swiattrader Here is fully Autotrading, AutoFibScalpingStrategy -fully converted NinjaTrader 8 Strategy based on your AutoFibIndicator logic. It trades NQ on 1-11 sniper bars, enters long/short on the 61.8% Fibonacci cross signals, and uses USD-based profit target and stop loss. How to Run Live / Sim Open a 1-11 NQ chart (e.g., NQ 06-25) Right-click chart → Strategies → Select AutoFibScalpingStrategy Set your parameters: Lookback: 20 (default) Quantity: 1 contract Profit Target USD: 33 Stop Loss USD: 99 SniperBar-1/11 Click OK → The strategy will go live and begin trading on signal bars @kimsam @Ninja_On_The_Roof A humble try, requesting improvising, if required🙏 Trade Flow Every bar close, Fib levels are recalculated from the rolling lookback window When price crosses above the 61.8% level → Long entry with PT/SL When price crosses below the 61.8% level → Short entry with PT/SL Opposing signals automatically exit the current position before reversingAutoFibScalpingStrategy.cs Profit target and stop loss orders are managed automatically by NinjaTrader's OCO system
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now