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 NullPointStrategies, 03-13-2026, 05:17 AM
    0 responses
    96 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    154 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    82 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    54 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    72 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X