• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

rectangle end time

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

  • brucelevy
    started a topic rectangle end time

    rectangle end time

    I want to draw a rectangle from 3am to 4am.

    I am currently using the following to draw a rectangle from 3am to 20 bars forward.

    if (ToTime(Time[0]) == 30000)
    {
    DrawRectangle("tag1"+CurrentBar, 0 ,Open[0], -20, Close[0], Color.PaleGreen);
    }



    I have tried this but nothing shows up on the chart...
    if (ToTime(Time[0]) == 30000)
    {
    DrawRectangle("tag1"+CurrentBar,true, 30000 ,Open[0], 40000, Close[0], Color.PaleGreen,Color.Red,5);
    }

  • brucelevy
    replied
    I was able to use the following to get rectangle start and end times. Thanks.

    //set the start and end time variables for the current day
    DateTime startTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 6, 45, 00);
    DateTime endTime = new DateTime(Time[0].Year, Time[0].Month, Time[0].Day, 6, 55, 00);

    //get the bar number for those time variables
    int startBar = GetBar(startTime);
    int endBar = GetBar(endTime);

    if (Time[0] >= startTime && Time[0] <= endTime)
    {
    DrawRectangle("tag", true, startBar, Low[LowestBar(Low, 10)], endBar, High[HighestBar(High, 10)], Color.Cyan, Color.Cyan, 1);
    }

    Leave a comment:


  • NinjaTrader_JessicaP
    replied
    I apologize, there was a bug in the sample I provided. This should work.

    Code:
    public static DateTime FromTime(int time)
    {
       return new DateTime (
                DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day,
                (time % 1000000) / 10000, (time % 10000) / 100, (time % 100) / 1
                );
    }
    I am going to leave the earlier, incorrect code up as it makes the meaning of the last 3 arguments clear.

    Leave a comment:


  • bltdavid
    replied
    Originally posted by NinjaTrader_JessicaP View Post
    Code:
    public static DateTime FromTime(int time)
    {
        DateTime outTime = new DateTime (
                DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day
                );
        outTime.Hour   = (time % 1000000) / 10000;
        outTime.Minute = (time % 10000)   / 100;
        outTime.second = (time % 100)     / 1;
        return outTime;
    }
    That lowercase 's' should probably be uppercase.

    Leave a comment:


  • bltdavid
    replied
    Originally posted by brucelevy View Post
    error says indexer date time hour minute second cannot be assigned - read only
    We can't see your screen.

    Simple answer: your code has an error, aka, you're doing something wrong.

    Want more help? Throw us a bone and post something more helpful.

    Please show us your code and/or post a screenshot of your error.
    Last edited by bltdavid; 09-23-2016, 08:46 AM.

    Leave a comment:


  • brucelevy
    replied
    error says indexer date time hour minute second cannot be assigned - read only

    Leave a comment:


  • NinjaTrader_JessicaP
    replied
    To clarify, if you would like to convert a ToTime() compatible time into a DateTime object, you can use this static method

    Code:
    public static DateTime FromTime(int time)
    {
        DateTime outTime = new DateTime (
                DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day
                );
        outTime.Hour   = (time % 1000000) / 10000;
        outTime.Minute = (time % 10000)   / 100;
        outTime.second = (time % 100)     / 1;
        return outTime;
    }

    Leave a comment:


  • bltdavid
    replied
    Originally posted by brucelevy View Post
    DrawRectangle("tag1"+CurrentBar,true, 30000 ,Open[0], 40000, Close[0], Color.PaleGreen,Color.Red,5);
    Because 30000 and 40000 are not DateTimes.

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by sergey_z, Today, 02:56 PM
1 response
9 views
0 likes
Last Post NinjaTrader_Jesse  
Started by samir, Today, 02:46 PM
1 response
13 views
0 likes
Last Post NinjaTrader_Kate  
Started by neoikon, Today, 02:24 PM
1 response
7 views
0 likes
Last Post NinjaTrader_ChristopherJ  
Started by XimoTrader, Today, 12:57 PM
1 response
12 views
0 likes
Last Post NinjaTrader_PatrickG  
Started by FxInception, Today, 12:27 PM
2 responses
14 views
0 likes
Last Post FxInception  
Working...
X