Sine Weighted MA (SWMA) - NinjaTrader | futures io social day trading
futures io futures trading


Sine Weighted MA (SWMA)
Updated: Views / Replies:4,301 / 16
Created: by Sam7768 Attachments:6

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors Ė all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you donít need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 6  
 
Thread Tools Search this Thread
 

Sine Weighted MA (SWMA)

  #11 (permalink)
Elite Member
Dallas, Texas, USA
 
Futures Experience: Beginner
Platform: NT 6.5 & Tradestation
Favorite Futures: Equities & ES
 
Posts: 45 since Sep 2010
Thanks: 21 given, 9 received

Sine Weighted MA


Sam7768 View Post
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: c.kryza@gte.net
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) );
}
}

Reply With Quote
 
  #12 (permalink)
Elite Member
Dallas, Texas, USA
 
Futures Experience: Beginner
Platform: NT 6.5 & Tradestation
Favorite Futures: Equities & ES
 
Posts: 45 since Sep 2010
Thanks: 21 given, 9 received

Sine Weighted MA code


Sam7768 View Post
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


Last edited by Sam7768; November 28th, 2010 at 11:21 AM.
Reply With Quote
 
  #13 (permalink)
Site Administrator
Manta, Ecuador
 
Futures Experience: Advanced
Platform: My own custom solution
Favorite Futures: E-mini ES S&P 500
 
Big Mike's Avatar
 
Posts: 46,238 since Jun 2009
Thanks: 29,350 given, 83,218 received

Answer
This post has been selected as an answer to the original posters question Answer


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

Due to time constraints, please do not PM me if your question can be resolved or answered on the forum.

Need help?
1) Stop changing things. No new indicators, charts, or methods. Be consistent with what is in front of you first.
2) Start a journal and post to it daily with the trades you made to show your strengths and weaknesses.
3) Set goals for yourself to reach daily. Make them about how you trade, not how much money you make.
4) Accept responsibility for your actions. Stop looking elsewhere to explain away poor performance.
5) Where to start as a trader? Watch this webinar and read this thread for hundreds of questions and answers.
6)
Help using the forum? Watch this video to learn general tips on using the site.

If you want
to support our community, become an Elite Member.

Reply With Quote
 
  #14 (permalink)
Market Wizard
virginia
 
Futures Experience: Intermediate
Platform: ninja
Favorite Futures: ES
 
cory's Avatar
 
Posts: 5,215 since Jun 2009
Thanks: 628 given, 6,312 received

not much diff from a SMA.

Reply With Quote
 
  #15 (permalink)
Elite Member
Dallas, Texas, USA
 
Futures Experience: Beginner
Platform: NT 6.5 & Tradestation
Favorite Futures: Equities & ES
 
Posts: 45 since Sep 2010
Thanks: 21 given, 9 received


cory View Post
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...

Attached Thumbnails
Sine Weighted MA (SWMA)-es-12-10-11_26_2010-512-tick-.jpg  
Reply With Quote
The following user says Thank You to Sam7768 for this post:
 
  #16 (permalink)
Elite Member
Quebec
 
Futures Experience: Intermediate
Platform: NinjaTrader wt Rancho Dinero's profiling tools
Broker/Data: Stage 5 trading/AMP/CQG
Favorite Futures: ES, NQ, YM
 
trendisyourfriend's Avatar
 
Posts: 3,697 since Oct 2009
Thanks: 3,041 given, 4,496 received

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 :

Attached Thumbnails
Sine Weighted MA (SWMA)-sinewavema_weightedmajpg.jpg  
Reply With Quote
The following user says Thank You to trendisyourfriend for this post:
 
  #17 (permalink)
Elite Member
Holland, Michigan
 
Futures Experience: None
Platform: ninjatrader
Broker/Data: CQG
Favorite Futures: Acoustic Guitar
 
trs3042's Avatar
 
Posts: 1,802 since Jun 2009
Thanks: 23,771 given, 5,600 received

SWMA


Big Mike View Post
If there is a NT7 version, please attach it so it can be backported.

Mike

Here it is Mike.

Rick

Attached Files
Register to download File Type: zip SWMA.zip (1.8 KB, 65 views)
Reply With Quote

Reply



futures io > > > > Sine Weighted MA (SWMA)

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hilbert sine wave indicator ntsst3 NinjaTrader 77 November 20th, 2015 07:15 PM
Double MA and Triple MA Script Sadboybh NinjaTrader Programming 8 June 17th, 2011 09:57 AM
Triple MA trs3042 NinjaTrader 3 February 25th, 2011 02:33 AM
MA of LinReg RomanFx The Elite Circle 2 July 10th, 2010 08:55 PM
Need help with MA Envelope Indicator Please Curbfeeler The Elite Circle 8 March 21st, 2010 03:02 PM


All times are GMT -4. The time now is 10:59 PM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
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.
no new posts
Page generated 2017-12-11 in 0.15 seconds with 34 queries on phoenix via your IP 54.145.16.43