Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Simple Strategy for Testing Purposes

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

    Simple Strategy for Testing Purposes

    Sorry noob programmer here. Maybe some help or put me in the right direction.
    I just want a strategy that enters long on the open and exits on the close.
    CalculateOnBarClose = false;

    Also have added intrabar granularity..

    #2
    Hello CWJones,

    Thanks for your post and welcome to the forums!

    From the description your strategy sound like it is time based. What you would want to do is to check the current bars time to see if it meets the opening time value then enter the order. The same would be true for the end of the day (also another method to consider would be ExitOnClose). I'll provide some links to a reference samples that use time as a filter but should give you the idea.

    Helpguide on time: http://ninjatrader.com/support/helpGuides/nt7/?time.htm
    For Multiseries you might need: http://ninjatrader.com/support/helpG...nt7/?times.htm

    Using ToTime: http://ninjatrader.com/support/helpG...t7/?totime.htm

    Reference strategy: http://ninjatrader.com/support/forum...ead.php?t=3226

    Finally, I like to use the condition builder of the strategy wizard to create the conditions needed and you can use this in code: http://ninjatrader.com/support/helpG...ing_action.htm

    http://ninjatrader.com/support/helpG...on_builder.htm Check the section: "How to create time comparisons"

    Exit On Close: http://ninjatrader.com/support/helpG...xitonclose.htm

    Comment


      #3
      Hey Paul ..Thanks for your response... It seems to me this should be fairly simple to do..Yet I am having trouble with this.. Could you give me an example possibly to put me on the right path.
      1. buy the open of say a 1hr time frame .
      2. exit on the close of same hour.

      I have looked through NT forum and Big Mikes forum.
      I am sure I am not the only one that wants this sort of algo to test biases.

      Comment


        #4
        Hello CWJones,

        Thanks for your reply.

        Assuming you are using CalculateOnBarClose = false this would be pretty easy. The key is to use the Ninjascript bool "FirstTickOfBar" to both enter and exit. http://ninjatrader.com/support/helpG...ttickofbar.htm

        First the code example:

        Code:
        if (FirstTickOfBar)
        {
            lookforentry = true;   [COLOR="Green"]// set flag to look for entry[/COLOR]
        
            if (Position.MarketPosition == MarketPosition.Long)  [COLOR="Green"]// But take care of exit first[/COLOR]
            {
                ExitLong() ; [COLOR="Green"]// if already long, exit position;[/COLOR]
            }
        }
        
        if (Position.MarketPosition == MarketPosition.Flat && lookforentry && your entry conditions)
        {
            EnterLong();  [COLOR="Green"]// place new order in this bar[/COLOR]
        
            lookforentry = false; [COLOR="Green"] // set back to false so we only do it once per bar[/COLOR]
        }
        FirstTickOfBar will be true once and only once on the very first tick of the new hourly bar and will not be true again until the very next bar. For the FirstTickOfBar bool to work, you must use CalculateOnbarClose set to false to allow processing on each tick.
        So FirstTickOfBar is basically the same time as the end of the previous bar which is why it works for both entry and exit.

        First to discuss the exit: On the first tick of the hourly bar we check to see if indeed we are in a long position (from the prior bar). If so then we process the exit.

        Now for the entry: Because we are potentially exiting and entering at the same time, to avoid any possible order conflict, I used another bool (previously initialized to false) called "lookforentry", which was set true on the first tick of the bar. As the ticks of the new bar process, when the strategy knows that we are in a flat market position (previous long exited) and if your entry conditions are true and the lookforentry is true, then we will enter long pretty much at the beginning of the bar. Finally, we set lookforentry to false until the very first tick of the next bar.

        I am assuming you would only enter long if you had some other conditions so that is why I had "your entry conditions" added in.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        574 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        332 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        553 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        551 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X