• 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

Just close on the first option

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

    Just close on the first option

    Code:
    if (
                     // si hay 4 contratos
                    ((Position.Quantity >= 4)
                     && (GetCurrentAsk(0) <= (Position.AveragePrice + (Cierre4contratos * TickSize)) )
                     && (Position.MarketPosition == MarketPosition.Short))
                     || (Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) <= Stoploss)
                     // si hay menos de 4 contratos
                     || ((Position.Quantity < 4)
                     && (GetCurrentAsk(0) <= EMA1[0])
                     && (Position.MarketPosition == MarketPosition.Short)))
                {
                    ExitShort(Convert.ToInt32(Position.Quantity), "", "");
                }
    I have 3 options to close a short trade. He always executes the first of them and should, if I am not mistaken, execute the situation of the three that previously occurred in the market.

    I don't know what's wrong.

    thanks

    #2
    In case it is not clear, I want it to close when one of the 3 conditions is in the market, which does not have to be the first of the three, as now is what happens.

    Comment


      #3
      Hello herkok,

      Thanks for your post.

      I may be misreading but I think you are saying that in the code shown, of the three conditions to exit, only the first one triggers an exit?

      If so then I would recommend debugging by using print statements prior to the "if" statement to indicate the status of each of the three conditions. Here is an example using your first condition:

      Print (Time[0]+ " Condition1: "+((Position.Quantity >= 4) && (GetCurrentAsk(0) <= (Position.AveragePrice + (Cierre4contratos * TickSize)) && (Position.MarketPosition == MarketPosition.Short))));

      The output would look like: 1/24/2020 9:42:00 AM Condition1: False

      Once you develop a situation where the condition should be true where it is false, then you could use further print statements to break out the variables in the condition and actually print the values to further debug.

      Here is a link to our debugging tips: https://ninjatrader.com/support/help...script_cod.htm
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_PaulH View Post
        Hello herkok,

        Thanks for your post.

        I may be misreading but I think you are saying that in the code shown, of the three conditions to exit, only the first one triggers an exit?

        If so then I would recommend debugging by using print statements prior to the "if" statement to indicate the status of each of the three conditions. Here is an example using your first condition:

        Print (Time[0]+ " Condition1: "+((Position.Quantity >= 4) && (GetCurrentAsk(0) <= (Position.AveragePrice + (Cierre4contratos * TickSize)) && (Position.MarketPosition == MarketPosition.Short))));

        The output would look like: 1/24/2020 9:42:00 AM Condition1: False

        Once you develop a situation where the condition should be true where it is false, then you could use further print statements to break out the variables in the condition and actually print the values to further debug.

        Here is a link to our debugging tips: https://ninjatrader.com/support/help...script_cod.htm
        indeed, only the first of the conditions is executed.

        I do not understand well how to put print time for the 3 conditions. I'm doing it with the strategy builder wizard

        Comment


          #5
          Hello herkok,

          Thanks for your reply.

          For the strategy builder I would take a slightly different approach and recommend that you print out all of the variables of the 3 conditions and print these on every bar. Then find where you think the condition(s) on the chart should have occured and check the printed values which will be shown by time (when you had the time as an output). This is a bit more work in the strategy builder but will serve you well as a good means to debug a strategy. Here is a link to a short video on how to construct a print statement that shows the values of variables: https://paul-ninjatrader.tinytake.co...NV8xMDk5MDc5Nw

          Paul H.NinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Kelsoner, Today, 11:31 AM
          0 responses
          3 views
          0 likes
          Last Post Kelsoner  
          Started by srbdoc, Today, 10:48 AM
          2 responses
          5 views
          0 likes
          Last Post srbdoc
          by srbdoc
           
          Started by Mttzern, Today, 10:42 AM
          0 responses
          12 views
          0 likes
          Last Post Mttzern
          by Mttzern
           
          Started by markbb10, Today, 06:55 AM
          2 responses
          8 views
          0 likes
          Last Post markbb10  
          Started by sgordet, Today, 09:58 AM
          1 response
          8 views
          0 likes
          Last Post NinjaTrader_ShawnB  
          Working...
          X