Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

next bar after entering order

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

    next bar after entering order

    Hello guys, i've been trying to figure out this problem for some hours already. it cant be so hard but i cant get around it.

    the thing is that i tell my strategy to execute a long order at the american time market open, in my case 15:30, after the order is executed, i want the strategy to close it at 15:31 independently of the PnL. that's all.

    i have this piece of code:
    Code:
     if (ToTime(Time[0]) == 153100 && (PositionAccount.MarketPosition == MarketPosition.Long))
    {
    ExitLong();
    }
    but the strategy doesnt read this piece of code and the order isnt closed. so my question is, is there any way i can tell a strategy to do something in the next minute? if so, how?

    thank you

    #2

    Hey solotiempopls,

    Are you using 1 minute bars as your data series? And PositionAccount only works with running strategies, not backtests (I could be wrong).

    Try this instead :

    Code:
    if (Time[0].Hour == 15 && Time[0].Minute == 31 && Position.MarketPosition == MarketPostiion.Long) {
        ExitLong();
    }



    I build useful software systems for financial markets.

    Generate automated strategies in NinjaTrader : www.stratgen.io

    Comment


      #3
      Hello solotiempopls,

      Is the entry being submitted by the strategy?
      A strategy can only close a position opened by that strategy instance.

      PositionAccount would be the account position and not the strategy position.



      Use Print() and trace orders to understand the behavior.


      Is the condition evaluating as true at the time you expect?
      Is the order being submitted, rejected, ignored, or cancelled?

      What Calculate setting is being used?
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hello JakeOfSpades

        thanks for the advice. yes, im using 1 minute charts. i have edited my code and replaced it with yours but it still doesnt seem to close the position.


        NinjaTrader_ChelseaB yes, the entry is opened correctly using an "if" function with "ToTime(Time[0]) == 153000". But when i use the same code to close the trade 1 minute in the future with "ToTime(Time[0]) == 153100" it doesnt work. i have tested with Print() and when the trade is opened at 15:30, the strategy continues reading the code down and works if i use "ToTime(Time[0]) != 153100" because its still 15:30. but it doesnt print anything if the condition is "ToTime(Time[0]) == 153100". because the strategy only seems to be working at the minute when the trade is opened. am i missing something?

        Comment


          #5
          Hello solotiempopls,

          May we have the output saved to a text file to assist with analyzing the output to understand the behavior?

          Are you printing the time of the bar and all values used in the condition above the condition set?
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            sure, i need an email and instructions to get the text file and ill send it. about the question, im not sure about what you mean

            Comment


              #7
              Hello solotiempopls,

              Right-click the NinjaScript Output window -> select Save as, then save the file as a text file.

              Attach this to your next forum post by clicking the Upload Attachments button.

              "Are you printing the time of the bar and all values used in the condition above the condition set?"
              I am wanting to confirm, that you are print format is as shown in the forum post that demonstrates how to use prints to understand behavior linked in post #3.
              The time of bar is Time[0]. The values in condition depends on your condition.. The print should be above the condition set.
              Chelsea B.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by NullPointStrategies, Yesterday, 05:17 AM
              0 responses
              71 views
              0 likes
              Last Post NullPointStrategies  
              Started by argusthome, 03-08-2026, 10:06 AM
              0 responses
              143 views
              0 likes
              Last Post argusthome  
              Started by NabilKhattabi, 03-06-2026, 11:18 AM
              0 responses
              76 views
              0 likes
              Last Post NabilKhattabi  
              Started by Deep42, 03-06-2026, 12:28 AM
              0 responses
              47 views
              0 likes
              Last Post Deep42
              by Deep42
               
              Started by TheRealMorford, 03-05-2026, 06:15 PM
              0 responses
              51 views
              0 likes
              Last Post TheRealMorford  
              Working...
              X