Swing in a Strategy - NinjaTrader Programming | futures io social day trading
futures io futures trading


Swing in a Strategy
Updated: Views / Replies:5,192 / 10
Created: by MXASJ Attachments:4

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
 4  
 
Thread Tools Search this Thread
 

Swing in a Strategy

  #1 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

Swing in a Strategy

Hi All,

I've been looking at incorporating the Swing High/Low indicator in a strategy and have hit a wall. Basically what I'm trying to code is;

If Close[0] > most recent swing high

Go long. And its counterpart;

If Close[0] < most recent swing low

Go short.

I might even want to try something like;

If (most recent swing high) - (most recent swing low) < 12 ticks
and close[0] is between them

Don't trade.

Can anyone point me in the right direction? Thanks!

Reply With Quote
 
  #2 (permalink)
Elite Member
Frankfurt
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: FGBL 6E B4
 
max-td's Avatar
 
Posts: 1,754 since Jun 2009
Thanks: 2,309 given, 917 received

hi mx,

why you have hit a wall ?
what did you try yet with the swing high/low indie ?
how you define : most recent swing high ?

max-td
Reply With Quote
 
  #3 (permalink)
 Vendor: www.innovative-trading-solutions-online.com 
Hartford, CT. USA
 
Futures Experience: Intermediate
Platform: NinjaTrader
Broker/Data: AMP/CQG, Kinetick
Favorite Futures: TF
 
RJay's Avatar
 
Posts: 677 since Jun 2009
Thanks: 726 given, 740 received



MXASJ View Post
Hi All,

I've been looking at incorporating the Swing High/Low indicator in a strategy and have hit a wall. Basically what I'm trying to code is;

If Close[0] > most recent swing high

Go long. And its counterpart;

If Close[0] < most recent swing low

Go short.

I might even want to try something like;

If (most recent swing high) - (most recent swing low) < 12 ticks
and close[0] is between them

Don't trade.

Can anyone point me in the right direction? Thanks!

XMASJ,

You could try some sort of compare, different but more complex.

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

if (Math.Max(close[0], swing high) <= close[0] {Go long}

if (Math.Min(close[0], swing low) >=close[0] {Go short}

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

RJay

Reply With Quote
 
  #4 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

I'm on the road now so I'll respond more clearly when I'm back.

Getting the value of most recent swing hi/lo has confused me as close[0] doesn't have a value, and there are times when no hi|lo is drawn or has a null(zero?) value for some time. I'm sure its a "duh" thing that I am missing. In RJay's example its the "swing high" and "swing low" that has me stumped.

Totally OT to my own thread () I'm trying GoToMyPC for the first time and am chuffed that I can access my three-screen trading rig back home while sitting in a hotel in a different country with my laptop.

But I digress, and the day job becons...

Reply With Quote
 
  #5 (permalink)
Member
California
 
Futures Experience: Beginner
Platform: NinjaTrader
 
Posts: 87 since Jun 2009
Thanks: 5 given, 119 received


MXASJ View Post
Hi All,

I've been looking at incorporating the Swing High/Low indicator in a strategy and have hit a wall. Basically what I'm trying to code is;

If Close[0] > most recent swing high

Go long. And its counterpart;

If Close[0] < most recent swing low

Go short.

I might even want to try something like;

If (most recent swing high) - (most recent swing low) < 12 ticks
and close[0] is between them

Don't trade.

Can anyone point me in the right direction? Thanks!

Something like this?

 
Code
                            
using System;

using System.ComponentModel;
using NinjaTrader.Indicator;

namespace 
NinjaTrader.Strategy
{
    [
Description ("Swing strategy.")]
    public class 
SwingStrategy Strategy
    
{
        
Swing _swing;

        protected 
override void Initialize ()
        {
            
Add (_swing Swing (_strength));
            
CalculateOnBarClose true;
        }

        protected 
override void OnBarUpdate ()
        {
            if (
CurrentBar 1)
                return;

            
double high _swing.SwingHigh [0];    // most recent swing high
            
double low _swing.SwingLow [0];    // most recent swing low
            
double close Close [0];    // latest price

            
if (high low >= 12 TickSize)    // only trade if swing is big enough
            
{
                if (
close high)
                    
EnterLong ();
                else if (
close low)
                    
EnterShort ();
            }
        }

        [
Category ("Parameters")]
        public 
int Strength
        
{
            
get { return _strength; }
            
set _strength Math.Max (1value); }
        }
        
int _strength;
    }


Attached Thumbnails
Swing in a Strategy-untitled.png  
Reply With Quote
 
  #6 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

Piresh that is very close to what I am trying to do. Before I saw your code I wrote this:

 
Code
                            
protected override void OnBarUpdate()
{
// Condition set 1 SHORT
if ((Swing(7).SwingLow[1] == 0)||((Swing(7).SwingHigh[1] - Swing(7).SwingLow[1]) >= 2.00))
{
DrawArrowDown("My down arrow" CurrentBarfalse02*TickSizeColor.Red);
}
// Condition set 2 LONG
if ((Swing(7).SwingHigh[1] == 0)||((Swing(7).SwingHigh[1] - Swing(7).SwingLow[1]) >= 2.00))
{
DrawArrowUp("My up arrow" CurrentBarfalse02*TickSizeColor.Lime);
}

Which doesn't work. You will see I'm trying an OR condition as well. The logic is;

The swing range needs to be wide enough OR the current SwingLow is 0 for shorts

The swing range needs to be wide enough OR the current SwingHigh is 0 for longs

I'll play some more and post it back!

EDIT TO ADD: For newcomers to Ninja Script [I include myslef in that comment!] you will see I'm making to simple mistakes in the code that I'm fixing as I go along. Look at the difference in the draw arrow code from this to the next.


Last edited by MXASJ; October 2nd, 2009 at 04:11 AM.
Reply With Quote
 
  #7 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

Some progress... but I'm getting up and down arrows on every bar. My broker would love me but it's not quite right;
 
Code
                            
protected override void Initialize()
{
Add (_swing Swing (_strength));
CalculateOnBarClose true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
 
if (
CurrentBar 1)
return;
 
double high _swing.SwingHigh[0]; // Most recent swing high (?)
double low _swing.SwingLow[0]; // Most recent swing low (?)
double close Close[0]; // latest price
 
// Condition set 1 SHORT
if ((high low >= 20TickSize));
{
DrawArrowDown("My down arrow" CurrentBarfalse0High[0]+(2*TickSize), Color.Red);
}
// Condition set 2 LONG
if ((high low >= 20TickSize));
{
DrawArrowUp("My up arrow" CurrentBarfalse0Low[0]+(-2*TickSize), Color.Lime);
}
}
#region Properties
[Description("")]
[
Category("Parameters")]
public 
int Strength
{
get { return _strength; }
set _strength Math.Max (7value); }
}
int _strength
I upped the value to 20*TickSize just to try it, but still not there...

EDIT: Long arrows are now being drawn 2 ticks below the low of the bar, and short arrows two tick above the highs of the bar. Doh!


Last edited by MXASJ; October 2nd, 2009 at 03:33 AM.
Reply With Quote
 
  #8 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received

Added a condition to see where it was doing what;

 
Code
                            
// Condition set 1 SHORT
if (high low >= 12TickSize
&& close low
)
{
DrawArrowDown("My down arrow" CurrentBarfalse0High[0]+(2*TickSize), Color.Red);
}
// Condition set 2 LONG
if (high low >= 12TickSize
&& close high
)
{
DrawArrowUp("My up arrow" CurrentBarfalse0Low[0]+(-2*TickSize), Color.Lime);

If memory serves this is where I gave up when a first looked at Swing a few months back. I think the value of swing hight or low is zero some times and that throws the logic out of whack.

Reply With Quote
 
  #9 (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,220 received

Always use Print statements to see what the data looks like if you are having trouble. Open the output window.

You might want to only know when a new Swing high or low has been formed, which you need to write some code to detect.

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
 
  #10 (permalink)
Elite Member
Asia
 
Futures Experience: Beginner
Platform: NinjaTrader, TOS
 
Posts: 798 since Jun 2009
Thanks: 109 given, 786 received


Printin' as we speak

 
Code
                            
// Condition set 1 SHORT
if (high low >= 12TickSize
&& close low
)
{
DrawArrowDown("My down arrow" CurrentBarfalse0High[0]+(2*TickSize), Color.Red);
Print (
Time[0] + " The Swing High value is: " high);
Print (
Time[0] + " The Swing Low value is: " low);
}
// Condition set 2 LONG
if (high low >= 12TickSize 
&& close high
)
{
DrawArrowUp("My up arrow" CurrentBarfalse0Low[0]+(-2*TickSize), Color.Lime);
Print (
Time[0] + " The Swing High value is: " high);
Print (
Time[0] + " The Swing Low value is: " low);

What appears to be happening is it only trades "breakouts" from the swing zone (fair enough, based on the entry trigger), but the 12 tick filter stays in place even if no new swing line is drawn on the chart by the indicator. What that means is if we are in a 14 tick swing range and it breaks out, a trade is put on. If we are in a 12 tick or less range and the price breaks out, it will NOT trade until a new swing range greater than 12 is drawn. So some of those lovely swing breakouts that keep climbing up or down are NOT traded if the previous swing range was <12... until they top or bottom out and a new swing range >12 is drawn by the indicator. Hmmm ...

Attached Thumbnails
Swing in a Strategy-wide-range.jpg   Swing in a Strategy-narrow-range.jpg  

Last edited by MXASJ; October 2nd, 2009 at 05:21 AM.
Reply With Quote

Reply



futures io > > > > > Swing in a Strategy

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
Automated Simple Swing Forex Strategy diverdan The Elite Circle 39 July 1st, 2011 01:47 AM
Swing/Pivot Points trs3042 Traders Hideout 3 November 28th, 2010 10:58 PM
How to use Price Action Swing? eone Traders Hideout 2 May 31st, 2010 12:16 AM
Swing HiLo with Extensions DavidHP NinjaTrader Programming 6 May 18th, 2010 09:18 PM
Chart for swing trade emini_Holy_Grail Traders Hideout 6 January 3rd, 2010 04:44 PM


All times are GMT -4. The time now is 06:05 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-12 in 0.14 seconds with 20 queries on phoenix via your IP 54.167.44.32