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 define if an event happened during an open trade

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

    #16
    Hello ArmKnuckle,

    Thanks for your post.

    To create a counter just declare an integer with the name of your choice such as peCounter. Initialize it to 0. Then in the code you increment the variable using "++", for example:

    if (Close[0] > 63.0)
    {
    priceExceeded = true; // set bool/flag to indicate exit when cross
    peCounter++; // increment counter each time.
    }


    Then all you would need to do is to test for peCounter == 1, for example:

    if (CrossBelow(Stochastics(7, 14, 3).K[1], Stochastics(7, 14, 3).D[1] && priceExceeded && peCounter == 1)
    {
    ExitLong(100)
    }


    So to exit with a cross the peCounter must only be 1, otherwise it would exit on time. If you wanted to you could actually remove the bool variable and replace its function with the counter.

    Later in your code where you are resetting the bool variable you would now also want to reset the counter to 0: peCounter = 0;
    Paul H.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Vitamite, Yesterday, 12:48 PM
    3 responses
    17 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by aligator, Today, 02:17 PM
    0 responses
    10 views
    0 likes
    Last Post aligator  
    Started by lorem, 04-25-2024, 09:18 AM
    22 responses
    94 views
    0 likes
    Last Post lorem
    by lorem
     
    Started by sofortune, Today, 10:05 AM
    3 responses
    16 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by ETFVoyageur, 05-07-2024, 07:05 PM
    23 responses
    185 views
    0 likes
    Last Post ETFVoyageur  
    Working...
    X