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 Do Something after a stop loss/after exiting ?

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

    How to Do Something after a stop loss/after exiting ?

    I am building a trend trading strategy. As everyone knows, there would be some 'false trends' recognised by a strategy whenever it is not a strategy perfect for recognising trend. I would like to spot those false trends by counting the times I hit my stop loss in a trend. For example, how should I code if I want to call a trend false after my stop loss has been hit 3 times? I have thought of the following
    if (stoploss something)
    {
    a++;
    }
    and when a = 3, I call this trend a false one. But I just do not know what to type in the bracket.
    Also, I would like to stop entering the market after having 3 profiting trades in a single trend. What should I type in the bracket?
    Thank you!

    #2
    Hello alantse123,

    Thank you for the post.

    Your logic would likely work for the purpose you described, but I am unsure what you mean by what to type into the bracket, Can you clarify what you mean by bracket in contrast to the syntax you provided? Is this the stoploss something condition you are speaking about?

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Sorry for the unclear meaning. What I mean is
      if (EventA)
      {
      a++;
      }
      EventA is "When my stop loss is hit./When I exit by a stop loss but not a profit target".
      How should I code for the above event?
      I want the action "a++" to be taken right after the an exit order is executed, does that mean I should put it inside OnOrderUpdate? If yes, what should the code look like?
      Last edited by alantse123; 12-18-2018, 09:18 PM.

      Comment


        #4
        Hello alantse123,

        Thank you for the reply.

        If you are looking for an order fill, you should use OnExecutionUpdate for that purpose as this override deals directly with the scripts executions.
        https://ninjatrader.com/support/help...ub=onexecution

        You have provided the syntax a++ which is valid syntax, you would just need to put that where you want it to be executed. If an order execution is where you would like that to happen, you could put the a++ inside of OnExecutionUpdate within a condition checking for the order you want. We have some examples showing how OnExecution can be used in the help guide link I provided above.

        If you are using the Set methods for the stoploss, you will need to look in the control center orders tab at the orders name and use that in place of the name provided in the sample "myEntryOrder". Upon finding the stop order you could execute the a++ inside of that condition.

        As I am unsure of the scope where you have defined the "a" variable, I would suggest using the help guide sample to implement the OnExecutionUpdate override in your script. At that point, if you are having difficulty with a portion of using this override in contrast to what you have coded, I would suggest uploading what you coded so I can see specifically what you wrote. This would help me to provide more detailed answers surrounding your questions.

        I look forward to being of further assistance.
        JesseNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by yertle, Yesterday, 08:38 AM
        7 responses
        28 views
        0 likes
        Last Post yertle
        by yertle
         
        Started by bmartz, 03-12-2024, 06:12 AM
        2 responses
        21 views
        0 likes
        Last Post bmartz
        by bmartz
         
        Started by funk10101, Today, 12:02 AM
        0 responses
        6 views
        0 likes
        Last Post funk10101  
        Started by gravdigaz6, Yesterday, 11:40 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by MarianApalaghiei, Yesterday, 10:49 PM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Working...
        X