topbanner_forum
  *

avatar image

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

Login with username, password and session length
  • Thursday March 28, 2024, 4:35 pm
  • Proudly celebrating 15+ 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 14448 times)

Niceperson

  • Supporting Member
  • Joined in 2010
  • **
  • Posts: 5
    • View Profile
    • Donate to Member
Fractal Trading Indicator
« on: October 31, 2011, 11:53 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: 13,288
  • 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 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: 13,288
  • 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 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,857
    • View Profile
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #3 on: October 31, 2011, 12:57 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 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: 13,288
  • 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 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# [Select]
  1. System.Media.SoundPlayer myPlayer = new System.Media.SoundPlayer();
  2. myPlayer.SoundLocation = @"c:\some-sound-file.wav";
  3. myPlayer.Play();

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 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: 13,288
  • 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 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# [Select]
  1. PlaySound(@"C:\mySound.wav");

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 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# [Select]
  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.         }
« Last Edit: November 01, 2011, 11:39 PM by skwire, Reason: Added code tags »

skwire

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 5,286
    • View Profile
    • Donate to Member
Re: Fractal Trading Indicator
« Reply #9 on: November 01, 2011, 11:41 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: 13,288
  • 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 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 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 [Select]
  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.                         //PlaySound(@"C:\Program Files\NinjaTrader 7\sounds\Alert4.wav");
  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.                                
  48.                         }
  49.                         if(pType == FractalPivot_TradeStation_Type.Both || pType == FractalPivot_TradeStation_Type.Lows) {
  50.                                 int bar = (int)Pivot_EasyLanguage(-1, 1, pLeftStrength, pRightStrength+1, pRightStrength).PivotBarRelative[0];
  51.                                
  52.                                 if(bar>=0) Values[1].Set(pRightStrength, Low[pRightStrength]-TickSize * pTickSeparation);
  53.                                
  54.                         }
  55.         }
  56.                
  57.                
  58.                
  59.  
  60.                
  61. //====================================================================
  62.                 #region Properties
  63.  
  64.                 [Description("Ticks separation from bar")]
  65.                 [Category("Visual")]
  66.                 public int TickSeparation
  67.                 {
  68.                         get { return pTickSeparation; }
  69.                         set { pTickSeparation = Math.Max(1,value); }
  70.                 }
  71.  
  72.                 [Description("Left strength")]
  73.                 [Category("Parameters")]
  74.                 public int LeftStrength
  75.                 {
  76.                         get { return pLeftStrength; }
  77.                         set { pLeftStrength = Math.Max(1,value); }
  78.                 }
  79.  
  80.                 [Description("Right strength")]
  81.                 [Category("Parameters")]
  82.                 public int RightStrength
  83.                 {
  84.                         get { return pRightStrength; }
  85.                         set { pRightStrength = Math.Max(1,value); }
  86.                 }
  87.                
  88.                 private FractalPivot_TradeStation_Type pType = FractalPivot_TradeStation_Type.Both;
  89.                 [Description("High prices, Low prices, or both")]
  90.                 [Category("Parameters")]
  91.                 public FractalPivot_TradeStation_Type Type
  92.                 {
  93.                         get { return pType; }
  94.                         set { pType = value; }
  95.                 }
  96.                
  97.                 #endregion
  98.         }
  99. }
  100. public enum FractalPivot_TradeStation_Type {
  101.         Highs,
  102.         Lows,
  103.         Both
  104. }
  105.  
  106. #region NinjaScript generated code. Neither change nor remove.
  107. // This namespace holds all indicators and is required. Do not change it.
  108. namespace NinjaTrader.Indicator
  109. {
  110.     public partial class Indicator : IndicatorBase
  111.     {
  112.         private FractalPivot_TradeStation[] cacheFractalPivot_TradeStation = null;
  113.  
  114.         private static FractalPivot_TradeStation checkFractalPivot_TradeStation = new FractalPivot_TradeStation();
  115.  
  116.         /// <summary>
  117.         ///
  118.         /// </summary>
  119.         /// <returns></returns>
  120.         public FractalPivot_TradeStation FractalPivot_TradeStation(int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  121.         {
  122.             return FractalPivot_TradeStation(Input, leftStrength, rightStrength, type);
  123.         }
  124.  
  125.         /// <summary>
  126.         ///
  127.         /// </summary>
  128.         /// <returns></returns>
  129.         public FractalPivot_TradeStation FractalPivot_TradeStation(Data.IDataSeries input, int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  130.         {
  131.             if (cacheFractalPivot_TradeStation != null)
  132.                 for (int idx = 0; idx < cacheFractalPivot_TradeStation.Length; idx++)
  133.                     if (cacheFractalPivot_TradeStation[idx].LeftStrength == leftStrength && cacheFractalPivot_TradeStation[idx].RightStrength == rightStrength && cacheFractalPivot_TradeStation[idx].Type == type && cacheFractalPivot_TradeStation[idx].EqualsInput(input))
  134.                         return cacheFractalPivot_TradeStation[idx];
  135.  
  136.             lock (checkFractalPivot_TradeStation)
  137.             {
  138.                 checkFractalPivot_TradeStation.LeftStrength = leftStrength;
  139.                 leftStrength = checkFractalPivot_TradeStation.LeftStrength;
  140.                 checkFractalPivot_TradeStation.RightStrength = rightStrength;
  141.                 rightStrength = checkFractalPivot_TradeStation.RightStrength;
  142.                 checkFractalPivot_TradeStation.Type = type;
  143.                 type = checkFractalPivot_TradeStation.Type;
  144.  
  145.                 if (cacheFractalPivot_TradeStation != null)
  146.                     for (int idx = 0; idx < cacheFractalPivot_TradeStation.Length; idx++)
  147.                         if (cacheFractalPivot_TradeStation[idx].LeftStrength == leftStrength && cacheFractalPivot_TradeStation[idx].RightStrength == rightStrength && cacheFractalPivot_TradeStation[idx].Type == type && cacheFractalPivot_TradeStation[idx].EqualsInput(input))
  148.                             return cacheFractalPivot_TradeStation[idx];
  149.  
  150.                 FractalPivot_TradeStation indicator = new FractalPivot_TradeStation();
  151.                 indicator.BarsRequired = BarsRequired;
  152.                 indicator.CalculateOnBarClose = CalculateOnBarClose;
  153. #if NT7
  154.                 indicator.ForceMaximumBarsLookBack256 = ForceMaximumBarsLookBack256;
  155.                 indicator.MaximumBarsLookBack = MaximumBarsLookBack;
  156. #endif
  157.                 indicator.Input = input;
  158.                 indicator.LeftStrength = leftStrength;
  159.                 indicator.RightStrength = rightStrength;
  160.                 indicator.Type = type;
  161.                 Indicators.Add(indicator);
  162.                 indicator.SetUp();
  163.  
  164.                 FractalPivot_TradeStation[] tmp = new FractalPivot_TradeStation[cacheFractalPivot_TradeStation == null ? 1 : cacheFractalPivot_TradeStation.Length + 1];
  165.                 if (cacheFractalPivot_TradeStation != null)
  166.                     cacheFractalPivot_TradeStation.CopyTo(tmp, 0);
  167.                 tmp[tmp.Length - 1] = indicator;
  168.                 cacheFractalPivot_TradeStation = tmp;
  169.                 return indicator;
  170.             }
  171.         }
  172.     }
  173. }
  174.  
  175. // This namespace holds all market analyzer column definitions and is required. Do not change it.
  176. namespace NinjaTrader.MarketAnalyzer
  177. {
  178.     public partial class Column : ColumnBase
  179.     {
  180.         /// <summary>
  181.         ///
  182.         /// </summary>
  183.         /// <returns></returns>
  184.         [Gui.Design.WizardCondition("Indicator")]
  185.         public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  186.         {
  187.             return _indicator.FractalPivot_TradeStation(Input, leftStrength, rightStrength, type);
  188.         }
  189.  
  190.         /// <summary>
  191.         ///
  192.         /// </summary>
  193.         /// <returns></returns>
  194.         public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(Data.IDataSeries input, int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  195.         {
  196.             return _indicator.FractalPivot_TradeStation(input, leftStrength, rightStrength, type);
  197.         }
  198.     }
  199. }
  200.  
  201. // This namespace holds all strategies and is required. Do not change it.
  202. namespace NinjaTrader.Strategy
  203. {
  204.     public partial class Strategy : StrategyBase
  205.     {
  206.         /// <summary>
  207.         ///
  208.         /// </summary>
  209.         /// <returns></returns>
  210.         [Gui.Design.WizardCondition("Indicator")]
  211.         public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  212.         {
  213.             return _indicator.FractalPivot_TradeStation(Input, leftStrength, rightStrength, type);
  214.         }
  215.  
  216.         /// <summary>
  217.         ///
  218.         /// </summary>
  219.         /// <returns></returns>
  220.         public Indicator.FractalPivot_TradeStation FractalPivot_TradeStation(Data.IDataSeries input, int leftStrength, int rightStrength, FractalPivot_TradeStation_Type type)
  221.         {
  222.             if (InInitialize && input == null)
  223.                 throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
  224.  
  225.             return _indicator.FractalPivot_TradeStation(input, leftStrength, rightStrength, type);
  226.         }
  227.     }
  228. }
  229. #endregion



Curt

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

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