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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        67 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        36 views
        0 likes
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        59 views
        1 like
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        62 views
        0 likes
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        53 views
        0 likes
        Last Post CarlTrading  
        Working...
        X