Thanks, Roy
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
Fibonacci Fan Code
Collapse
X
-
Fibonacci Fan Code
I don't know why NT doesn't have a Fibonacci Fan tool, but it should. Until it does, I would like to try and create my own one. The easiest way to do this would be to take the existing code for the Fib Extension Tool and just modify it. Is there any way to access this code?
Thanks, RoyTags: None
-
Thanks for your response. According to this thread, its been under consideration for quite a while:
I'm not sure I really want to wait another three years
I could pretty much code it myself as an indicator, except for handling the part that selects the two anchor points. Is there any generic code you could provide that I could use for this purpose, and I will do the rest? Thanks!
Comment
-
I could unfortunately not point you to a supported / documented framework for achieving that, but you can check into for example this custom data box study published on http://www.volumedigger.com/NinjaTra...dsDataBox.aspx
This would give you access to the code needed for mouse selecting the bar.
Also, if I'm not mistaken a partner company offers a Fib Fan indicator as custom addon (http://www.syete.com/)BertrandNinjaTrader Customer Service
Comment
-
I finally had a chance to return to this. The code from volume digger works nicely and allows me to choose an anchor bar by mouseclick, but there is one thing I can't figure out. How do I prevent the OnBarUpdate method from beginning to process all the data until I can first click on an anchor bar? Somehow I need to "pause" OnBarUpdate until there is a proper value for the anchor bar.Last edited by Srgtroy; 01-20-2013, 04:06 AM.
Comment
-
I think here you can look into simply returning out of the OnBarUpdate() until the desired value is found / located. OnBarUpdate() would still receive a call, but would not calculate anything as you put control back to the start until the value is there.
if (myAnchor != desiredValue) return;BertrandNinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_Bertrand View PostI think here you can look into simply returning out of the OnBarUpdate() until the desired value is found / located. OnBarUpdate() would still receive a call, but would not calculate anything as you put control back to the start until the value is there.
if (myAnchor != desiredValue) return;
Rather,
I think I need to say something like:
if (CurrentBar == 0)
{
if (myAnchor == null)
{
Some code here that will make it wait for anchor click
}
}
Comment
-
Originally posted by Srgtroy View PostThe problem with this solution is that each bar will still be processed (even though no code will) before I ever have a chance of choosing the anchor bar with a mouseclick. By the time, I do that, all the bars will already be processed and essentially nothing will be drawn/happen.
Rather,
I think I need to say something like:
if (CurrentBar == 0)
{
if (myAnchor == null)
{
Some code here that will make it wait for anchor click
}
}
Event-driven programs run in a loop, trapping events and producing output. There is nothing to pause while you click: you instead write an event handler for your click event. The messaging loop will get the event and send it to the scheduler, which will produce a return, which you handle.
Comment
-
Originally posted by koganam View PostI am not really understanding your issue, but it seems to me that maybe there is a lack of understanding about event-driven programming. You need to focus on the event that you want to generate/capture and how you want to handle it.
Event-driven programs run in a loop, trapping events and producing output. There is nothing to pause while you click: you instead write an event handler for your click event. The messaging loop will get the event and send it to the scheduler, which will produce a return, which you handle.
Code:#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; using System.Windows.Forms; #endregion namespace NinjaTrader.Indicator { [Description("Identifies Bar Number")] public class BarNum : Indicator { #region Variables ToolStripLabel tsLabel = null; ToolStripSeparator tsSeparator = null; #endregion protected override void Initialize() { CalculateOnBarClose = true; Overlay = true; } protected override void OnStartUp() { //add the mouse events this.ChartControl.ChartPanel.MouseClick += new MouseEventHandler(myMouseEvents); //add the controls if (ChartControl != null) { ToolStrip toolstrip = (ToolStrip)ChartControl.Controls["tsrTool"]; if (toolstrip !=null) { //add separator tsSeparator = new ToolStripSeparator(); tsSeparator.Name = "tsSeparator"; toolstrip.Items.Add(tsSeparator); //add label tsLabel = new ToolStripLabel(); tsLabel.Name = "tsLabel"; tsLabel.Text = "www.volumedigger.com"; toolstrip.Items.Add(tsLabel); } } } protected override void OnBarUpdate() { } private void myMouseEvents(object sender, MouseEventArgs e) { try { TriggerCustomEvent(new CustomEvent(myCustomEvent),e ); } catch (Exception ex) { Print("Error " + ex.Message); } } private void myCustomEvent(object state) { try { MouseEventArgs m = (MouseEventArgs)state; int xpos = m.X; if (xpos >= ChartControl.CanvasRight) return; //make sure clicked on chart area int barclick = (int)(xpos/ChartControl.BarSpace); //gets the bar, from the painted ones where the mouse is clicked int idx = ChartControl.BarsPainted - barclick ; idx = Bars.Count - 2 - ChartControl.LastBarPainted + idx; if (idx > Bars.Count - 2) return; //firstbar if (idx < -1) return; //last bar int bn = Bars.Count - 2 - idx; tsLabel.Text = "BarNumber:" + bn.ToString(); //DrawText("text", idx.ToString() + " " + Bars.Count.ToString(),idx,Low[idx] - TickSize * 2,Color.Blue); } catch (Exception ex) { Print("Error " + ex.Message); } } protected override void OnTermination() { if (this.ChartControl != null) { //remove the mouse click event this.ChartControl.ChartPanel.MouseMove -=myMouseEvents; //remove the controls ToolStrip toolstrip = (ToolStrip)ChartControl.Controls["tsrTool"]; if (toolstrip != null) { if (tsSeparator != null) toolstrip.Items.Remove(tsSeparator); if (tsLabel != null) toolstrip.Items.Remove(tsLabel); } } } #region Properties #endregion } } #region NinjaScript generated code. Neither change nor remove. #endregion
1. In Variables Region, made bn variable global.
2. Added code in OnBarUpdate method to draw dot.
3. In EventHandling code, removed int declaration from bn variable.
I suspect the problem is that the handling code isn't meant to return the value globally but I'm not sure. Anyway, this is what the code now looks like with changes in red:
Code:#region Using declarations using System; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Drawing.Drawing2D; using System.Xml.Serialization; using NinjaTrader.Cbi; using NinjaTrader.Data; using NinjaTrader.Gui.Chart; using System.Windows.Forms; #endregion namespace NinjaTrader.Indicator { [Description("Identifies Bar Number")] public class BarNum : Indicator { #region Variables [COLOR="Sienna"]private int bn;[/COLOR] ToolStripLabel tsLabel = null; ToolStripSeparator tsSeparator = null; #endregion protected override void Initialize() { CalculateOnBarClose = true; Overlay = true; } protected override void OnStartUp() { //add the mouse events this.ChartControl.ChartPanel.MouseClick += new MouseEventHandler(myMouseEvents); //add the controls if (ChartControl != null) { ToolStrip toolstrip = (ToolStrip)ChartControl.Controls["tsrTool"]; if (toolstrip !=null) { //add separator tsSeparator = new ToolStripSeparator(); tsSeparator.Name = "tsSeparator"; toolstrip.Items.Add(tsSeparator); //add label tsLabel = new ToolStripLabel(); tsLabel.Name = "tsLabel"; tsLabel.Text = "www.volumedigger.com"; toolstrip.Items.Add(tsLabel); } } } protected override void OnBarUpdate() { [COLOR="DarkRed"]if (CurrentBar == bn) { DrawDot("z" + CurrentBar, true, 0, Close[0], Color.Red); } }[/COLOR] private void myMouseEvents(object sender, MouseEventArgs e) { try { TriggerCustomEvent(new CustomEvent(myCustomEvent),e ); } catch (Exception ex) { Print("Error " + ex.Message); } } private void myCustomEvent(object state) { try { MouseEventArgs m = (MouseEventArgs)state; int xpos = m.X; if (xpos >= ChartControl.CanvasRight) return; //make sure clicked on chart area int barclick = (int)(xpos/ChartControl.BarSpace); //gets the bar, from the painted ones where the mouse is clicked int idx = ChartControl.BarsPainted - barclick ; idx = Bars.Count - 2 - ChartControl.LastBarPainted + idx; if (idx > Bars.Count - 2) return; //firstbar if (idx < -1) return; //last bar [COLOR="DarkRed"]bn = Bars.Count - 2 - idx;[/COLOR] tsLabel.Text = "BarNumber:" + bn.ToString(); //DrawText("text", idx.ToString() + " " + Bars.Count.ToString(),idx,Low[idx] - TickSize * 2,Color.Blue); } catch (Exception ex) { Print("Error " + ex.Message); } } protected override void OnTermination() { if (this.ChartControl != null) { //remove the mouse click event this.ChartControl.ChartPanel.MouseMove -=myMouseEvents; //remove the controls ToolStrip toolstrip = (ToolStrip)ChartControl.Controls["tsrTool"]; if (toolstrip != null) { if (tsSeparator != null) toolstrip.Items.Remove(tsSeparator); if (tsLabel != null) toolstrip.Items.Remove(tsLabel); } } } #region Properties #endregion } } #region NinjaScript generated code. Neither change nor remove. #endregion
Last edited by Srgtroy; 01-26-2013, 05:01 PM.
Comment
-
Another possible starting point
I used a program I found in the Ninja 7 user indicators in the forums called dDrawABC.
It has way more than you want, but it might be a good starting point for you. You would strip out most of the code and insert your drawing of lines within the Event Handler. He also has a lot of other routines which I did not need, that are related to his desired outcome for drawing lines. I am probably just ahead of you in the learning dept, but I am willing to Help. Kogonam is great and talented and always ready to help. He really understand this stuff, relative to C# and Ninja script capabilities. Also, I have Visual Studio and I use the debugging capabilities it has to let me step through code and watch variables to see what really happens, vs what I thought I coded. PM me your Skype ID if you have one and would like to chat. I am in US EST.
John
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by pmachiraju, 11-01-2023, 04:46 AM
|
8 responses
147 views
0 likes
|
Last Post
by rehmans
Today, 06:44 PM
|
||
Started by mattbsea, Today, 05:44 PM
|
0 responses
5 views
0 likes
|
Last Post
by mattbsea
Today, 05:44 PM
|
||
Started by RideMe, 04-07-2024, 04:54 PM
|
6 responses
33 views
0 likes
|
Last Post
by RideMe
Today, 05:31 PM
|
||
Started by tkaboris, Today, 05:13 PM
|
0 responses
4 views
0 likes
|
Last Post
by tkaboris
Today, 05:13 PM
|
||
Started by GussJ, 03-04-2020, 03:11 PM
|
16 responses
3,282 views
0 likes
|
Last Post
by Leafcutter
Today, 04:14 PM
|
Comment