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 NullPointStrategies, Yesterday, 05:17 AM
    0 responses
    62 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    134 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    75 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    45 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    50 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X