Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 01, 2015, 05:08:00 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Fractal Trading Indicator  (Read 5288 times)

Niceperson

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 5
    • View Profile
    • Donate to Member
Fractal Trading Indicator
« on: October 31, 2011, 11:53:56 AM »
I have a "fractal indicator script" which provides Buy or Sell signals on Ninja Trader Platform. It shows visual arrows but does not give any audio alert. I want audio alerts when the visual arrows appear on the screen.

I have attached the script written in C#. I am not a programmer. I will much appreciate if some one can help.

Thanks

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 12,787
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #1 on: October 31, 2011, 12:08:16 PM »
Hi. I have 500 lines of source code. Please sort through it and give me an answer...

Seriously...

If you want an answer, lay out the problem and give some background.

If you had have laid out the problem neatly, I could probably give you an answer very quickly. However, I really don't want to sort through a bunch of code to give you what should be 10 lines of code or less for an answer.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 12,787
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #2 on: October 31, 2011, 12:14:36 PM »
Sigh... Skimmed through it. I didn't see where any alerts are. (Skimmed quickly, so a closer look might help.)

If you can identify WHERE the notifications happen, it's simple to add an audio alert.

It might be that there is no way to do it in the code you've supplied. Check the program docs to see about customization possibilities.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

40hz

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 11,529
    • View Profile
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #3 on: October 31, 2011, 12:57:37 PM »
@niceperson - First up, welcome to Donation Coder. Glad you could join us. I think you're gonna like it here! :Thmbsup:

Regarding putting an alert in Ninja Trader:

Wouldn't it be easier to just submit a feature request directly to NinjaTrader LLC? It's their program. There's a good chance the feature you want may already be available. I took a quick browse of their user forums. They seem to be responsive to user requests.  :)

Niceperson

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #4 on: October 31, 2011, 01:35:58 PM »
My apologies. I had no intention of making you to read through so many codes of line.

Here are some details as I could assemble in few minutes.
The indicator script is designed to run on Ninja Trader ver 7. (www.ninjatrader.com). Once this script is run, it provides visual signals to buy or sell in market. Please see attached screen shot #01. You will find big red and green triangles there. I wanted to have audio alerts also along with these visual signs. So I added few lines of code reading from the help file of the software. These are shown on attached Screen shot #2 in green. They are showing in green because these did not work as required and they were commented out by me. When these lines were added, the audio alert happened on each tick and not when the visual triangle appeared on the screen. Please also note that there is a companion sub code file associated with this which is included in the zip file (also attached).IT contains all of code lines.

I am willing to show you live working on shared live screen sharing. I am in Toronto, Canada.

Thanks 

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 12,787
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #5 on: October 31, 2011, 11:50:57 PM »
The second screenshot there has the sound code in it. Can you attach it here and post a link to the relevant documentation?

It looks like it may already have the necessary functionality in it, and that only needs to be enabled.

You can also try using this in the spot where you want to play the sound.

Code: C#
  1. System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
  2. myPlayer.SoundLocation = @"c:\some-sound-file.wav";
  3. myPlayer.Play();
  4.  

However, make certain to replace "c:\some-sound-file.wav" with the proper path to the WAV file that you want to play. It MUST be a WAV file though. You cannot use MP3s or anything else.
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

Niceperson

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #6 on: November 01, 2011, 09:10:26 PM »
Thanks for your quick reply.

I added the code lines. These are highlighted on the attached screenshot.

No sound.

The sound file used by me is good file because I can hear it when clicked directly.

Any help will be much appreciated.


Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 12,787
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #7 on: November 01, 2011, 09:53:58 PM »
Try copying the wave file to another location under "My Documents" then try that. (In case there's a permissions problem.)

Next, if that doesn't work, remove the code I had there before and insert this:

Code: C#
  1. PlaySound(@"C:\mySound.wav");
  2.  

From: http://www.ninjatrad...x.html?playsound.htm

Fix the path there as well.

If you post the code itself rather than a screenshot, that makes it easier. (e.g. I'd like to see what's in the "using" directives.)
Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

Niceperson

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #8 on: November 01, 2011, 10:34:06 PM »
The code is pasted below with the ' Using ' directives'. I have highlighted in RED the Play sound line code for easy reading.

The sound comes on each tick not on alert triangle. It is required only when the alert conditions are met.


-----------------------------------------------------------------------------------------------------------


Code: C#
  1. #region Using declarations
  2. using System;
  3. using System.Diagnostics;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.ComponentModel;
  7. using System.Xml.Serialization;
  8. using NinjaTrader.Cbi;
  9. using NinjaTrader.Data;
  10. using NinjaTrader.Gui.Chart;
  11. #endregion
  12.  
  13. namespace NinjaTrader.Indicator
  14. {
  15.     [Description("")]
  16.     [Gui.Design.DisplayName("FractalPivot (TradeStation)")]
  17.     public class FractalPivot_TradeStation : Indicator
  18.     {
  19.         #region Variables
  20.                 private int pLeftStrength = 2;
  21.                 private int pRightStrength = 2;
  22.                 private int pTickSeparation = 3;
  23.         #endregion
  24.                
  25.                
  26.  
  27.         protected override void Initialize()
  28.         {
  29.                         Add(new Plot(new Pen(Color.Red,12), PlotStyle.TriangleDown, "Highs"));                                 
  30.                         Add(new Plot(new Pen(Color.Blue,12), PlotStyle.TriangleUp, "Lows"));            
  31.                        
  32.                         CalculateOnBarClose     = false;
  33.             Overlay                             = true;
  34.             PriceTypeSupported  = false;
  35.         }
  36.  
  37.         protected override void OnBarUpdate()
  38.         {
  39.                         if(CurrentBar < Math.Max((pLeftStrength+pRightStrength)*3,15))
  40.                                 return;
  41.  
  42.                         if(pType == FractalPivot_TradeStation_Type.Both || pType == FractalPivot_TradeStation_Type.Highs) {
  43.                                 int bar = (int)Pivot_EasyLanguage(1, 1, pLeftStrength, pRightStrength+1, pRightStrength).PivotBarRelative[0];
  44.                                
  45.                                 if(bar>=0) Values[0].Set(pRightStrength, High[pRightStrength]+TickSize * pTickSeparation);
  46.                                
  47.                                 PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav");
  48.                                
  49.                                
  50.                         }
  51.                         if(pType == FractalPivot_TradeStation_Type.Both || pType == FractalPivot_TradeStation_Type.Lows) {
  52.                                 int bar = (int)Pivot_EasyLanguage(-1, 1, pLeftStrength, pRightStrength+1, pRightStrength).PivotBarRelative[0];
  53.                                
  54.                                 if(bar>=0) Values[1].Set(pRightStrength, Low[pRightStrength]-TickSize * pTickSeparation);
  55.                                
  56.                         }
  57.         }
  58.  
« Last Edit: November 01, 2011, 11:39:54 PM by skwire, Reason: Added code tags »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 4,391
    • View Profile
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #9 on: November 01, 2011, 11:41:18 PM »
@Niceperson: I added code tags around your code snippet for readability.
@Renegade: Line 47 was the red coloured line before I added the code tags.

Renegade

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 12,787
  • Tell me something you don't know...
    • View Profile
    • Renegade Minds
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #10 on: November 01, 2011, 11:54:44 PM »
@Niceperson: I added code tags around your code snippet for readability.
@Renegade: Line 47 was the red coloured line before I added the code tags.

Thanks for that.


For the code, you have sound now, so that's good. It's just in the wrong spot.

Comment out that line by placing "//" at the front of it. That will disable it.

Next, sift through the various methods and see if you can read enough of the names of variables to find an "alert". When you find that, paste in the sound code that you'd commented out before. (Make sure it's not still commented out.)

Test to see if you've put it in the right place. If not, look around again and repeat.

Make sure to search for "alert" in the code as that should be faster & easier than just reading through. Do make sure to skim it though for words that you recognize as possibly being relevant.

Slow Down Music - Where I commit thought crimes...

Freedom is the right to be wrong, not the right to do wrong. - John Diefenbaker

Niceperson

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 5
    • View Profile
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #11 on: November 02, 2011, 04:28:39 PM »
Hello,

You are right that the code has to be placed in the right spot. I searched through the complete code file, but did not find any "alert" line. I have also attached the complete code file, syntax highlighted.

Please note that the code in Line 31 has been commented out because it gives sound on each tick.  Codes from line 106 are auto generated by Ninja system. I have just added them here for completeness.


Thanks


Code: Text
  1.  
  2. #region Using declarations
  3. using System;
  4. using System.Diagnostics;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.ComponentModel;
  8. using System.Xml.Serialization;
  9. using NinjaTrader.Cbi;
  10. using NinjaTrader.Data;
  11. using NinjaTrader.Gui.Chart;
  12. #endregion
  13.  
  14. namespace NinjaTrader.Indicator
  15. {
  16.     [Description("")]
  17.     [Gui.Design.DisplayName("FractalPivot (TradeStation)")]
  18.     public class FractalPivot_TradeStation : Indicator
  19.     {
  20.         #region Variables
  21.                 private int pLeftStrength = 2;
  22.                 private int pRightStrength = 2;
  23.                 private int pTickSeparation = 3;
  24.         #endregion
  25.                
  26.                
  27.  
  28.         protected override void Initialize()
  29.         {
  30.                         Add(new Plot(new Pen(Color.Red,12), PlotStyle.TriangleDown, "Highs"));                                 
  31.                         Add(new Plot(new Pen(Color.Blue,12), PlotStyle.TriangleUp, "Lows"));            
  32.                         //PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav");
  33.                         CalculateOnBarClose     = false;
  34.             Overlay                             = true;
  35.             PriceTypeSupported  = false;
  36.         }
  37.  
  38.         protected override void OnBarUpdate()
  39.         {
  40.                         if(CurrentBar < Math.Max((pLeftStrength+pRightStrength)*3,15))
  41.                                 return;
  42.  
  43.                         if(pType == FractalPivot_TradeStation_Type.Both || pType == FractalPivot_TradeStation_Type.Highs) {
  44.                                 int bar = (int)Pivot_EasyLanguage(1, 1, pLeftStrength, pRightStrength+1, pRightStrength).PivotBarRelative[0];
  45.                                
  46.                                 if(bar>=0) Values[0].Set(pRightStrength, High[pRightStrength]+TickSize * pTickSeparation);
  47.                                
  48.                                
  49.                         }
  50.                         if(pType == FractalPivot_TradeStation_Type.Both || pType == FractalPivot_TradeStation_Type.Lows) {
  51.                                 int bar = (int)Pivot_EasyLanguage(-1, 1, pLeftStrength, pRightStrength+1, pRightStrength).PivotBarRelative[0];
  52.                                
  53.                                 if(bar>=0) Values[1].Set(pRightStrength, Low[pRightStrength]-TickSize * pTickSeparation);
  54.                                
  55.                         }
  56.         }
  57.                
  58.                
  59.                
  60.  
  61.                
  62. //====================================================================
  63.                 #region Properties
  64.  
  65.                 [Description("Ticks separation from bar")]
  66.                 [Category("Visual")]
  67.                 public int TickSeparation
  68.                 {
  69.                         get { return pTickSeparation; }
  70.                         set { pTickSeparation = Math.Max(1,value); }
  71.                 }
  72.  
  73.                 [Description("Left strength")]
  74.                 [Category("Parameters")]
  75.                 public int LeftStrength
  76.                 {
  77.                         get { return pLeftStrength; }
  78.                         set { pLeftStrength = Math.Max(1,value); }
  79.                 }
  80.  
  81.                 [Description("Right strength")]
  82.                 [Category("Parameters")]
  83.                 public int RightStrength
  84.                 {
  85.                         get { return pRightStrength; }
  86.                         set { pRightStrength = Math.Max(1,value); }
  87.                 }
  88.                
  89.                 private FractalPivot_TradeStation_Type pType = FractalPivot_TradeStation_Type.Both;
  90.                 [Description("High prices, Low prices, or both")]
  91.                 [Category("Parameters")]
  92.                 public FractalPivot_TradeStation_Type Type
  93.                 {
  94.                         get { return pType; }
  95.                         set { pType = value; }
  96.                 }
  97.                
  98.                 #endregion
  99.         }
  100. }
  101. public enum FractalPivot_TradeStation_Type {
  102.         Highs,
  103.         Lows,
  104.         Both
  105. }
  106.  
  107. #region NinjaScript generated code. Neither change nor remove.
  108. // This namespace holds all indicators and is required. Do not change it.
  109. namespace NinjaTrader.Indicator
  110. {
  111.     public partial class Indicator : IndicatorBase
  112.     {
  113.         private FractalPivot_TradeStation[] cacheFractalPivot_TradeStation = null;
  114.  
  115.         private static FractalPivot_TradeStation checkFractalPivot_TradeStation = new FractalPivot_TradeStation();
  116.  
  117.         /// <summary>
  118.         ///
  119.         /// </summary>
  120.         /// <returns></returns>
  121.         public FractalPivot_TradeStation FractalPivot_TradeStation(int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  122.         {
  123.             return FractalPivot_TradeStation(Input, leftStrength, rightStrength, type);
  124.         }
  125.  
  126.         /// <summary>
  127.         ///
  128.         /// </summary>
  129.         /// <returns></returns>
  130.         public FractalPivot_TradeStation FractalPivot_TradeStation(Data.IDataSeries input, int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  131.         {
  132.             if (cacheFractalPivot_TradeStation != null)
  133.                 for (int idx = 0; idx < cacheFractalPivot_TradeStation.Length; idx++)
  134.                     if (cacheFractalPivot_TradeStation[idx].LeftStrength == leftStrength && cacheFractalPivot_TradeStation[idx].RightStrength == rightStrength && cacheFractalPivot_TradeStation[idx].Type == type && cacheFractalPivot_TradeStation[idx].EqualsInput(input))
  135.                         return cacheFractalPivot_TradeStation[idx];
  136.  
  137.             lock (checkFractalPivot_TradeStation)
  138.             {
  139.                 checkFractalPivot_TradeStation.LeftStrength = leftStrength;
  140.                 leftStrength = checkFractalPivot_TradeStation.LeftStrength;
  141.                 checkFractalPivot_TradeStation.RightStrength = rightStrength;
  142.                 rightStrength = checkFractalPivot_TradeStation.RightStrength;
  143.                 checkFractalPivot_TradeStation.Type = type;
  144.                 type = checkFractalPivot_TradeStation.Type;
  145.  
  146.                 if (cacheFractalPivot_TradeStation != null)
  147.                     for (int idx = 0; idx < cacheFractalPivot_TradeStation.Length; idx++)
  148.                         if (cacheFractalPivot_TradeStation[idx].LeftStrength == leftStrength && cacheFractalPivot_TradeStation[idx].RightStrength == rightStrength && cacheFractalPivot_TradeStation[idx].Type == type && cacheFractalPivot_TradeStation[idx].EqualsInput(input))
  149.                             return cacheFractalPivot_TradeStation[idx];
  150.  
  151.                 FractalPivot_TradeStation indicator = new FractalPivot_TradeStation();
  152.                 indicator.BarsRequired = BarsRequired;
  153.                 indicator.CalculateOnBarClose = CalculateOnBarClose;
  154. #if NT7
  155.                 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
  156.                 indicator.MaximumBarsLookBack = MaximumBarsLookBack;
  157. #endif
  158.                 indicator.Input = input;
  159.                 indicator.LeftStrength = leftStrength;
  160.                 indicator.RightStrength = rightStrength;
  161.                 indicator.Type = type;
  162.                 Indicators.Add(indicator);
  163.                 indicator.SetUp();
  164.  
  165.                 FractalPivot_TradeStation[] tmp = new FractalPivot_TradeStation[cacheFractalPivot_TradeStation == null ? 1 : cacheFractalPivot_TradeStation.Length + 1];
  166.                 if (cacheFractalPivot_TradeStation != null)
  167.                     cacheFractalPivot_TradeStation.CopyTo(tmp, 0);
  168.                 tmp[tmp.Length - 1] = indicator;
  169.                 cacheFractalPivot_TradeStation = tmp;
  170.                 return indicator;
  171.             }
  172.         }
  173.     }
  174. }
  175.  
  176. // This namespace holds all market analyzer column definitions and is required. Do not change it.
  177. namespace NinjaTrader.MarketAnalyzer
  178. {
  179.     public partial class Column : ColumnBase
  180.     {
  181.         /// <summary>
  182.         ///
  183.         /// </summary>
  184.         /// <returns></returns>
  185.         [Gui.Design.WizardCondition("Indicator")]
  186.         public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  187.         {
  188.             return _indicator.FractalPivot_TradeStation(Input, leftStrength, rightStrength, type);
  189.         }
  190.  
  191.         /// <summary>
  192.         ///
  193.         /// </summary>
  194.         /// <returns></returns>
  195.         public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(Data.IDataSeries input, int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  196.         {
  197.             return _indicator.FractalPivot_TradeStation(input, leftStrength, rightStrength, type);
  198.         }
  199.     }
  200. }
  201.  
  202. // This namespace holds all strategies and is required. Do not change it.
  203. namespace NinjaTrader.Strategy
  204. {
  205.     public partial class Strategy : StrategyBase
  206.     {
  207.         /// <summary>
  208.         ///
  209.         /// </summary>
  210.         /// <returns></returns>
  211.         [Gui.Design.WizardCondition("Indicator")]
  212.         public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  213.         {
  214.             return _indicator.FractalPivot_TradeStation(Input, leftStrength, rightStrength, type);
  215.         }
  216.  
  217.         /// <summary>
  218.         ///
  219.         /// </summary>
  220.         /// <returns></returns>
  221.         public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(Data.IDataSeries input, int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  222.         {
  223.             if (InInitialize && input == null)
  224.                 throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
  225.  
  226.             return _indicator.FractalPivot_TradeStation(input, leftStrength, rightStrength, type);
  227.         }
  228.     }
  229. }
  230. #endregion
  231.  
  232.  



Curt

  • Supporting Member
  • Joined in 2006
  • **
  • gravatar avatar
  • Posts: 6,755
    • View Profile
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #12 on: November 02, 2011, 05:28:51 PM »
Quote from: NinjaTrader Support
you can enable / disable specific sounds under Tools > Options > General  in your Control Center

-but maybe this option is missing if you are running the free version?

If you search their site and keep an eye on new feature development, you may want to look for "enhancement # 1254" (new audio settings).