• 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

sessionBegin/End condition logic

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

  • Taddypole
    started a topic sessionBegin/End condition logic

    sessionBegin/End condition logic

    I'm trying to start an indicator if the current time is within the current session but having problems.

    I'm using:


    dateTag = DateTime.Now.Date.Month.ToString("00") + DateTime.Now.Date.Day.ToString("00");

    if(dateTag == sessionBegin.Month.ToString() + sessionBegin.Day.ToString())
    {
    runRealTime = true;
    Print("VolumeUpDownOne" + " runRealTime " + runRealTime );
    }

    but this logic never turns true. The code compiles, runs normally and produces no error in the Ninja Trader log.

    What am I doing wrong?

    regards,
    taddypole...

  • Taddypole
    replied
    Cal,

    Thank you for the help.

    Here is the solution: (Its a combination of both "if" statements)

    if (DateTime.Now > sessionBegin && DateTime.Now < sessionEnd)
    {
    if(Time[0] > sessionBegin.AddHours(1) && Time[0] < sessionEnd)
    {
    CurrentSession = true;
    }
    }

    Leave a comment:


  • NinjaTrader_CalH
    replied
    TaddyPole,

    You would want to use Time[0] instead of DateTime.Now as this would never be true.

    Aditionally, you need to reset the CurrentSession bool otherwise once its set it will always be true.
    Code:
    CurrentSession = false;
    if(Time[0] > sessionBegin.AddHours(1) && Time[0] < sessionEnd)
         {     CurrentSession = true;     }

    Leave a comment:


  • Taddypole
    replied
    I'm trying to modify the VolumeUpDown indicator by not plotting the volume bars for some period of time after sessionBegin.

    I'm using: sessionBegin.AddHour(1)

    But for some reason this is not working. It is still plotting the bars.

    Code and picture attached.

    Can someone tell me what I'm doing wrong?

    regards,

    taddypole...
    Attached Files
    Last edited by Taddypole; 01-15-2015, 01:13 PM.

    Leave a comment:


  • Taddypole
    replied
    Thank you Chelsea,

    that's exactly what I was looking for. As you can see in the attachment, it is working!

    regards,
    taddypole...
    Attached Files

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hi Taddypole,

    That wasn't tested but was a general idea of what you would be looking for. Really the GetNextBeginTime returns a time without date which causes the GetBar to be incorrect.

    If you are using the DateTime.Now instead of the bar time, the following code is actually easier and I did test this to ensure it works.

    Code:
    private DateTime sessionBegin;
    private DateTime sessionEnd;
    
    protected override void OnBarUpdate()
    {
    Instrument.MasterInstrument.Session.GetNextBeginEnd(BarsArray[0], 0, out sessionBegin, out sessionEnd);
    if (DateTime.Now > sessionBegin && DateTime.Now < sessionEnd)
    {
    // execute code
    }
    Below is a link to the help guide on Bars.Session.GetNextBeginEnd().
    http://www.ninjatrader.com/support/h...xtbeginend.htm


    However, as I mentioned, the better way to go about this, is to reset a variable when there is a new session. Though I am just assuming that you are trying to reset an accumulation when there is a new session.
    Last edited by NinjaTrader_ChelseaB; 12-31-2014, 01:47 PM.

    Leave a comment:


  • Taddypole
    replied
    I tried your suggestion which seems like it might work but I'm getting indexing errors as highlighted in the "Code" attachment.

    I increased the number of bars before starting calculations to 500 and still get the indexing error.

    What else might i need?

    thank you,
    taddypole...
    Attached Files

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hi Taddypole,

    If you are accumulating data on each OnBarUpdate, you can reset your variable on the new session. This might be the easiest way.

    If (FirstBarOfSession)
    {
    myVariable = 0;
    }


    However, this does not quite answer the question.
    Are you using the Default 24/7 session template?
    Are you only checking the current time and not the time of the bar?

    I ask because you probably want something like:
    if (DateTime.Now > Instrument.MasterInstrument.Session.NextBeginTime. AddDays(-1) && Time[CurrentBar-Bars.GetBar(Instrument.MasterInstrument.Session.Ne xtBeginTime.AddDays(-1))+1].Hour == Instrument.MasterInstrument.Session.NextBeginTime. AddDays(-1).Hour)

    This checks that the current time is after the beginning of the session, and that there is a session today.

    Leave a comment:


  • Taddypole
    replied
    Hi Chelsea,

    I'm using this logic in a volume indicator and don't want the previous day's volume to keep the scaling based on yesterday's volume. I want to start today's (this sessions) scaling fresh based on the current volume (usually low).

    So if I load the chart with a weeks worth of data, I don't want any historical volume data. Just start calculating volume at the beginning of the latest session.

    So the session settings are "use instrument settings".

    My thoughts are when a new session starts, I reload ninja script and use the code to determine when the new session started. If the new session is in progress, then calculate historical volume from the session begin time to Now and continue volume calculations as real time progresses.

    does this make sense?

    Leave a comment:


  • NinjaTrader_ChelseaB
    replied
    Hello Taddypole,

    I'm not quite sure what you are trying to find out.

    Your script will only evaluate if it is receiving data. It will only receive data if the current time is during the session.

    If you change the session on the chart, this changes the time of Bars.Session.NextBeginTime.

    Are you instead using the Default 24/7 template and want to find the session times of the instrument in the Instrument Manager?

    Leave a comment:

Latest Posts

Collapse

Topics Statistics Last Post
Started by Venom, Yesterday, 01:05 PM
1 response
19 views
0 likes
Last Post NinjaTrader_ChrisSch  
Started by thgamey, Today, 02:05 AM
2 responses
12 views
0 likes
Last Post thgamey
by thgamey
 
Started by yeshujbp, Yesterday, 02:40 PM
1 response
11 views
0 likes
Last Post NinjaTrader_PaulH  
Started by sardana, Today, 05:52 AM
1 response
4 views
0 likes
Last Post NinjaTrader_PaulH  
Started by Mykro, Yesterday, 04:58 PM
1 response
11 views
0 likes
Last Post NinjaTrader_PaulH  
Working...
X