Jump to content

⤴️-Paid Ad- Check advertising disclaimer here. Add your banner here.🔥

Recommended Posts

Posted

#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);
        }
    }
}

Posted
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.

 

Posted (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 by Ninja_On_The_Roof
Posted

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);
            }
        }
    }
}

 

AutoFibIndicator Screen Shot.JPG

Posted (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);
            }
        }
    }
}

 

AutoFibIndicator Screen Shot.JPG

@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.

WeK5659Ur.png

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 by Ninja_On_The_Roof
Posted

 

@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

  1. Open a 1-11 NQ chart (e.g., NQ 06-25)
  2. Right-click chart → Strategies → Select AutoFibScalpingStrategy
  3. Set your parameters:
    • Lookback: 20 (default)
    • Quantity: 1 contract
    • Profit Target USD: 33 
    • Stop Loss USD:  99
    • SniperBar-1/11
  4. 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

  1. Every bar close, Fib levels are recalculated from the rolling lookback window
  2. When price crosses above the 61.8% level → Long entry with PT/SL
  3. When price crosses below the 61.8% level → Short entry with PT/SL
  4. Opposing signals automatically exit the current position before reversingAutoFibScalpingStrategy.cs
  5. Profit target and stop loss orders are managed automatically by NinjaTrader's OCO system

Auto Fib 33-99.webp

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 account

Sign in

Already have an account? Sign in here.

Sign In Now


⤴️-Paid Ad- Check advertising disclaimer here. Add your banner here.🔥

×
×
  • Create New...