NexusFi: Find Your Edge


Home Menu

 





A simple time based study


Discussion in EasyLanguage Programming

Updated
    1. trending_up 4,941 views
    2. thumb_up 5 thanks given
    3. group 4 followers
    1. forum 4 posts
    2. attach_file 0 attachments




 
Search this Thread

A simple time based study

  #1 (permalink)
 robz75 
baltimore md/usa
 
Experience: Beginner
Platform: TradeStation
Trading: Futures
Posts: 16 since Jul 2014
Thanks Given: 0
Thanks Received: 0

Does anyone have some simple code for this idea?


Looking to run a study on @es that looks to test a buy and sell signal based on time of day. So it would say after x time of day buy and then at x time of day sell.

Example would be at 0945 buy this bar close and at 1600 sell. Looking to test all times to buy up until 1600 so both the time to buy and then time to sell need to be optimizable.

Started this thread Reply With Quote

Can you help answer these questions
from other members on NexusFi?
MC PL editor upgrade
MultiCharts
Pivot Indicator like the old SwingTemp by Big Mike
NinjaTrader
REcommedations for programming help
Sierra Chart
Trade idea based off three indicators.
Traders Hideout
Exit Strategy
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Spoo-nalysis ES e-mini futures S&P 500
29 thanks
Just another trading journal: PA, Wyckoff & Trends
25 thanks
Tao te Trade: way of the WLD
24 thanks
Bigger Wins or Fewer Losses?
22 thanks
GFIs1 1 DAX trade per day journal
17 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,434 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627


robz75,

do you have some code written yourself already?
With time based inputs optimization can be more "problematic" as when you try to optimize from 930 to 1030 in steps of one, the optimizer would also test 961, 962 etc.. One way around that is to use minutes since midnight as an input for example. This might take some time to getting used to it, but it will avoid the issue with non-existing times.
This should get you started:
 
Code
Inputs:
StartTimeInMinutes(570),
EndTimeInMinutes(960);

Variables:
StartTime(0),
EndTime(0);

//convert minutes to time
once 
begin
StartTime = MinutesToTime( StartTimeInMinutes ) ;
EndTime = MinutesToTime( EndTimeInMinutes ) ;
end ;

if Time = StartTime and MarketPosition = 0 then 
//put your entry order here

if Time = EndTime and MarketPosition <> 0 then
//put your exit order here
Regards,
ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
 robz75 
baltimore md/usa
 
Experience: Beginner
Platform: TradeStation
Trading: Futures
Posts: 16 since Jul 2014
Thanks Given: 0
Thanks Received: 0

Thank you sir, yes I just finished it up and that was exactly the problem I was running into. Not sure how good the code is either. Was talking to some folks and they provided some code to use the computer time but it sill shows times like 960 990 etc when running the optimization. My code is below but let me give yours a shot. I like the idea of minutes much better! I put a trend filter on this one when I was testing. Only buy when price is above moving average.


Inputs:
THE_OPEN (0930),
THE_CLOSE (1600),
Price( Close),
RegimeLookback (50) ;

// define ALL your variables for storage.
Var: Min(0),TheOpen_Min(0), MA200 ( 0 );

Min = timetominutes(time);
TheOpen_Min = timetominutes(The_Open);
MA200 = Average(Close, RegimeLookback);


// The_Open to The_Close - 1 barinterval to allow a close before the market close's.
If min >= TheOpen_Min and Min <= timetominutes(calctime(THE_CLOSE,-barInterval)) and ( Close > MA200 ) Then
Buy next bar market;

Started this thread Reply With Quote
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,434 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

robz75,

you are welcome. My code is just something I put together here in the thread. One issue that could occur is that there is no bar with the time you are currently testing. That would obviously much more dangerous for the exit than for an entry. So it might make sense expand the code with two flags a bit to allow for those situations.

 
Code
Inputs:
StartTimeInMinutes(570),
EndTimeInMinutes(960);

Variables:
EntryAllowed(true),
ExitAllowed(true),
StartTime(0),
EndTime(0);

//convert minutes to time
once 
begin
StartTime = MinutesToTime( StartTimeInMinutes ) ;
EndTime = MinutesToTime( EndTimeInMinutes ) ;
end ;

//new day, reset flags
if Date <> Date[1] then
begin
EntryAllowed = true;
ExitAllowed = true;
end;

if Time >= StartTime and MarketPosition = 0 and EntryAllowed then 
begin
//put your entry order here
EntryAllowed = false;
end ;
if Time >= EndTime and MarketPosition <> 0 and ExitAllowed then
begin
//put your exit order here
ExitAllowed = false;
end;

Follow me on Twitter Reply With Quote
Thanked by:




Last Updated on February 25, 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