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

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 traderqz, Yesterday, 09:06 AM
          3 responses
          20 views
          0 likes
          Last Post NinjaTrader_ThomasC  
          Started by f.saeidi, Today, 10:19 AM
          1 response
          4 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Started by kujista, Today, 06:23 AM
          5 responses
          15 views
          0 likes
          Last Post kujista
          by kujista
           
          Started by traderqz, Today, 12:06 AM
          3 responses
          6 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by RideMe, 04-07-2024, 04:54 PM
          5 responses
          28 views
          0 likes
          Last Post NinjaTrader_BrandonH  
          Working...
          X