Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Storing a Bool Flag

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

    #31
    Originally posted by cdjindia View Post
    I want to execute custom stuff whenever strategy closes out of a position and I've done following to make it work reliably. Most crucial word here is volatile.
    By declaring a variable as volatile, I effectively tell C# to never cache or
    skip execution step that involves that variable.

    Code:
    public volatile bool myBooleanFlag = false;
    protected override void OnExecution(IExecution execution)
    {
        if (execution.MarketPosition == MarketPosition.Flat)
        {
            if (myBooleanFlag == true)
                DoCustomStuff();
            myBooleanFlag = false;
        } else
        {
            myBooleanFlag = true;
        }
    }
    Thanks, I will play with that.

    Comment


      #32
      Originally posted by NinjaTrader_ChelseaB View Post
      Hi Hammerhorn,

      To clarify, when an order is entered the longTrades bool is changed to false. At that point the you would not like the bool reset to true until the indicator value drops below Close[0] price and the rises above it once again. Is this correct?

      For this you will need two variables. I have modified the sample I have created to show this.

      Let me know if this is still not what you are looking for.
      Yes you are correct. I will have to play with this, never even thought of the two variables. This seems straight forward, but I would like to know the logic behind it, please.

      Comment


        #33
        Originally posted by Hammerhorn View Post
        Sorry for my ignorance, but how is that different that Close[0] greater or less than an indicator in this instance?
        You tell me. Was it working the way that you wanted when you coded it that way? That is the difference.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        591 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        343 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        103 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        556 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        553 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X