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

      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

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by NullPointStrategies, Yesterday, 05:17 AM
          0 responses
          54 views
          0 likes
          Last Post NullPointStrategies  
          Started by argusthome, 03-08-2026, 10:06 AM
          0 responses
          131 views
          0 likes
          Last Post argusthome  
          Started by NabilKhattabi, 03-06-2026, 11:18 AM
          0 responses
          73 views
          0 likes
          Last Post NabilKhattabi  
          Started by Deep42, 03-06-2026, 12:28 AM
          0 responses
          44 views
          0 likes
          Last Post Deep42
          by Deep42
           
          Started by TheRealMorford, 03-05-2026, 06:15 PM
          0 responses
          49 views
          0 likes
          Last Post TheRealMorford  
          Working...
          X