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 NullPointStrategies, Today, 05:17 AM
    0 responses
    44 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    65 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    42 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X