Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

How to make a strategy stay in for more than 24 hours?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    How to make a strategy stay in for more than 24 hours?

    By default, the strategy analyzer has the session begin/end at 12:00 AM, giving it a theoretical maximum lifespan of 24 hours. To allow more than 24 hours, I have "ExitOnClose" to false, but then it will not exit when I close the strategy or on the weekends. I would like my strategies have the ability to stay in 24 hours a day but still exit on the weekends and if I stop the strategy. How can I program this?

    Thank you,
    - Daniel

    #2
    it is best to leave the session times to 24 hgours 7 days - inside the strategy you can test the time and date of the bar - if it is within your date range eg. mon 8am to fri 16:00pm then process else go flat do not process...

    you will need some parameters such as

    sesssionStartHour = 8
    sesssionStartMinute =0
    sesssionEndHour = 16
    sesssionEndMinute =0
    weekends=0

    means trade only within 08 to 16 weekdays

    and a method to call on barupdate


    privatebool InValidSession()
    {
    //Print("InValidSession");
    bool result = true;
    try
    {
    if ((Weekends == 0) && (Time[0].DayOfWeek == DayOfWeek.Saturday || Time[0].DayOfWeek == DayOfWeek.Sunday))
    {
    result =
    false;
    }
    int TimeNow = ToTime(Time[0].Hour, Time[0].Minute, Time[0].Second);
    if (result && sessionMode == 1)
    {
    timeStart = ToTime(sessionStartHour, sessionStartMinute,
    0);
    timeEnd = ToTime(sessionEndHour, sessionEndMinute,
    0);
    result = (TimeNow >= timeStart) && (TimeNow <= timeEnd);
    }

    }
    catch (Exception ex)
    {
    result = false;
    Log(ex.ToString(), LogLevel.Error);
    }
     
    return result;
    }


    protectedoverridevoid OnBarUpdate()
    {

    canTrade=InValidSession()
     
     
    if (!canTrade) return;


    }
    MicroTrends
    NinjaTrader Ecosystem Vendor - micro-trends.co.uk

    Comment


      #3
      Thank you very much, that was most helpful. :-)

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by lightsun47, Today, 03:51 PM
      0 responses
      5 views
      0 likes
      Last Post lightsun47  
      Started by 00nevest, Today, 02:27 PM
      1 response
      9 views
      0 likes
      Last Post 00nevest  
      Started by futtrader, 04-21-2024, 01:50 AM
      4 responses
      45 views
      0 likes
      Last Post futtrader  
      Started by Option Whisperer, Today, 09:55 AM
      1 response
      14 views
      0 likes
      Last Post bltdavid  
      Started by port119, Today, 02:43 PM
      0 responses
      9 views
      0 likes
      Last Post port119
      by port119
       
      Working...
      X