Announcement

Collapse
No announcement yet.

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.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    43 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    20 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    30 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    48 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    38 views
    0 likes
    Last Post CarlTrading  
    Working...
    X