Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Trading Time management - issues

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

    Trading Time management - issues

    Dear Sir or Madam,

    I want to inform you that I am trying to add active and inactive period of my strategy.
    The issue is that somehow the strategy does not respond to the basic drawing tool at cetain time.

    Code:
    
                        if (ToTime(Time[0]) == StartingTime)
                        {
                            DrawText("StartingTime" + CurrentBar, "StartingTime", 0, High[0] + 5 * TickSize, Color.LimeGreen);
                            DrawVerticalLine("StartingTime", 0, Color.LimeGreen, DashStyle.DashDot, 2);
                        }
                        if (ToTime(Time[0]) == EndingTime)
                        {
                            DrawText("EndingTime" + CurrentBar, " EndingTime", 0, High[0] + 5 * TickSize, Color.OrangeRed);
                            DrawVerticalLine("EndingTime", 0, Color.Red, DashStyle.DashDot, 2);
                        }
      if (ToTime(Time[0]) == BeforeNews)
                        {
                            DrawText("BeforeNews" + CurrentBar, " EndingTime", 0, High[0] + 5 * TickSize, Color.OrangeRed);
                            DrawVerticalLine("BeforeNews", 0, Color.Red, DashStyle.DashDot, 2);
                        }
    I mean before writting you I tried every alternative.
    I tried onlytwo lines. just starting time and ending time. it gave the same results it draws only one vertical line with its text. and ignore the second one.
    I tried to change StartingTime with the number 130000 and EndingTime with 225000
    didn't work & gave same result (1 part executed)

    I actually tried to call to use intervals with bools activetradingtime =true/false;
    the issue is that the strategy doesn't draw more than one simple line at a specific time. and totally does not execute the intervals logic
    Summary : I need to draw 4 lines and create two intervals. Starting/beforeNews, AfterNews/Ending

    Please, tell me what went wrong with my logic. I think I will be able to debug it myself if I understand the real issue here.

    Thank you.
    Last edited by Yassine.Chetouani; 08-08-2017, 05:39 AM.

    #2
    Hello Yassine.Chetouani,

    Thanks for your post.

    The DrawVerticalLine statement would only show one vertical line for each statement as each time is hit because you are using the same tagname each time the lines are drawn. Just like your DrawText(), you can add +CurrentBar to the tag name to create unique tagnames. This would allow you to see historically all the previous lines.

    Your time statements appear correct however you are testing for a very specific time and if you are not using time-based bars it is possible that a tick may not occur at a specific time thus your time conditions may or may not be met.

    A work around for this is to use a time range and a bool variable, for example:

    if (ToTime(Time[0]) >= 100000 && ToTime(Time[0]) <= 100100 && doitonce)
    {
    DrawText("StartingTime" + CurrentBar, "StartingTime", 0, High[0] + 5 * TickSize, Color.LimeGreen);
    DrawVerticalLine("StartingTime", 0, Color.LimeGreen, DashStyle.DashDot, 2);
    doitonce = false; // set bool false to prevent additional lines/text
    }


    The above example looks for the end bar time to be between 10:00 and 10:01 so a full minute. The bool doitonce would need to be previously set to true and when the time condition becomes true any time in the time range of 10:00 to 10:01, the statements are executed and the bool is set false to prevent execution again. Note that you would need to set up another condition to reset the bool to true. Depending on what your times are, one way you can do this is to test for a new session by:

    if (Bars.FirstBarOfSession)
    {
    doitonce = true; // enable the bool for checking time condition in the new session
    }
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Dear Mr. Paul,

      By this message, I want to inform you that I succeeded to Draw the lines and Text after several attempts. As you told I figured that I am not using time-based bars and there are bars that takes 10 mins +, so even 1 mins didn't draw some lines. So I increased the interval

      if (ToTime(Time[0]) >= 100000 && ToTime(Time[0]) <= 101000 && doitonce)
      and later desactivate the doitonce bool
      It was complicated first but I solved it later with your instructions...
      So, Thank you again.
      Yassine

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by jaybedreamin, Today, 05:56 PM
      0 responses
      3 views
      0 likes
      Last Post jaybedreamin  
      Started by DJ888, 04-16-2024, 06:09 PM
      6 responses
      18 views
      0 likes
      Last Post DJ888
      by DJ888
       
      Started by Jon17, Today, 04:33 PM
      0 responses
      1 view
      0 likes
      Last Post Jon17
      by Jon17
       
      Started by Javierw.ok, Today, 04:12 PM
      0 responses
      6 views
      0 likes
      Last Post Javierw.ok  
      Started by timmbbo, Today, 08:59 AM
      2 responses
      10 views
      0 likes
      Last Post bltdavid  
      Working...
      X