Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Code to add preceding candle as a condition

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

    Code to add preceding candle as a condition

    I'm trying to create a pullback/breakout indicator. I have correctly defined a PullbackCandle with a bool function. I want to now define the BreakoutCandle as the candle that makes a new high vs the previous candle only if that previous candle is also a PullbackCandle (that's critical). When I try to use a bool function with something like this: bool isBreakoutCandle = isPullback[1] && High[0] > High[1], I get a "cannot apply indexing with [] to an expression of type bool. What would be a work around that?

    Thanks in advance.

    #2
    Hello snoinvest,

    Thank you for your post.

    Is isPullback a bool? This would likely be why you are getting the error if this is the case, bools can only contain true or false values. Indexing [] can only be applied to things like series.

    You could instead define it as a custom Series<bool> which would hold a collection of true/false values. Then you could store a true or false value for every bar, and access it via indexing i.e. isPullback[0] for the current bar processing, isPullback[1] for the previous bar, etc.



    Please let us know if you have any further questions.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    128 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    74 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    116 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    110 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    89 views
    0 likes
    Last Post CarlTrading  
    Working...
    X