• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by vitrxotinusa, Yesterday, 11:56 PM
    0 responses
    5 views
    0 likes
    Last Post vitrxotinusa  
    Started by vitrxotinusa, Yesterday, 11:55 PM
    0 responses
    3 views
    0 likes
    Last Post vitrxotinusa  
    Started by vitrxotinusa, Yesterday, 11:53 PM
    0 responses
    4 views
    0 likes
    Last Post vitrxotinusa  
    Started by raymonds, Yesterday, 10:23 PM
    0 responses
    4 views
    0 likes
    Last Post raymonds  
    Started by Gbnowpes, Yesterday, 09:21 PM
    0 responses
    5 views
    0 likes
    Last Post Gbnowpes  
    Working...
    X