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 lightsun47, Today, 03:51 PM
    0 responses
    4 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    8 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    44 views
    0 likes
    Last Post futtrader  
    Started by Option Whisperer, Today, 09:55 AM
    1 response
    13 views
    0 likes
    Last Post bltdavid  
    Started by port119, Today, 02:43 PM
    0 responses
    8 views
    0 likes
    Last Post port119
    by port119
     
    Working...
    X