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

how to check last trade = loser and was a long

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

    #16
    Hello meowflying,

    That would likely be correct. The check requires that there be at least one trade. (There must be at least one trade if you are trying to check the position of the entry of the previous trade)

    You may want to change your if statement and use parenthesis.

    if ( Performance.AllTrades.Count < 1 || (Performance.AllTrades.Count > 0 && Performance.AllTrades[Performance.AllTrades.Count - 1].Entry.MarketPosition != MarketPosition.Long) )

    This states if the count is less than 1 or if both the count is greater than 0 and the previous trades entry is not into a long position.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      Chelsea, thank you for suggestion. It does what it should regarding the long and short entries restriction. However the code providing undesired pending entries to the opposite direction, ignoring one of the main conditions: Close[1] > Open[1]
      Please advise, I have no idea what is the reason for that..

      (Close[1] > Open[1]
      && Performance.AllTrades.Count < 1 || (Performance.AllTrades.Count > 0
      && Performance.AllTrades[Performance.AllTrades.Count - 1].Entry.MarketPosition != MarketPosition.Long)
      && High[1]-Close[0] > 1 * TickSize
      && Position.MarketPosition == MarketPosition.Flat
      && Low[1]-Low[2] < 6 * TickSize )

      {


      EnterLongStopLimit(DefaultQuantity, High[1]-1 * TickSize,High[1]-1 * TickSize, "long");

      Originally posted by NinjaTrader_ChelseaB View Post
      Hello meowflying,

      That would likely be correct. The check requires that there be at least one trade. (There must be at least one trade if you are trying to check the position of the entry of the previous trade)

      You may want to change your if statement and use parenthesis.

      if ( Performance.AllTrades.Count < 1 || (Performance.AllTrades.Count > 0 && Performance.AllTrades[Performance.AllTrades.Count - 1].Entry.MarketPosition != MarketPosition.Long) )

      This states if the count is less than 1 or if both the count is greater than 0 and the previous trades entry is not into a long position.

      Comment


        #18
        Hello meowflying,

        With the parenthesis you have the condition states the following:

        if the Close of the previous bar is greater than the Open of the previous bar and the performance count is less than one, OR if the Close of the previous bar is less than or equal to the Open of the previous bar and the performance count is greater than 0 and the position of the entry order was not into a long position.

        So, if the previous order was a buy order and the close of the previous bar is less than or equal to the open of the previous bar (meaning a red bar or a doji) then this condition will trigger.

        Is this the action you are intending?

        Are you wanting to isolate the performance check as its own condition?
        If so, put the condition for the performance check in parenthesis.
        Last edited by NinjaTrader_ChelseaB; 05-19-2016, 08:11 AM.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          I'm not intending to have that: "OR if the Close of the previous bar is less than or equal to the Open of the previous bar". By isolating the performance check as its own condition you mean to do this:

          (Performance.AllTrades.Count < 1 || (Performance.AllTrades.Count > 0
          && Performance.AllTrades[Performance.AllTrades.Count - 1].Entry.MarketPosition != MarketPosition.Long))

          Please advise. Thank you.




          Originally posted by NinjaTrader_ChelseaB View Post
          Hello meowflying,

          With the parenthesis you have the condition states the following:

          if the Close of the previous bar is greater than the Open of the previous bar and the performance count is less than one, OR if the Close of the previous bar is less than or equal to the Open of the previous bar and the performance count is greater than 0 and the position of the entry order was not into a long position.

          So, if the previous order was a buy order and the close of the previous bar is less than or equal to the open of the previous bar (meaning a red bar or a doji) then this condition will trigger.

          Is this the action you are intending?

          Are you wanting to isolate the performance check as its own condition?
          If so, put the condition for the performance check in parenthesis.

          Comment


            #20
            Hello meowflying,

            Yes, this would be putting that condition in parenthesis to isolate that condition.

            Does this have the intended affect?
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Chelsea, thank you it does work well now. May i ask you 2 more questions, i just dont want to open another thread for this.

              1. First, how I can know exact value of Stochastic R on the last Swing high or low. MIN and MAX functions are ok, but I dont want to guess how many bars ago the Swing happened.

              2. I'm trying to work with IOrder for canceling and entering order in better price, however it seems like null conditions not executing and first order never got pending or filled:

              private IOrder entryOrder = null; // This variable holds an object representing our entry order.

              // Condition set 1
              if (Close[1] > Open[1]
              && High[1]-Close[0] > 1 * TickSize
              && entryOrder == null)

              {

              entryOrder = EnterLongStopLimit(DefaultQuantity, High[1]-1 * TickSize,High[1]-1 * TickSize, "long");

              }


              else if (entryOrder != null && High[1]-Close[0] > 4 * TickSize )
              {

              CancelOrder(entryOrder);
              }


              // Condition set 2
              if (Close[1] > Open[1]
              && High[1]-Close[0] > 5 * TickSize
              && Low[1]-Low[2] < 6 * TickSize)



              {

              EnterLongStopLimit(DefaultQuantity, High[1]-4 * TickSize,High[1]-4 * TickSize, "long1");

              }


              Please advise, thank you.


              Originally posted by NinjaTrader_ChelseaB View Post
              Hello meowflying,

              Yes, this would be putting that condition in parenthesis to isolate that condition.

              Does this have the intended affect?

              Comment


                #22
                Hello meowflying,

                The Swing indicator changes its historical values. This makes this indicator difficult to create logic for. I'm not certain of the logic necessary to detect swings with this indicator correctly.

                Our NinjaTrader support does not create, debug, or modify code for our clients. This is so that we can maintain a high level of service for all of our clients as well as our partners.

                However this thread will remain open for any community members that would like to assist.

                You can also contact one of our professional NinjaScript Consultants who would be eager to create or modify this script at your request or assist you with your script. Please let me know if you would like our business development follow up with you with a list of professional NinjaScript Consultants who would be happy to create this script or any others at your request.


                When it comes to cancelling an order, calling CancelOrder() does not cause the IOrder handle (the variable holding the order) to become null. Instead this cancels the order and triggers OnOrderUpdate with the order state as cancelled. You would need to detect that the cancellation is effective and then make the variable null in the code.

                That said, if you are wanting to change the price of an order, it is not necessary to cancel it and resubmit it. Use a signalName on the order. Anytime an order is resubmitted using the same signalName, this will change that order instead of submitting a new order. This is called an order modification.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by samish18, 04-17-2024, 08:57 AM
                16 responses
                55 views
                0 likes
                Last Post samish18  
                Started by arvidvanstaey, Today, 02:19 PM
                3 responses
                9 views
                0 likes
                Last Post NinjaTrader_Zachary  
                Started by jordanq2, Today, 03:10 PM
                2 responses
                8 views
                0 likes
                Last Post jordanq2  
                Started by traderqz, Today, 12:06 AM
                10 responses
                18 views
                0 likes
                Last Post traderqz  
                Started by algospoke, 04-17-2024, 06:40 PM
                5 responses
                47 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X