Dark Theme
Light Theme
Trading Articles
Article Categories
Article Tools
Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to
register in order to view the content of the threads and start contributing to our community.
It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
Sine Weighted MA (SWMA)
Updated November 28, 2010
Top Posters
looks_one
Sam7768
with 8 posts (1 thanks)
looks_two
cory
with 3 posts (1 thanks)
looks_3
Big Mike
with 2 posts (0 thanks)
looks_4
trendisyourfriend
with 1 posts (1 thanks)
trending_up
7,779 views
thumb_up
3 thanks given
group
5 followers
forum
16 posts
attach_file
6 attachments
Sine Weighted MA (SWMA)
November 27th, 2010, 04:50 PM
Dallas, Texas, USA
Experience: Beginner
Platform: NT 6.5 & Tradestation
Trading: Equities & ES
Posts: 47 since Sep 2010
Thanks Given: 21
Thanks Received: 9
Sam7768
Thank you Cory. I will try to code and post it. Thanks again for your time & effort.
Here is the code for e-signal. Thjs MA is normalized and is extremely smooth and excellent indicator for direction...Spend weekend to code it in NT 6.5 and gave up.
Any one can try coding this to NT 6.5?
/********************************************************************
Title: Sine Weighted MA for eSignal 7.x
By: Chris D. Kryza (Divergence Software, Inc.)
Email: [email protected]
Incept: 02/17/2004
Version: 1.0.0
=====================================================================
Fix History:
02/17/2004 - Initial Release
1.0.0
=====================================================================
Project Description:
Sine Weighted Moving Average plot.
Dislaimer: For educational purposes only! Obviously, no guarantees
whatsoever and use at your own risk.
**********************************************************************/
//External Variables
var nBarCounter = 0;
var nFac = null;
var nVal2 = null;
var aFPArray = new Array();
var bInitialized = false;
//== PreMain function required by eSignal to set things up
function preMain() {
var x;
setPriceStudy(true);
setStudyTitle("Sine Weighted MA");
setCursorLabelName("SineMA", 0);
setDefaultBarFgColor( Color.blue, 0 );
setShowTitleParameters( false );
//initialize formula parameters
x=0;
aFPArray[x] = new FunctionParameter( "Period", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setLowerLimit( 2 );
setUpperLimit( 125 );
setDefault( 15 );
}
x++;
aFPArray[x] = new FunctionParameter( "Price", FunctionParameter.STRING);
with( aFPArray[x] ) {
addOption( "Close" );
addOption( "HL/2" );
addOption( "HLC/3" );
addOption( "OHLC/4" );
addOption( "High" );
addOption( "Low" );
setDefault( "Close" );
}
x++;
aFPArray[x] = new FunctionParameter( "Color", FunctionParameter.COLOR);
with( aFPArray[x] ) {
setDefault( Color.blue );
}
x++;
aFPArray[x] = new FunctionParameter( "Thickness", FunctionParameter.NUMBER);
with( aFPArray[x] ) {
setLowerLimit( 1 );
setUpperLimit( 10 );
setDefault( 2 );
}
}
//== Main processing function
function main( Period, Price, Color, Thickness ) {
var x;
//script is initializing
if ( getBarState() == BARSTATE_ALLBARS ) {
return null;
}
if ( bInitialized == false ) {
setDefaultBarFgColor( Color, 0 );
setDefaultBarThickness( Math.round( Thickness ), 0 );
nFac = Math.PI / ( Period+1 );
nVal2 = 0;
//calculate the denominator. This won't change
for ( x=0; x<Math.round(Period); x++ ) {
nVal2 += Math.sin( (x+1) * nFac );
}
bInitialized = true;
}
//called on each new bar
if ( getBarState() == BARSTATE_NEWBAR ) {
nBarCounter++;
}
nVal1 = 0;
nMax = Math.round( Period );
for ( x=0; x<nMax; x++ ) {
nVal1 += Math.sin( (x+1) * nFac ) * getPrice( Price, x );
}
nPlot = nVal1/nVal2;
return( nPlot );
}
/*************************************************
SUPPORT FUNCTIONS
**************************************************/
//== gID function assigns unique identifier to graphic/text routines
function gID() {
grID ++;
return( grID );
}
//== return price type selected by user
function getPrice( Price, nOffset ) {
if ( Price == "Close" ) {
return( close(-nOffset ) );
}
else if ( Price == "HL/2" ) {
return( (high(-nOffset)+low(-nOffset)) / 2 );
}
else if ( Price == "HLC/3" ) {
return( (high(-nOffset)+low(-nOffset)+close(-nOffset)) / 3 );
}
else if ( Price == "OHLC/4" ) {
return( (open(-nOffset)+high(-nOffset)+low(-nOffset)+close(-nOffset)) / 4 );
}
else if ( Price == "Low" ) {
return( low(-nOffset) );
}
else if ( Price == "High" ) {
return( high(-nOffset) );
}
}
Can you help answer these questions from other members on NexusFi?
Best Threads (Most Thanked) in the last 7 days on NexusFi
November 27th, 2010, 11:37 PM
Dallas, Texas, USA
Experience: Beginner
Platform: NT 6.5 & Tradestation
Trading: Equities & ES
Posts: 47 since Sep 2010
Thanks Given: 21
Thanks Received: 9
Sam7768
Thank you Cory. I will try to code and post it. Thanks again for your time & effort.
Here is the code for NT 6.5
Code
Sine Weighted Moving Average (SWMA). (I am new to NT hence do not know how to make it importable, so, please copy and paste it as an indicator)
#region Using declarations
using System;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.ComponentModel;
using System.Xml.Serialization;
using NinjaTrader.Data;
using NinjaTrader.Gui.Chart;
#endregion
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
/// <summary>
/// The SWMA is an indicator
/// </summary>
[Description("The SWMA is an indicator that shows the average value of a security's price over a period of time.")]
public class SWMA : Indicator
{
#region Variables
private int period = 14;
#endregion
/// <summary>
/// This method is used to configure the indicator and is called once before any bar data is loaded.
/// </summary>
protected override void Initialize()
{
Add(new Plot(Color.Orange, "SWMA"));
Overlay = true;
PriceTypeSupported = true;
}
/// <summary>
/// Called on each bar update event (incoming tick).
/// </summary>
protected override void OnBarUpdate()
{
if (CurrentBar < Period+1) return;
double nFac = Math.PI / ( Period+1 );
double nVal2 = 0;
for ( int x=0; x<Period; x++ )
{
nVal2 += Math.Sin( (x+1) * nFac );
}
double nVal1 = 0;
for ( int x=0; x<Period; x++ )
{
nVal1 += Math.Sin( (x+1) * nFac ) * Close[x];
}
Value.Set(nVal1/nVal2);
}
#region Properties
/// <summary>
/// </summary>
[Description("Numbers of bars used for calculations")]
[Category("Parameters")]
public int Period
{
get { return period; }
set { period = Math.Max(1, value); }
}
#endregion
}
}
#region NinjaScript generated code. Neither change nor remove.
// This namespace holds all indicators and is required. Do not change it.
namespace NinjaTrader.Indicator
{
public partial class Indicator : IndicatorBase
{
private SWMA[] cacheSWMA = null;
private static SWMA checkSWMA = new SWMA();
/// <summary>
/// The SWMA is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
/// <returns></returns>
public SWMA SWMA(int period)
{
return SWMA(Input, period);
}
/// <summary>
/// The SWMA is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
/// <returns></returns>
public SWMA SWMA(Data.IDataSeries input, int period)
{
checkSWMA.Period = period;
period = checkSWMA.Period;
if (cacheSWMA != null)
for (int idx = 0; idx < cacheSWMA.Length; idx++)
if (cacheSWMA[idx].Period == period && cacheSWMA[idx].EqualsInput(input))
return cacheSWMA[idx];
SWMA indicator = new SWMA();
indicator.BarsRequired = BarsRequired;
indicator.CalculateOnBarClose = CalculateOnBarClose;
indicator.Input = input;
indicator.Period = period;
indicator.SetUp();
SWMA[] tmp = new SWMA[cacheSWMA == null ? 1 : cacheSWMA.Length + 1];
if (cacheSWMA != null)
cacheSWMA.CopyTo(tmp, 0);
tmp[tmp.Length - 1] = indicator;
cacheSWMA = tmp;
Indicators.Add(indicator);
return indicator;
}
}
}
// This namespace holds all market analyzer column definitions and is required. Do not change it.
namespace NinjaTrader.MarketAnalyzer
{
public partial class Column : ColumnBase
{
/// <summary>
/// The SWMA is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.SWMA SWMA(int period)
{
return _indicator.SWMA(Input, period);
}
/// <summary>
/// The SWMA is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
/// <returns></returns>
public Indicator.SWMA SWMA(Data.IDataSeries input, int period)
{
return _indicator.SWMA(input, period);
}
}
}
// This namespace holds all strategies and is required. Do not change it.
namespace NinjaTrader.Strategy
{
public partial class Strategy : StrategyBase
{
/// <summary>
/// The SWMA is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
/// <returns></returns>
[Gui.Design.WizardCondition("Indicator")]
public Indicator.SWMA SWMA(int period)
{
return _indicator.SWMA(Input, period);
}
/// <summary>
/// The SWMA is an indicator that shows the average value of a security's price over a period of time.
/// </summary>
/// <returns></returns>
public Indicator.SWMA SWMA(Data.IDataSeries input, int period)
{
if (InInitialize && input == null)
throw new ArgumentException("You only can access an indicator with the default input/bar series from within the 'Initialize()' method");
return _indicator.SWMA(input, period);
}
}
}
#endregion
November 28th, 2010, 12:34 AM
Manta, Ecuador
Site Administrator Developer Swing Trader
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,460 since Jun 2009
Thanks Given: 33,234
Thanks Received: 101,655
Tip
If posting code snippets, please wrap it in the [code]put code in here[/code] tags. If posting entire indicators, please attach the file instead of cutting and pasting it.
Mike
November 28th, 2010, 02:42 AM
virginia
Experience: Intermediate
Platform: ninja
Trading: NQ
Posts: 6,098 since Jun 2009
Thanks Given: 877
Thanks Received: 8,090
not much diff from a SMA .
November 28th, 2010, 08:46 AM
Dallas, Texas, USA
Experience: Beginner
Platform: NT 6.5 & Tradestation
Trading: Equities & ES
Posts: 47 since Sep 2010
Thanks Given: 21
Thanks Received: 9
cory
not much diff from a
SMA .
50 period Weighted MA (WMA) and 50 period Sine Weighted MA (SWMA) combination gives simple, yet effective trend indication. Throw in 10 period WMA and 10 period SWMA, you get almost precise entry and exits within the large trend indications.
Attached the screen shots ...showing only 50 MAs...
November 28th, 2010, 09:40 AM
Quebec Canada
Market Wizard
Experience: Intermediate
Platform: NinjaTrader
Broker: AMP/CQG
Trading: ES, NQ, YM
Frequency: Daily
Duration: Minutes
Posts: 4,527 since Oct 2009
Thanks Given: 4,176
Thanks Received: 6,020
Sam,
Using Moving Average is nice and *appears to work very well in most cases. I also like to use trend lines as they seem to remove the lag inherent to a MA. Your chart is a good example of what we have to deal with every day: pullback and reversal or continuation and change of direction.
I have added some lines to your chart just to compare both approaches :
November 28th, 2010, 11:55 AM
Holland, Michigan
Experience: None
Platform: ninjatrader
Broker: CQG
Trading: Acoustic Guitar
Posts: 1,617 since Jun 2009
Thanks Given: 23,764
Thanks Received: 5,616
Big Mike
If there is a NT7 version, please attach it so it can be backported.
Mike
Here it is Mike.
Rick
Attached Files
Elite Membership required to download: SWMA.zip
Last Updated on November 28, 2010