NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 05-27-2011, 11:36 AM   #1
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default Resetting the Swing High/Low Indicator on New Session

Time for my daily post on here.....

I have a problem where it seems a signal is being triggered early in a session by reference to the swing high or low of a previous session if one hasn't formed yet during this session.

Does anyone have any ideas how I can address this?

Thanks

Mark
MJUK10 is offline  
Reply With Quote
Old 05-27-2011, 11:47 AM   #2
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Hi Mark,

Using Swing as a condition for entry will generally be challenging for this reason. When you're looking at historical swing values, these are actually generated by future values, causing a discrepancy with what you see on the chart compared to what is available programatically. You may get better results basing trade conditions on indicators that only have a historical lookback, rather than repainting ones like swing.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 05-30-2011, 07:36 AM   #3
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

Hi Ryan

I have not explained it clearly enough.

I'm not using the swing indicator for entry it is used for exit.

What is happening however is when a trade is entered into (short for example), if the price is higher than the last swing high (which was last session) it sends a signal to exit the trade. As it happens the exact same time as the entry, the trade does not exit but i'm just concerned that in theory it could.

Is there anyway round this?
MJUK10 is offline  
Reply With Quote
Old 05-30-2011, 08:33 AM   #4
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

Mark, I believe you could use the High and Low bar methods of the Swing indicator here as workaround to check to how long back this Swing point was found and then not submit the exit if it's one from the prior day / session.
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 05-30-2011, 08:52 AM   #5
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

Could you write a brief example please Bertard?

Many thanks

Mark
MJUK10 is offline  
Reply With Quote
Old 05-30-2011, 08:55 AM   #6
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,411
Thanks: 252
Thanked 976 times in 959 posts
Default

I would unfortunately not have a code snippet handy, but the methods you would need to work with are shown here - http://www.ninjatrader.com/support/h.../nt7/swing.htm
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 06-04-2011, 04:26 AM   #7
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

I'm still having problems with this unfortunately.



I entered into a trade yesterday. At 99.40 on the CL contract. A swing low exit was triggered straight away despite the swing low being aproximately $1 below.

The output log is as follows:

Quote:

03/06/2011 14:51:00 Entered internal PlaceOrder() method at 03/06/2011 14:51:00: BarsInProgress=0 Action=Buy OrderType=Market Quantity=5 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
03/06/2011 14:51:00 Entered internal SetStopTarget() method: Type=Stop FromEntrySignal='' Mode=Ticks Value=0 Currency=2125 Simulated=False
03/06/2011 14:51:00 Entered internal SetStopTarget() method: Type=Target FromEntrySignal='' Mode=Ticks Value=0 Currency=12500 Simulated=False
03/06/2011 14:52:00 Aup Entry


03/06/2011 14:51:00 Entered internal PlaceOrder() method at 03/06/2011 14:51:00: BarsInProgress=0 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
03/06/2011 14:51:00 Ignored PlaceOrder() method: Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
03/06/2011 14:52:00 Exit Long Swing

03/06/2011 14:51:00 Entered internal PlaceOrder() method at 03/06/2011 14:51:00: BarsInProgress=0 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
03/06/2011 14:51:00 Ignored PlaceOrder() method: Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
03/06/2011 14:52:00 Exit Long Swing

03/06/2011 14:51:00 Entered internal PlaceOrder() method at 03/06/2011 14:51:00: BarsInProgress=0 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
03/06/2011 14:51:00 Ignored PlaceOrder() method: Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal='' Reason='This was an exit order but no position exists to exit'
03/06/2011 14:52:00 Exit Long Swing

**NT** Stop/target handling for strategy 'ACD' set to 'ByStrategyPosition' since currency based stop order was placed.
03/06/2011 14:51:01 Amended stop order: Order='90cf29ad52cb402e8a98537052bd963a/U653374' Name='Stop loss' State=PendingSubmit Instrument='CL 07-11' Action=Sell Limit price=0 Stop price=98.93 Quantity=2 Strategy='ACD' Type=Stop Tif=Gtc Oco='CL 07-11/0000e9a5.4de838b7.01.01-20' Filled=0 Fill price=0 Token='5fa008d2380a4f27b5f040955d41f9b1' Gtd='01/12/2099 00:00:00'
03/06/2011 14:51:01 Amended target order: Order='f5a86c45e13242e18d81fbd98c9af4d8/U653374' Name='Profit target' State=PendingSubmit Instrument='CL 07-11' Action=Sell Limit price=101.85 Stop price=0 Quantity=2 Strategy='ACD' Type=Limit Tif=Gtc Oco='CL 07-11/0000e9a5.4de838b7.01.01-20' Filled=0 Fill price=0 Token='a18d23bb67b3453d9e3980f0ab65ac47' Gtd='01/12/2099 00:00:00'
03/06/2011 14:51:01 Amended stop order: Order='90cf29ad52cb402e8a98537052bd963a/U653374' Name='Stop loss' State=PendingSubmit Instrument='CL 07-11' Action=Sell Limit price=0 Stop price=98.92 Quantity=3 Strategy='ACD' Type=Stop Tif=Gtc Oco='CL 07-11/0000e9a5.4de838b7.01.01-20' Filled=0 Fill price=0 Token='5fa008d2380a4f27b5f040955d41f9b1' Gtd='01/12/2099 00:00:00'
03/06/2011 14:51:01 Amended target order: Order='f5a86c45e13242e18d81fbd98c9af4d8/U653374' Name='Profit target' State=PendingSubmit Instrument='CL 07-11' Action=Sell Limit price=101.85 Stop price=0 Quantity=3 Strategy='ACD' Type=Limit Tif=Gtc Oco='CL 07-11/0000e9a5.4de838b7.01.01-20' Filled=0 Fill price=0 Token='a18d23bb67b3453d9e3980f0ab65ac47' Gtd='01/12/2099 00:00:00'
03/06/2011 14:51:01 Amended stop order: Order='90cf29ad52cb402e8a98537052bd963a/U653374' Name='Stop loss' State=PendingSubmit Instrument='CL 07-11' Action=Sell Limit price=0 Stop price=98.93 Quantity=4 Strategy='ACD' Type=Stop Tif=Gtc Oco='CL 07-11/0000e9a5.4de838b7.01.01-20' Filled=0 Fill price=0 Token='5fa008d2380a4f27b5f040955d41f9b1' Gtd='01/12/2099 00:00:00'
03/06/2011 14:51:01 Amended target order: Order='f5a86c45e13242e18d81fbd98c9af4d8/U653374' Name='Profit target' State=PendingSubmit Instrument='CL 07-11' Action=Sell Limit price=101.85 Stop price=0 Quantity=4 Strategy='ACD' Type=Limit Tif=Gtc Oco='CL 07-11/0000e9a5.4de838b7.01.01-20' Filled=0 Fill price=0 Token='a18d23bb67b3453d9e3980f0ab65ac47' Gtd='01/12/2099 00:00:00'
03/06/2011 14:51:01 Amended stop order: Order='90cf29ad52cb402e8a98537052bd963a/U653374' Name='Stop loss' State=PendingSubmit Instrument='CL 07-11' Action=Sell Limit price=0 Stop price=98.93 Quantity=5 Strategy='ACD' Type=Stop Tif=Gtc Oco='CL 07-11/0000e9a5.4de838b7.01.01-20' Filled=0 Fill price=0 Token='5fa008d2380a4f27b5f040955d41f9b1' Gtd='01/12/2099 00:00:00'
03/06/2011 14:51:01 Amended target order: Order='f5a86c45e13242e18d81fbd98c9af4d8/U653374' Name='Profit target' State=PendingSubmit Instrument='CL 07-11' Action=Sell Limit price=101.85 Stop price=0 Quantity=5 Strategy='ACD' Type=Limit Tif=Gtc Oco='CL 07-11/0000e9a5.4de838b7.01.01-20' Filled=0 Fill price=0 Token='a18d23bb67b3453d9e3980f0ab65ac47' Gtd='01/12/2099 00:00:00'
03/06/2011 14:51:01 Entered internal PlaceOrder() method at 03/06/2011 14:51:01: BarsInProgress=0 Action=Sell OrderType=Market Quantity=0 LimitPrice=0 StopPrice=0 SignalName='' FromEntrySignal=''
03/06/2011 14:52:00 Exit Long Swing
The relevant code is as follows:

Code:
      

if (GetCurrentAsk() < Swing(5).SwingLow[0] - (OffsetS * TickSize)
                && Avalue == 1)
                
            {
            ExitLong();
                Print("Exit Long Swing Low exit");
            }
Obviously the swing values are higher that they should be. How can I track/print the SwingLow value maybe on each new bar?

Thanks

Mark



MJUK10 is offline  
Reply With Quote
Old 06-06-2011, 05:50 AM   #8
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

Can anyone help with this please?
MJUK10 is offline  
Reply With Quote
Old 06-06-2011, 08:25 AM   #9
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

Whether you're using swing as conditions for entry or exit is pretty much the same. The value accessed programatically varies from what you see visually, as discussed earlier. You should generally not use swing in automated strategies.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 06-06-2011, 10:37 AM   #10
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_RyanM View Post
Whether you're using swing as conditions for entry or exit is pretty much the same. The value accessed programatically varies from what you see visually, as discussed earlier. You should generally not use swing in automated strategies.
Understand what you are saying Ryan but whether it differs from whats shown on the chart is irrelevant really.

Using the swing indicator is a key part of my strategy. Without it, I don;t have a strategy and therefore the need to continue paying your subscription.

It works fine when back tested (irrespective of if it differs from the charts). I need to know how it is working during live trading and therefore need to print the SwingLow and SwingHigh values to the output window. To see what is going on. How can I do this at regular intervals say on the start of a new bar. (bear in mind I have the strategy set up as CalculateOnBarClose = False)

Many thanks

Mark
MJUK10 is offline  
Reply With Quote
Old 06-06-2011, 11:25 AM   #11
NinjaTrader_RyanM
NinjaTrader Customer Service
 
NinjaTrader_RyanM's Avatar
 
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
Default

You can Print the current value of Swing highs and lows. If you want to check on the start of a bar you can use FirstTickOfBar when using COBC = false.
http://www.ninjatrader.com/support/h...ttickofbar.htm

if (FirstTickOfBar)
Print(Swing(3).SwingHigh[0]);

When you look at the same bar historically it will not necessarily be the same value. This indicator works great when you backtest because it has a forward bias.
NinjaTrader_RyanM is offline  
Reply With Quote
Old 06-06-2011, 11:37 AM   #12
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

Quote:
Originally Posted by NinjaTrader_RyanM View Post
You can Print the current value of Swing highs and lows. If you want to check on the start of a bar you can use FirstTickOfBar when using COBC = false.
http://www.ninjatrader.com/support/h...ttickofbar.htm

if (FirstTickOfBar)
Print(Swing(3).SwingHigh[0]);

When you look at the same bar historically it will not necessarily be the same value. This indicator works great when you backtest because it has a forward bias.
Great thanks.

Strangly it has worked fine today when traded using the sim account.
MJUK10 is offline  
Reply With Quote
Old 06-06-2011, 12:01 PM   #13
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

Ryan - problem identified straight away!

According to the chart - the first SwingHigh of the session occured at 14.27 (GMT) at a high of $100.04. the first SwingLow at 14.02 (GMT) at $99.02.

These values are still showing up in the following (at 19.00 GMT):

Code:
 
Print(Swing(10).SwingHigh[0]); and 
Print(Swing(10).SwingLow[0]);
So essentially all the succeeding SwingHigh and SwingLows have not updated from the original values. Do you have any idea why this might be?

Thanks




MJUK10 is offline  
Reply With Quote
Old 06-06-2011, 12:22 PM   #14
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

The values has just changed @ 19.22 (GMT) to the second SwingHigh/Low which occured about 15.00 (GMT).
MJUK10 is offline  
Reply With Quote
Old 06-06-2011, 12:23 PM   #15
MJUK10
Senior Member
 
Join Date: Dec 2009
Posts: 102
Thanks: 4
Thanked 0 times in 0 posts
Default

According to the chart there about 8 Swing Highs and Lows after this...
MJUK10 is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Swing High / Low Indicator lawyse Indicator Development 1 12-03-2009 11:33 AM
Modify Swing High/Low Indicator yimbot Indicator Development 5 12-30-2008 06:16 AM
How to use Swing(High/Low) indicator cassb Strategy Analyzer 5 03-05-2008 10:56 PM
Swing high low indicator winJR NinjaScript File Sharing Discussion 1 02-06-2008 12:39 AM
Swing Low/High indicator ts888 Indicator Development 10 07-12-2007 07:56 AM


All times are GMT -6. The time now is 01:47 PM.