NinjaTrader scripting language: last month's friday - NinjaTrader | futures io social day trading
futures io futures trading


NinjaTrader scripting language: last month's friday
Updated: Views / Replies:1,007 / 4
Created: by Astrogirl Attachments:0

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

NinjaTrader scripting language: last month's friday

  #1 (permalink)
Trading for Fun
Milan/Italy
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES, YM, NQ, FDAX
 
Astrogirl's Avatar
 
Posts: 51 since Oct 2013
Thanks: 25 given, 7 received

NinjaTrader scripting language: last month's friday

An hard question about ninjascript. How can I translate, in NinjaTrader code, the following condition:

If it is the last Friday of each month, enter long position.

I really appreciate any help.


Last edited by Astrogirl; August 3rd, 2015 at 01:29 PM.
Reply With Quote
 
  #2 (permalink)
Elite Member
Pune India
 
Futures Experience: Beginner
Platform: NinjaTrader
Favorite Futures: Stocks
 
Elite Trader's Avatar
 
Posts: 28 since Apr 2015
Thanks: 56 given, 14 received


Astrogirl View Post
An hard question about ninjascript; how can I translate in code the following condition:

If it is the last friday of any month, enter long position.

I really appreciate any help.

Hi Astrogirl,

For this condition you can write a method to check every last friday's date of the month.

Example : 08/28/2015 this date is the last friday of this month and 09/25/2015 is the last friday of the next month, In this way you can add the date of the last fridays of the month for the one year two years and so on....

public bool CheckLastFriday(DateTime barTime)
{
if ( ToDay(barTime) == 20150828 || ToDay(barTime) == 20150925 || ......)
{

return true;

}
else
{
return false;
}
}


if ( CheckLastFriday(Time[0]) == true )
{

EnterLong();

}



Elite Trader.

Reply With Quote
 
  #3 (permalink)
 Vendor: www.probabletrades.com 
OC, California, USA
 
Futures Experience: Advanced
Platform: IB/TWS, NinjaTrader, thinkorswim
Favorite Futures: stocks, options, futures, VIX
 
shodson's Avatar
 
Posts: 1,860 since Jun 2009
Thanks: 480 given, 3,255 received

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


Assumes you are running on daily bars. Enters at the open of the last Friday of the month, exits the next Monday morning.

 
Code
protected override void OnBarUpdate()
{
	DateTime tomorrow = Time[0].Date.AddDays(1);
	
	// if tomorrow is a Friday...
	if (tomorrow.DayOfWeek == DayOfWeek.Friday)	
	{
		// if next week is not the same month as tomorrow, then tomorrow is the last friday of the month
		if (tomorrow.Month != tomorrow.AddDays(7).Month)
			EnterLong();
	}
	// if long, exit
	else if (Position.MarketPosition == MarketPosition.Long)
		ExitLong();
}


Last edited by shodson; August 3rd, 2015 at 09:01 PM.
Reply With Quote
The following 4 users say Thank You to shodson for this post:
 
  #4 (permalink)
Trading for Fun
Milan/Italy
 
Futures Experience: Intermediate
Platform: NinjaTrader
Favorite Futures: ES, YM, NQ, FDAX
 
Astrogirl's Avatar
 
Posts: 51 since Oct 2013
Thanks: 25 given, 7 received


Elite Trader View Post
Hi Astrogirl,

For this condition you can write a method to check every last friday's date of the month.

Example : 08/28/2015 this date is the last friday of this month and 09/25/2015 is the last friday of the next month, In this way you can add the date of the last fridays of the month for the one year two years and so on....


Elite Trader.

Thanks Elite Trader, your help is very useful. However I would need to find a logic that allow me to avoid entering each single Friday manually in the code as my script works on several years!


Last edited by Astrogirl; August 3rd, 2015 at 01:20 PM.
Reply With Quote
 
  #5 (permalink)
Administrator: Retired Backtester
 Vendor: speedytradingservers.com 
Rennes France
 
Futures Experience: Advanced
Platform: NinjaTrader
Broker/Data: IB/Kinetick
Favorite Futures: Futures
 
sam028's Avatar
 
Posts: 3,366 since Jun 2009
Thanks: 3,574 given, 3,983 received


Astrogirl View Post
Thanks Elite Trader, your help is very useful. However I would need to find a logic that allow me to avoid entering each single Friday manually in the code as my script works on several years!

Check @shodson reply, he gives the right piece of code for the next billion years.

Success requires no deodorant! (Sun Tzu)
Reply With Quote

Reply



futures io > > > > NinjaTrader scripting language: last month's friday

Thread Tools Search this Thread
Search this Thread:

Advanced Search



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

Jigsaw Trading: TBA

Elite only

FuturesTrader71: TBA

Elite only

NinjaTrader: TBA

Jan 18

RandBots: TBA

Jan 23

GFF Brokers & CME Group: Futures & Bitcoin

Elite only

Adam Grimes: TBA

Elite only

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scripting sell condition mtngoat ThinkOrSwim 1 June 26th, 2015 09:01 PM
Exit on friday - Backtest stops after first friday cago NinjaTrader Programming 10 May 2nd, 2015 07:46 PM
Need some help for c sharp scripting hugebaozi NinjaTrader Programming 1 July 9th, 2014 11:06 PM
Last winning/loosing trades: translate in NT scripting language Astrogirl NinjaTrader Programming 2 October 20th, 2013 10:14 AM
Ninjatrader 3-month license for sale PeterOhlson Off-Topic 5 June 27th, 2012 10:53 AM


All times are GMT -4. The time now is 04:52 AM.

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-18 in 0.12 seconds with 29 queries on phoenix via your IP 23.22.136.56