NexusFi: Find Your Edge


Home Menu

 





Better Sine Wave or Hilbert Sine wave with S/R lines (Ninjatrader 8)


Discussion in Traders Hideout

Updated
    1. trending_up 1,116 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 2 posts
    2. attach_file 0 attachments




 
Search this Thread
  #1 (permalink)
 rx13 
Delhi, India
 
Experience: Intermediate
Platform: NinjaTrader, others
Trading: Future and Options
Frequency: Every few days
Duration: Days
Posts: 28 since Mar 2023
Thanks Given: 24
Thanks Received: 18

Can someone please tell me if there is a Better Sine wave indicator or Hilbert Sine wave (with S/R lines) available for NT8 in nexusfi (like eminiwatch) ? The only sine wave I find was built for NT7. Here is one from ninjatrader forum but unfortunately it is also made with older version.

https://forum.ninjatrader.com/forum/ninjascript-file-sharing/ninjascript-file-sharing-discussion/16601-ehlers-sine-wave?p=235381#post235381


Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Would a node-based workflow for automated trading be useful?
Traders Hideout
El Clasico Draws $9.2M in Prediction Market Action -- Bi …
Prediction Markets & Event Contracts
I Have a Thing Called Iran -- Trump Stays in DC as Airsp …
Prediction Markets & Event Contracts
Hormuz Normalization Collapses to 19.5% -- Iran Regime F …
Prediction Markets & Event Contracts
Trump Lands in Beijing on CPI Day: Iran Peace Expires To …
Prediction Markets & Event Contracts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
NexusFi site changelog and issues/problem reporting
8 thanks
Darmok and Jalad at Tanagra
1 thanks
  #2 (permalink)
 JBWTrader 
Murrays Bay
 
Experience: Advanced
Platform: NT*,Tradestation
Trading: ES, NQ
Frequency: Many times daily
Duration: Seconds
Posts: 80 since Aug 2017
Thanks Given: 5,262
Thanks Received: 109

i put into chat gpt 4.0 and it spat out this

using System;
using NinjaTrader.Cbi;
using NinjaTrader.Gui.Tools;
using NinjaTrader.NinjaScript;
using NinjaTrader.NinjaScript.Strategies;
using NinjaTrader.Data;
using NinjaTrader.NinjaScript.StrategyAnalyzer;
using NinjaTrader.Gui.StrategyAnalyzer;
using NinjaTrader.NinjaScript.Strategies.SpreadAnalyzer;
using NinjaTrader.NinjaScript.StrategyAnalyzerMetrics;

namespace NinjaTrader.NinjaScript.Strategies
{
public class TrueHilbertSineWaveIndicator : Strategy
{
private int period;
private double[] price;
private double[] hilbert;
private double[] sine;
private double[] leadSine;

protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"True Hilbert Sine Wave Indicator";
Name = "TrueHilbertSineWaveIndicator";
Calculate = Calculate.OnEachTick;
IsOverlay = true;

// Default period for the Hilbert Transform
period = 40; // This value can be adjusted based on the frequency of the cycle
price = new double[period];
hilbert = new double[period];
sine = new double[period];
leadSine = new double[period];
}
}

protected override void OnBarUpdate()
{
if (CurrentBar < period)
return;

// Store the median price in the price array
price[0] = (High[0] + Low[0]) / 2;

// Compute the Hilbert Transform
for (int i = 0; i < period; i++)
{
double sum = 0.0;
for (int j = 0; j < period; j++)
{
if (i - j >= 0)
{
sum += price[j] * Math.Sin(Math.PI * (i - j) / period);
}
}
hilbert[i] = sum;
}

// Compute the Sine and Lead Sine
for (int i = 0; i < period; i++)
{
sine[i] = Math.Sin(Math.Atan2(hilbert[i], price[i]));
if (i > 0)
{
leadSine[i] = sine[i - 1];
}
}

// Plot the Sine and Lead Sine values
Values[0][0] = sine[0];
Values[1][0] = leadSine[0];
}

public override string[] DataSeries
{
get { return new string[] { "Sine", "Lead Sine" }; }
}
}
}


Key Points:
Complexity: This implementation is more complex and attempts to more accurately represent the Hilbert Transform. It calculates a continuous sine wave representation of the price action, useful for identifying market cycles.

Testing and Optimization: This indicator should be thoroughly tested and possibly optimized for the specific asset and time frame you are trading.

Expertise in Signal Processing: The Hilbert Transform is a complex topic in digital signal processing. If you are not familiar with these concepts, you might need further research or consultation with a specialist.

Indicator Characteristics: The Hilbert Sine Wave indicator is used to identify market cycles and should not be used in isolation. It's typically more effective when combined with other indicators and analysis techniques.

Remember to test this script thoroughly in a simulated environment before applying it to live trading, as it's a complex tool and can have significant implications on trading decisions.


Visit my NexusFi Trade Journal Reply With Quote
Thanked by:
  #3 (permalink)
 Arthurtrades 
Paris France
 
Experience: Intermediate
Platform: sd
Trading: sd
Posts: 20 since Aug 2023
Thanks Given: 45
Thanks Received: 13



JBWTrader View Post
i put into chat gpt 4.0 and it spat out this



using System;

using NinjaTrader.Cbi;

using NinjaTrader.Gui.Tools;

using NinjaTrader.NinjaScript;

using NinjaTrader.NinjaScript.Strategies;

using NinjaTrader.Data;

using NinjaTrader.NinjaScript.StrategyAnalyzer;

using NinjaTrader.Gui.StrategyAnalyzer;

using NinjaTrader.NinjaScript.Strategies.SpreadAnalyzer;

using NinjaTrader.NinjaScript.StrategyAnalyzerMetrics;



namespace NinjaTrader.NinjaScript.Strategies

{

public class TrueHilbertSineWaveIndicator : Strategy

{

private int period;

private double[] price;

private double[] hilbert;

private double[] sine;

private double[] leadSine;



protected override void OnStateChange()

{

if (State == State.SetDefaults)

{

Description = @"True Hilbert Sine Wave Indicator";

Name = "TrueHilbertSineWaveIndicator";

Calculate = Calculate.OnEachTick;

IsOverlay = true;



// Default period for the Hilbert Transform

period = 40; // This value can be adjusted based on the frequency of the cycle

price = new double[period];

hilbert = new double[period];

sine = new double[period];

leadSine = new double[period];

}

}



protected override void OnBarUpdate()

{

if (CurrentBar < period)

return;



// Store the median price in the price array

price[0] = (High[0] + Low[0]) / 2;



// Compute the Hilbert Transform

for (int i = 0; i < period; i++)

{

double sum = 0.0;

for (int j = 0; j < period; j++)

{

if (i - j >= 0)

{

sum += price[j] * Math.Sin(Math.PI * (i - j) / period);

}

}

hilbert[i] = sum;

}



// Compute the Sine and Lead Sine

for (int i = 0; i < period; i++)

{

sine[i] = Math.Sin(Math.Atan2(hilbert[i], price[i]));

if (i > 0)

{

leadSine[i] = sine[i - 1];

}

}



// Plot the Sine and Lead Sine values

Values[0][0] = sine[0];

Values[1][0] = leadSine[0];

}



public override string[] DataSeries

{

get { return new string[] { "Sine", "Lead Sine" }; }

}

}

}





Key Points:

Complexity: This implementation is more complex and attempts to more accurately represent the Hilbert Transform. It calculates a continuous sine wave representation of the price action, useful for identifying market cycles.



Testing and Optimization: This indicator should be thoroughly tested and possibly optimized for the specific asset and time frame you are trading.



Expertise in Signal Processing: The Hilbert Transform is a complex topic in digital signal processing. If you are not familiar with these concepts, you might need further research or consultation with a specialist.



Indicator Characteristics: The Hilbert Sine Wave indicator is used to identify market cycles and should not be used in isolation. It's typically more effective when combined with other indicators and analysis techniques.



Remember to test this script thoroughly in a simulated environment before applying it to live trading, as it's a complex tool and can have significant implications on trading decisions.

Up

Sent using the NexusFi mobile app


Reply With Quote




Last Updated on December 26, 2023


© 2026 NexusFi®, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Downloads - Top
no new posts