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

Reset BOOL value after target reached

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

    Reset BOOL value after target reached

    My current code is below and it works to enter and exit trades accurately as long as my criteria is NOT met again on a subsequent bar while the trade is open. If the entry critria is met on subsequent bars while the trade is open, the strategy updates my varaible values and moves my profit/loss targets. I have created the bool "TradeInProgress" to address this, but I don't know how to set TradeInProgress = false after my targets are hit.

    The code below is entering a position and setting the BOOL to true. My question: how do you tell the strategy to keep the BOOL value true until a target is hit, then set the BOOL value to false after the target is reached?

    --------------------------------------
    if (criteria to enter trade)

    {
    EntryCandleHigh = High[0];
    EntryCandleLow = Low[0];
    LongTarget = (EntryCandleHigh - (EntryCandleLow-0.25)) * RiskReward;

    EnterLongLimit(Convert.ToInt32(DefaultQuantity), EntryCandleHigh, @"EnterLong");
    SetStopLoss(@"EnterLong", CalculationMode.Price, EntryCandleLow-0.25, false);
    SetProfitTarget(@"EnterLong", CalculationMode.Price, EntryCandleHigh + LongTarget);

    TradeInProgress = true;
    }​

    #2
    Hello GoCubsGo,

    Thank you for your post.

    You can track if your profit target has been hit from OnOrderUpdate() and flip the bool to false from there (as long as it is a class level variable).





    You can check to see if the order.Name is "Profit target", and check the order state from OnOrderUpdate().

    Please let me know if you have any further questions.
    Gaby V.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Option Whisperer, Today, 09:55 AM
    0 responses
    4 views
    0 likes
    Last Post Option Whisperer  
    Started by geddyisodin, 04-25-2024, 05:20 AM
    8 responses
    58 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by halgo_boulder, 04-20-2024, 08:44 AM
    2 responses
    22 views
    0 likes
    Last Post halgo_boulder  
    Started by mishhh, 05-25-2010, 08:54 AM
    19 responses
    6,189 views
    0 likes
    Last Post rene69851  
    Started by gwenael, Today, 09:29 AM
    0 responses
    5 views
    0 likes
    Last Post gwenael
    by gwenael
     
    Working...
    X