Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

COBC general signals with one special conditional exit

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

    COBC general signals with one special conditional exit

    Hi folks:

    I am working with a strategy that I am testing that uses COBC set to TRUE. When the basic condition is meet for Longs upon bar close it enters, if conditions change for short then it does reverse with COBC TRUE.

    Work fine...

    But, I want to set a separate and independent special condition using "else if" that will do the following:

    I would like, however, a moving average or equivalent following the entry long or short (as the case may be) in real time effectively being calculate as if it was running (or is running) with COBC false (or some method that will effectively allow it to calculate in the same way as COBC false). So, if I am in long or short this special condition will simply ExitShort or ExitLong (as the case may be) if price touches/crosses over the MA. This way, it does not have to wait for the bar to close to exit.

    How can I do this?

    I welcome multiple thoughts from different folks and I am sure others would like to potentially do this as well in the future.

    Thanks guys...

    @koganam if you can commit that would be great if you have time.


    #2
    Hello birdog,

    Using an "else if" statement it, will still have to process and be apart of the first "if" condition, so if you want a separate and independent condition then you may want just use an "if" statement.

    But with that said you may do something like the following:

    Code:
    protected override void OnBarUpdate()
    {
    	if (CrossAbove(SMA(7), SMA(14), 1))
    	    EnterLong();
    	else if (CrossBelow(SMA(7), SMA(14), 1))
    	    EnterShort();
    	else if (SMA(7)[0] <= Close[0] && Position.MarketPosition == MarketPosition.Long)
    	    ExitLong();
    	else if (SMA(7)[0] >= Close[0] && Position.MarketPosition == MarketPosition.Short)
    	   ExitShort();
    }
    Let me know if you have any questions.
    JCNinjaTrader Customer Service

    Comment


      #3
      Originally posted by birdog View Post
      Hi folks:

      I am working with a strategy that I am testing that uses COBC set to TRUE. When the basic condition is meet for Longs upon bar close it enters, if conditions change for short then it does reverse with COBC TRUE.

      Work fine...

      But, I want to set a separate and independent special condition using "else if" that will do the following:

      I would like, however, a moving average or equivalent following the entry long or short (as the case may be) in real time effectively being calculate as if it was running (or is running) with COBC false (or some method that will effectively allow it to calculate in the same way as COBC false). So, if I am in long or short this special condition will simply ExitShort or ExitLong (as the case may be) if price touches/crosses over the MA. This way, it does not have to wait for the bar to close to exit.

      How can I do this?

      I welcome multiple thoughts from different folks and I am sure others would like to potentially do this as well in the future.

      Thanks guys...

      @koganam if you can commit that would be great if you have time.

      If you want to do anything midbar, you have only 2 choices. Use COBC = false, or use another event that is not constrained to the bar close, such as OnMarketData(), in conjunction with the COBC = true.

      If you use COBC = false, you will have to use FirstTickOfBar as a gate to process they that must be calculated on bar close, and index matters to the previous bar.

      There is an example in the Samples forum on this board.

      Comment


        #4
        Thanks @koganam I am looking at that sample thread and I think this is precisely what I am after after a cursory look real quick...I will try to implement...

        @jc I think it would still execute after bar close with your example if I set to cobc True on the main strategy...maybe I am not understanding?

        Comment


          #5
          Hello birdog,

          Correct, using COBC true it will execute after the bar close. To have your code processed intrabar you would have to use the 2 options koganam or add an intrabar granularity but two different options that koganam are much easier.

          Here is an example of using COBC false and then separating out your logic from the logic that you want processed intrabar (every tick) and the logic that you want to happen on the close of a bar.
          JCNinjaTrader Customer Service

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          648 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          369 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          108 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          572 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          573 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X