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 Mindset, 04-21-2026, 06:46 AM
    0 responses
    89 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by M4ndoo, 04-20-2026, 05:21 PM
    0 responses
    135 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by M4ndoo, 04-19-2026, 05:54 PM
    0 responses
    68 views
    0 likes
    Last Post M4ndoo
    by M4ndoo
     
    Started by cmoran13, 04-16-2026, 01:02 PM
    0 responses
    119 views
    0 likes
    Last Post cmoran13  
    Started by PaulMohn, 04-10-2026, 11:11 AM
    0 responses
    69 views
    0 likes
    Last Post PaulMohn  
    Working...
    X