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

Pending orders with different conditions

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

    Pending orders with different conditions

    Hello,

    Could anybody pls help me with pending orders based on two different conditions?
    I would like to program bellow logic

    if my 1st condition (simple formation in a chart) is filled , place 1st pending order on high of current bar High[0].

    After my 1st pending order is filled (and i am in position now) i want the strategy to place another pending order on current High[0]

    Basically i would like to program, if my condition1 is filled, place 1st pending order and if this 1st pending order is filled by following bar, place another pending order on current bar (which opened the 1st position).

    I tried to program bellow logic but it does not work :s

    Code:
     if (entryOrderOne != null && High[0] > High[1]) // if 1st pending order is filled place 2nd pending order
            {
            entryOrderTwo = EnterLongStop(0, false, 1, High[0] + 1 * TickSize, "trend");
            }
    
    If (conditionOne)
    {
    entryOrderOne  // 1st pending order placed after my condition was confirmed
    }
    Could anybody pls tell me what is wrong with the code? I used IOrders to place pendings as well as to check if position was filled.

    #2
    Hello Filip88,
    Thank you for your post.

    Please try to use Position.MarketPosition == MarketPosition.Flat for your first order and
    use Position.MarketPosition == MarketPosition.Long as the condition to submit your second order instead of entryOrderOne != null
    In addition as you are using a managed approach you will need to take EntriesPerDirection into account.
    If you change EntriesPerDirection to a value greater than 1 does the second order get placed?
    You can change EntriesPerDirection in the Strategy Parameters window.
    Cody B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_CodyB View Post
      Hello Filip88,
      Thank you for your post.

      Please try to use Position.MarketPosition == MarketPosition.Flat for your first order and
      use Position.MarketPosition == MarketPosition.Long as the condition to submit your second order instead of entryOrderOne != null
      In addition as you are using a managed approach you will need to take EntriesPerDirection into account.
      If you change EntriesPerDirection to a value greater than 1 does the second order get placed?
      You can change EntriesPerDirection in the Strategy Parameters window.
      Thank you for your quick reply

      It works now, however i am having different problem, please see bellow code

      // If my condition is filled and position is flat place pending order
      if (condition one, Position.MarketPosition == MarketPosition.Flat)
      {
      EntryOrderOne = EnterLongStop(0, false, 1, High[0] + 1 * TickSize, "trend1")
      }

      // If i have long position opened, due to previous 1st condition, place second pending order
      If (Position.MarketPosition == MarketPosition.Long
      && High[0] > High[1])
      EntryOrderTwo = EnterLongStop(0, false, 1, High[0] + 1 * TickSize, "trend2");

      each time i am in long position, the strategy generates continuously new pending orders even though 1st condition is not filled. Am I able somehow to fix this so that 2nd pending order will be placed only in case the 1st condition is filled?

      I tried to add IOrders EntryOrderOne =! null, but it did not work :s

      Comment


        #4
        Hello,
        Can you provide a snippet of your code showing these conditions so I may investigate further?
        I look forward to your reply.
        Cody B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_CodyB View Post
          Hello,
          Can you provide a snippet of your code showing these conditions so I may investigate further?
          I look forward to your reply.
          Hello

          bellow code
          Code:
            protected override void OnBarUpdate()
                  {
              double upperValue_BB = Bollinger(2, BBvalue_RH1).Upper[0];
              
                      
                      
              if (Position.MarketPosition == MarketPosition.Long && High[0] > High[1]) 
                  {
              
                  entryOrderTwo = EnterLongStop(0, false, 1, High[0] + 1 * TickSize, "trend");
                 
                  }
                      
              if (
                  High[1] > High[2] && High[1] > High[3] && Low[1] > Low[2] && Low[0] > Low[1] &&
                  Close[0] > High[1] &&    High[0] > upperValue_BB &&
                  Position.MarketPosition == MarketPosition.Flat 
                  )
          
                      {
                          DrawArrowUp(CurrentBar.ToString(), false, 0, Low[0], Color.Lime);
          
                          entryOrderOne = EnterLongStop(0, false, 1, High[0] + 1 * TickSize, "1st_enter");    
                  
          
                      } 
                  }
          in case i am in long position from previous trades, it continuously enters new positions, regardless the formation in the 2nd if statement. I am trying to fix the second entry to the formation and enters the second position only in case the formation was formed.

          Thank you for support

          Comment


            #6
            Hello Filip88,

            Thank you for your response.

            Use a bool as a switch in this case.
            Code:
            if(conditon1 && !myBool)
            {
            myBool = true;
            }
            if(condition2 && mybool)
            {
            myBool = false;
            }
            Where myBool is your bool defined.

            Comment


              #7
              it works, thank you for support

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by funk10101, Today, 12:02 AM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_LuisH  
              Started by GLFX005, Today, 03:23 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_Erick  
              Started by nandhumca, Yesterday, 03:41 PM
              1 response
              13 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by The_Sec, Yesterday, 03:37 PM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_Gaby  
              Started by vecnopus, Today, 06:15 AM
              0 responses
              1 view
              0 likes
              Last Post vecnopus  
              Working...
              X