• 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 Benjaminf, Today, 02:21 PM
    0 responses
    5 views
    0 likes
    Last Post Benjaminf  
    Started by chrismcdermut, Today, 01:46 PM
    1 response
    6 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by dpolyakov, Today, 01:13 PM
    3 responses
    14 views
    0 likes
    Last Post dpolyakov  
    Started by tjendra, Today, 12:15 PM
    3 responses
    9 views
    0 likes
    Last Post tjendra
    by tjendra
     
    Started by lunardiplomacy, Today, 11:46 AM
    4 responses
    17 views
    0 likes
    Last Post lunardiplomacy  
    Working...
    X