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

Algorim search and put pending order

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

    Algorim search and put pending order

    Hello i need that one strategy, when i start at 22:00 when market close , see all points that algorim search, and put pending orders in this points for next day.

    I cant do the algorim, i try but i cant.

    Thanks for the help.

    #2
    Hello tibetillo,

    I can quote and paraphrase a section from the Help Guide to help you with this strategy. You will need to modify the market opening time the two places where you see bold italic font



    Code:
    [FONT=Courier New]// Only trade before [I][B]7:45 AM[/B][/I] or after 22:00 PM
    if (ToTime(Time[0]) <= [I][B]74500[/B][/I] || ToTime(Time[0]) >= 220000)
    {
        [B]// Strategy logic goes here[/B]
    }[/FONT]
    Where I have bolded you will want to delete and replace by your algorithm and pending order code.

    Please let us know if there is any other way we can help.
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Algorim

      Hello Jessica,

      Thanks for reply but i need know the next algorim:

      Market Open 8:00 to 22:00.

      First - When i put the algorim in 8:00 , the algorim evaluate previous day.
      Second - When algorim obtain the points, put the pending order in actually day.

      Other option.

      First - The algorim obtain the points in the current day but not put the order.
      Second - The orders put in next day.

      Comment


        #4
        So first, with the market opening at 08:00, this is why I bolded a couple things. Let's change that first.

        Code:
        [FONT=Courier New]// Only trade before [B]8:00 AM[/B] or after 22:00 PM
        if (ToTime(Time[0]) <= [B]80000[/B] || ToTime(Time[0]) >= 220000)
        {
            // Strategy logic goes here
        }[/FONT]
        Next, it sounds like you will need to do something between the hours of 22:00 PM and 08:00 AM exactly once. So we can do this :

        Code:
        [FONT=Courier New]private bool placedNextDaysTrades = false;
        
        protected override void OnBarUpdate()
        {[/FONT]
        [FONT=Courier New]    // Place pending trades before 8:00 AM or after 22:00 PM
            if (ToTime(Time[0]) <= 80000 || ToTime(Time[0]) >= 220000)
            {
                if (! placedNextDaysTrades)
                {
                    [B]// Strategy logic goes here[/B]
                    placedNextDaysTrades = true;
                }
            }
        
            // It is during trading hours
            else
            {
                placedNextDaysTrades = false;
            }
        }
        [/FONT]
        Now you will just need to replaced the bolded line with your order entry logic. I am including a link to a help guide page for order entry. Please review the below link. Please also let us know if there are any other ways we can help.

        Jessica P.NinjaTrader Customer Service

        Comment


          #5
          Hello

          Hello! Thanks for reply.

          I need the algorithm if I put it at 8:00 , the first thing you should do is check the day before according to some conditions. Here there is the problem not as done to review the previous 14 bars for the previous day , once a revised target those conditions pending orders at certain points , this last if I can do it.

          Comment


            #6
            So for this last part, we just need to make sure that there is data for yesterday available. We can use the variables BarsPeriod.BasePeriodType and BarsPeriod.BasePeriodValue to figure out how many bars we need. The following sample will only work with minute and daily bars; if you need it to do more, it should be easy enough to figure out how to modify it.

            Code:
            [FONT=Courier New]private bool placedNextDaysTrades = false;
            
            [B]/// <return>whether or not 1 day has passed yet</return>
            private bool enoughBarsHavePassed()
            {
                if (BarsPeriod.BasePeriodType == PeriodType.Minute)
                {
                    return CurrentBar / (1440 / BarsPeriod.BasePeriodValue) >= 1.0;
                }
                if (BarsPeriod.BasePeriodType == PeriodType.Daily)
                {
                    return CurrentBar >= 1;
                }
                return false;
            }
            [/B] 
            protected override void OnBarUpdate()
            {
                [B]if (! [/B][/FONT][FONT=Courier New][B][FONT=Courier New][B]enoughBarsHavePassed())
                {
                    return;
                }
            
            [/B][/FONT][/B][/FONT] [FONT=Courier New]     // Place pending trades before 8:00 AM or after 22:00 PM
                if (ToTime(Time[0]) <= 80000 || ToTime(Time[0]) >= 220000)
                {
                    if (! placedNextDaysTrades)
                    {
                        // Strategy logic goes here
                        placedNextDaysTrades = true;
                    }
                }
            
                // It is during trading hours
                else
                {
                    [B]// yesterday's data will now be available here
                    // this example will work with daily bars
                    Print("Yesterday's closing price was " + Close[1]);
            
            [/B]         placedNextDaysTrades = false;
                }
            }
            [/FONT]
            Please don't hesitate if we can clear anything else up.
            Jessica P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Stanfillirenfro, Yesterday, 09:19 AM
            7 responses
            51 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by TraderCro, 04-12-2024, 11:36 AM
            4 responses
            69 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Mindset, Yesterday, 02:04 AM
            1 response
            15 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by agclub, 04-21-2024, 08:57 PM
            4 responses
            18 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by Irukandji, Today, 04:58 AM
            0 responses
            6 views
            0 likes
            Last Post Irukandji  
            Working...
            X