• 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

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.
            Patrick H.NinjaTrader Customer Service

            Comment


              #7
              it works, thank you for support

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by hundert, Today, 08:37 AM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_Melissa  
              Started by ronaldgreene828, Today, 08:16 AM
              1 response
              6 views
              0 likes
              Last Post NinjaTrader_PatrickG  
              Started by hir04068, Today, 01:36 AM
              1 response
              16 views
              0 likes
              Last Post NinjaTrader_PaulH  
              Started by luxurious_04, 07-21-2019, 07:13 PM
              2 responses
              14 views
              0 likes
              Last Post luxurious_04  
              Started by swcooke, Yesterday, 07:35 PM
              0 responses
              16 views
              0 likes
              Last Post swcooke
              by swcooke
               
              Working...
              X