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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    87 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    128 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    65 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    117 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    67 views
    0 likes
    Last Post PaulMohn  
    Working...
    X