NexusFi: Find Your Edge


Home Menu

 





NinjaTrader scripting language: last month's friday


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one Astrogirl with 2 posts (0 thanks)
    2. looks_two shodson with 1 posts (4 thanks)
    3. looks_3 Elite Trader with 1 posts (0 thanks)
    4. looks_4 sam028 with 1 posts (0 thanks)
    1. trending_up 2,024 views
    2. thumb_up 4 thanks given
    3. group 4 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

NinjaTrader scripting language: last month's friday

  #1 (permalink)
Astrogirl
Milan/Italy
 
Posts: 51 since Oct 2013
Thanks Given: 25
Thanks Received: 12

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.

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
How to apply profiles
Traders Hideout
Better Renko Gaps
The Elite Circle
Trade idea based off three indicators.
Traders Hideout
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
MC PL editor upgrade
MultiCharts
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
31 thanks
Just another trading journal: PA, Wyckoff & Trends
26 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
23 thanks
GFIs1 1 DAX trade per day journal
18 thanks
  #2 (permalink)
 
Elite Trader's Avatar
 Elite Trader 
Pune India
 
Experience: Beginner
Platform: NinjaTrader
Trading: Stocks
Posts: 28 since Apr 2015
Thanks Given: 56
Thanks Received: 15


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)
 
shodson's Avatar
 shodson 
OC, California, USA
Quantoholic
 
Experience: Advanced
Platform: IB/TWS, NinjaTrader, ToS
Broker: IB, ToS, Kinetick
Trading: stocks, options, futures, VIX
Posts: 1,976 since Jun 2009
Thanks Given: 533
Thanks Received: 3,709


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();
}

Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #4 (permalink)
Astrogirl
Milan/Italy
 
Posts: 51 since Oct 2013
Thanks Given: 25
Thanks Received: 12


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!

Reply With Quote
  #5 (permalink)
 
sam028's Avatar
 sam028 
Site Moderator
 
Posts: 3,765 since Jun 2009
Thanks Given: 3,825
Thanks Received: 4,629


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)
Follow me on Twitter Reply With Quote




Last Updated on August 3, 2015


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
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.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts