NexusFi: Find Your Edge


Home Menu

 





Certain times excluded from trading


Discussion in NinjaTrader

Updated
      Top Posters
    1. looks_one vast with 4 posts (0 thanks)
    2. looks_two Big Mike with 4 posts (0 thanks)
    3. looks_3 shodson with 1 posts (3 thanks)
    4. looks_4 piersh with 1 posts (0 thanks)
    1. trending_up 5,621 views
    2. thumb_up 3 thanks given
    3. group 3 followers
    1. forum 10 posts
    2. attach_file 0 attachments




 
Search this Thread

Certain times excluded from trading

  #1 (permalink)
 
vast's Avatar
 vast 
Australia
 
Experience: Intermediate
Platform: Ninja
Posts: 167 since Jun 2009
Thanks Given: 154
Thanks Received: 62

I am in need again of help. Sorry
I am trying to blank out certain times that I want the strategy to ignore.
The code seems to be ok, but it isn't enforcing it. I have debugged it and the sessions are correct, but for some reason it is not enforcing it on the condition set.
Is there a way of enforcing an open position to exit at 30sec before the session time? I found something on the NInja chat, but couldn't get it to work either.
Any ideas please?

{
// Condition set 1



if (ToTime(Time[0]) >= 083000 && ToTime(Time[0]) < 085700 || (ToTime(Time[0]) >= 090200 && ToTime(Time[0]) <= 092800 ||
(ToTime(Time[0]) >= 093200 && ToTime(Time[0]) < 095800 || (ToTime(Time[0]) >= 100200 && ToTime(Time[0]) <= 102800 ||
(ToTime(Time[0]) >= 103200 && ToTime(Time[0]) < 105800 || (ToTime(Time[0]) >= 110200 && ToTime(Time[0]) <= 115800 ||
(ToTime(Time[0]) >= 120200 && ToTime(Time[0]) <= 125800)))))))
DrawVerticalLine("tag1"+CurrentBar,0,Color.Blue,DashStyle.Dot,3);

{
if (CrossAbove(ECO2NEW(7, 5, 21).Main, EMA(7, 5, 21).Signal, 1)
&& Close[0] > EMA(144)[0]
&& HMA2[0] > HMA2[1]);
{
EnterLong(DefaultQuantity, "LongCross");
}
}

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
PowerLanguage & EasyLanguage. How to get the platfor …
EasyLanguage Programming
Trade idea based off three indicators.
Traders Hideout
REcommedations for programming help
Sierra Chart
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Tao te Trade: way of the WLD
24 thanks
Just another trading journal: PA, Wyckoff & Trends
24 thanks
Bigger Wins or Fewer Losses?
21 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #2 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,603

I like to write my code so it's easy to follow. I suggest doing that and taking it one step at a time to find the logic error.

 
Code
                            
// do not trade before 4:30am or after 2:30pm
if (ToTime(Time[0]) <= 043000 || ToTime(Time[0]) >= 143000)
return;

// do not trade between 11:30am and 12:30pm
if (ToTime(Time[0]) >= 113000 && ToTime(Time[0]) <= 123000)
return;

// do not trade on Wednesday between 9:25am and 10:15am
if (Time[0].DayOfWeek == DayOfWeek.Friday)
  if (
ToTime(Time[0]) >= 092500 && ToTime(Time[0]) <= 101500)
     return; 
Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #3 (permalink)
 MXASJ 
Asia
 
Experience: Beginner
Platform: NinjaTrader, TOS
Posts: 796 since Jun 2009
Thanks Given: 109
Thanks Received: 800


ToTime works on your PC time, right?

Reply With Quote
  #4 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,603


MXASJ View Post
ToTime works on your PC time, right?

ToTime is just a converter to make it easy to test against using a numbers like 080000 for 08:00:00am (hours:minutes:seconds).

Time[0] is the time of bar 0. So it works for historical data (backtesting) as it's tested against the bar time, not against the current PC clock time. In other words, in real live trading, Time[0] will be based on the time of the last close of the bar, and it's the same for historical.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #5 (permalink)
 
vast's Avatar
 vast 
Australia
 
Experience: Intermediate
Platform: Ninja
Posts: 167 since Jun 2009
Thanks Given: 154
Thanks Received: 62

Hi Mike
Thanks for the guide. I should do this as it tells me what my code is talking about.
My times seem to be valid. I run the script and the "draw vert lines after the time code draws the lines in all the correct places. What doesn't seem to be happening is the enforcing of it, to the place a trade signal. ie, trades are still being taken in times that I have deemed to be out of bounds.
Any ideas?

Started this thread Reply With Quote
  #6 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,603


vast View Post
Hi Mike
Thanks for the guide. I should do this as it tells me what my code is talking about.
My times seem to be valid. I run the script and the "draw vert lines after the time code draws the lines in all the correct places. What doesn't seem to be happening is the enforcing of it, to the place a trade signal. ie, trades are still being taken in times that I have deemed to be out of bounds.
Any ideas?

You have no code telling it not to trade in these times... your code simply draws a plot...

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #7 (permalink)
 
vast's Avatar
 vast 
Australia
 
Experience: Intermediate
Platform: Ninja
Posts: 167 since Jun 2009
Thanks Given: 154
Thanks Received: 62

Ok. Well I am giving up.
I thought that using the totime sets the parameters and that the trade entry requirements after it will only execute if the totime parameters are met.
Just goes to show how much I understand C# and the Ninja guides.
Oh well. Another idea wasted. I am wasting so much time trying to get a strategy to work.
I am better to go back to my old ways of manually backtesting. I realise that this is a backwards move, but the wizard and Ninja guides are frustrating me.
Thanks Mike for trying to help.

Started this thread Reply With Quote
  #8 (permalink)
 
Big Mike's Avatar
 Big Mike 
Manta, Ecuador
Site Administrator
Developer
Swing Trader
 
Experience: Advanced
Platform: Custom solution
Broker: IBKR
Trading: Stocks & Futures
Frequency: Every few days
Duration: Weeks
Posts: 50,442 since Jun 2009
Thanks Given: 33,215
Thanks Received: 101,603


vast View Post
Ok. Well I am giving up.
I thought that using the totime sets the parameters and that the trade entry requirements after it will only execute if the totime parameters are met.
Just goes to show how much I understand C# and the Ninja guides.
Oh well. Another idea wasted. I am wasting so much time trying to get a strategy to work.
I am better to go back to my old ways of manually backtesting. I realise that this is a backwards move, but the wizard and Ninja guides are frustrating me.
Thanks Mike for trying to help.

Backtesting can be the wrong path. I've blogged about that.

But, if you are giving up because of ToTime() then you are 99.9% there, in this post I already provided an example specifically showing how not to trade. It's called "return;". You can { Drawyourlines(); return; } and that will prevent the script from continuing further and thereby not executing your Enter() command.

Mike

We're here to help: just ask the community or contact our Help Desk

Quick Links: Change your Username or Register as a Vendor
Searching for trading reviews? Review this list
Lifetime Elite Membership: Sign-up for only $149 USD
Exclusive money saving offers from our Site Sponsors: Browse Offers
Report problems with the site: Using the NexusFi changelog thread
Follow me on Twitter Visit my NexusFi Trade Journal Reply With Quote
  #9 (permalink)
 
vast's Avatar
 vast 
Australia
 
Experience: Intermediate
Platform: Ninja
Posts: 167 since Jun 2009
Thanks Given: 154
Thanks Received: 62

Thank you Mike. I can't believe that all my problem was a "return;" missing. Aghhh

I promise that I will no longer look at C# programming
I promise that I will no longer look at C# programming
I promise that I will no longer look at C# programming
I promise that I will no longer look at C# programming

Started this thread Reply With Quote
  #10 (permalink)
piersh
California
 
Posts: 87 since Jun 2009
Thanks Given: 5
Thanks Received: 120



Big Mike View Post
ToTime is just a converter to make it easy to test against using a numbers like 080000 for 08:00:00am (hours:minutes:seconds).

Time[0] is the time of bar 0. So it works for historical data (backtesting) as it's tested against the bar time, not against the current PC clock time. In other words, in real live trading, Time[0] will be based on the time of the last close of the bar, and it's the same for historical.

Mike

You can also use DateTime.TimeOfDay:

DateTime timeNow = Time[0].TimeOfDay;
TimeSpan timeStart = new TimeSpan (4,30,0);
TimeSpan timeEnd = new TimeSpan (14,30,0);
if (timeNow <= timeStart || timeNow >= timeEnd)
....

Reply With Quote




Last Updated on August 7, 2009


© 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