• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 Gav_G, Today, 02:12 PM
        3 responses
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Gav_G, Today, 01:41 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by kweiss, Today, 01:21 PM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by cutzpr, Today, 08:44 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Started by Burak, Yesterday, 10:40 PM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_ChrisL  
        Working...
        X