Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Maintain true condition until the condition changes to false

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

    Maintain true condition until the condition changes to false

    I thought that I had posted a question on the above earlier this week, but maybe it did not happen.
    I am trying to add to my code such that when a condition changes from false to true, this condition is maintained until some later event causes the condition to change back to false. This is to stop potential trades opening in the opposite direction to my definition of the main trend.
    I have tried one menthod that changes when the event occurs, but changes back on the next bar. I cannot get it to stay 'true" for the next unknown number of bars. I think that the "while" idea may be useful, but I cannot find any snippets to help me.
    Any information to point me in the productive direction would be most appreciated.

    #2
    Originally posted by oldhiker View Post
    I thought that I had posted a question on the above earlier this week, but maybe it did not happen.
    I am trying to add to my code such that when a condition changes from false to true, this condition is maintained until some later event causes the condition to change back to false. This is to stop potential trades opening in the opposite direction to my definition of the main trend.
    I have tried one menthod that changes when the event occurs, but changes back on the next bar. I cannot get it to stay 'true" for the next unknown number of bars. I think that the "while" idea may be useful, but I cannot find any snippets to help me.
    Any information to point me in the productive direction would be most appreciated.
    Code:
    private ConditionIsTrueFlag = true; //or false, as your initial condition desired
    
    if (!ConditionIsTrue)
    {
    //Process code for when condition is false
    ConditionIsTrueFlag = true;
    }
    
    if (ConditionIsTrue)
    {
    //Process code for when condition is true
    ConditionIsTrueFlag = false;
    }
    
    if (ConditionIsTrueFlag)
    {
    //Do stuff for the megabucks
    }
    Where "ConditionIsTrue" is just a place holder for your conditions to activate/deactivate the flag.

    If you need to be able to compare the truth state to that in a previous bar, then you will need to use a BoolSeries instead of a bool variable.

    Comment


      #3
      oldhiker, for what you seek you can look into this reference sample here dealing with user variables, which are the strategy wizard version of bool flags basically - http://www.ninjatrader.com/support/f...ad.php?t=15417
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Hello Bertrand and koganam,
        Thank you for the speedy reply. I have a severe cold/flu, so I will not be able to test the info for a day or two, but it looks good.
        I will get back to both when I have tried the coding.
        I like the line of code re "megabucks"
        I cannot find where to record my "thanks", so I am very pleased to say thanks in this reply.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by soyjesus, Today, 05:27 AM
        0 responses
        2 views
        0 likes
        Last Post soyjesus  
        Started by JarodB, Today, 04:44 AM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Jason  
        Started by mahmud999, Today, 04:54 AM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by leonardo3381, Today, 01:58 AM
        3 responses
        21 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by Mindset, Today, 02:16 AM
        0 responses
        9 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X