Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Look for a value different to zero

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

    Look for a value different to zero

    Hi

    I´m working with fractals and I want to place the sl at the previous fractal, This indicator only shows a value greater that 0 at the bar that has the fractal signal. So is there a way I can look for a value greater than 0 in previous bars.

    In the following example value of bwFractal1.Lower[0] is 0, I can´t find the way to know which previous bar has the value greater than 0.


    Code:
    EnterLong(Convert.ToInt32(Buyqty), "Buy1");
    Stop_Price1 = Position.AveragePrice - (Position.AveragePrice-(bwFractal1.Lower[0]));
    SetStopLoss("Buy1", CalculationMode.Price, Stop_Price1, false);

    #2
    Hello henryd333,

    Thanks for your post.

    The bwFractal indicator does not display a fractal on a current bar, it displays it on past bars because it needs to confirm the fractal by bars past it.

    You would need to loop through the last x bars to look for a non zero value, for example (lower fractal):

    for (int i = 0; i < 10; i++)
    {
    if (bwFractal1.Lower[i] != 0)
    {
    _lowerBarsAgo = i;
    Print (Time[0]+" Lower found at: "+Time[_lowerBarsAgo]+" "+bwFractal1.Lower[i]);
    break;
    }
    }

    In that example, once a non-zero value is found the loop breaks and _lowerBarsAgo is an int variable that holds the number of bars ago that the latest lower fractal occurred. You can then use the bars ago to find the Low price of that bar. You may or may not need to increase the loop lookback which I used 10.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    45 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    21 views
    0 likes
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    31 views
    1 like
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    50 views
    0 likes
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    42 views
    0 likes
    Last Post CarlTrading  
    Working...
    X