• 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

time limitations for automated strategies

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

  • NinjaTrader_JessicaP
    replied
    Hello rtwave,

    With NinjaScript, you accomplish this with conditional logic, usually if statements. OnBarUpdate is a "clock signal", meaning that it will trigger over and over again as time goes on. Every tick or bar has a unique time that it triggers. You can test every bar's trigger time to see if it is within a range, and only perform tasks if this test passes.

    I am including a link to the ToTime() section of the Help Guide.

    http://ninjatrader.com/support/helpG...-us/totime.htm

    I will also adapt its sample code to cover the three situations you mentioned.

    Code:
    // Only trade between 18:00 and 16:00 (so not between 16:00 and 18:00)
    if (! (ToTime(Time[0]) > 160000 && ToTime(Time[0]) < 180000))
    {
        if(MarketPosition == MarketPosition.Flat)
        {
            EnterLong();
        }
    }
    The first snippet done another way, as a more literal interpretation of what you were asking.

    Code:
    // Only trade between midnight and 16:00, or between 18:00 and midnight
    if (ToTime(Time[0]) <= 160000 || ToTime(Time[0]) >= 180000)
    {
        if(MarketPosition == MarketPosition.Flat)
        {
            EnterLong();
        }
    }
    Code:
    // Close all positions at 16:10
    if (ToTime(Time[0]) >= 161000)
    {
        ExitLong();
        ExitShort();
    }
    The second code snippet takes into account your third question. Since it is possible that some bar types may not update exactly at 16:10 - we may have an update, say, at 16:09 and another at 16:11 - by setting my condition so that it checks every time between 16:10 and midnight, and using methods that are safe to call from a flat position and will flatten any non-flat position, we have guaranteed that our position will flatten some time between 16:10 and midnight.

    If we need this to flatten exactly at 16:10, we can provide this guarantee by setting CalculationMode to Ticks (or CalculateOnBarClose = false in NT7).
    Last edited by NinjaTrader_JessicaP; 03-23-2016, 08:26 AM. Reason: Extra right paren

    Leave a comment:


  • rtwave
    started a topic time limitations for automated strategies

    time limitations for automated strategies

    hello, everyone,



    i could use a lot of guidance with the subject of time limitations / filters for automated strategies. i searched these fora, but found no definitive answers for nt7.


    1) how could i limit an automated strategy so that it only enters new trades between 18:00 et and 16:00 et of the next day? say, from 18:00 on sunday on to 16:00 on monday, and then from 18:00 on monday on to 16:00 on tuesday and so on.


    2) also, if i wanted the strategy to close all the positions it has generated at 16:10 every day, what kind of commands would be useful?


    3) and finally, it seems to me that nt can handle this kind of time constraints on periods to place trades and times to close all positions irrespective of the kind of bars that the strategy is executed on (minute, range, kase, etc), am i right?


    thanks.

Latest Posts

Collapse

Topics Statistics Last Post
Started by Moody1337, Today, 09:25 AM
0 responses
3 views
0 likes
Last Post Moody1337  
Started by franco12364, Today, 08:59 AM
1 response
5 views
0 likes
Last Post NinjaTrader_Kate  
Started by kweiss, Yesterday, 08:35 PM
1 response
8 views
0 likes
Last Post NinjaTrader_Jesse  
Started by franco12364, Today, 08:36 AM
1 response
3 views
0 likes
Last Post NinjaTrader_Jim  
Started by Aporshnev, Today, 02:36 AM
2 responses
7 views
0 likes
Last Post Aporshnev  
Working...
X