Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Price "near" an indicator line

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

    Price "near" an indicator line

    Hi Team

    I'm working on a strategic logic where one of the conditions is the bar closing price Close[0] is "near" (price can be above/at/or below) the line of an indicator. "Near would be measured in Ticks, say within 10 ticks. For example, condition is met only if Close[0] is within X n. of ticks from say a EMA. I tried the below but it doesn't seem to work. Any thoughts on how to achieve this:

    else if (State == State.DataLoaded)
    {
    ...
    EMA1 = EMA(Close, 30);
    ..
    }

    protected override void OnBarUpdate()
    {
    ...
    if (MathAbs((Close[0] * TickSize) - (EMA1[0] * TickSize)) < 10) Enterlong()
    }

    Any thoughts on what's the issue of if there's a better way to achieve the result I'm looking for?

    Thanks!

    #2
    Hello sandman55,

    Thank you for the post.

    The first thing I can see here is the way you are doing the tick math, generally you would use something like the following to calculate a price in ticks:

    Code:
    Close[0] - 10 * TickSize
    That is the close minus 10 ticks. Your ema would be the same or

    Code:
    EMA1[0] - 10 * TickSize

    You could try something like the following:

    Code:
    double baseEma = EMA1[0]; 
    double upperBound = baseEma + 10 * TickSize;
    double lowerBound = baseEma - 10 * TickSize; 
    
    if(Close[0] >= lowerBound && Close[0] <= upperBound)
    {
       // price should be between the bands now
    }


    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Mindset, 04-21-2026, 06:46 AM
    0 responses
    90 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
    120 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