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 TheMarlin801, 10-13-2020, 01:40 AM
        20 responses
        3,914 views
        0 likes
        Last Post Bidder
        by Bidder
         
        Started by timmbbo, 07-05-2023, 10:21 PM
        3 responses
        150 views
        0 likes
        Last Post grayfrog  
        Started by Lumbeezl, 01-11-2022, 06:50 PM
        30 responses
        805 views
        1 like
        Last Post grayfrog  
        Started by xiinteractive, 04-09-2024, 08:08 AM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by Johnny Santiago, 10-11-2019, 09:21 AM
        95 responses
        6,194 views
        0 likes
        Last Post xiinteractive  
        Working...
        X