Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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 cmtjoancolmenero, Yesterday, 03:58 PM
    4 responses
    23 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by Brevo, Today, 01:45 AM
    1 response
    14 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by rjbtrade1, 11-30-2023, 04:38 PM
    2 responses
    73 views
    0 likes
    Last Post DavidHP
    by DavidHP
     
    Started by suroot, 04-10-2017, 02:18 AM
    5 responses
    3,021 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by Stanfillirenfro, Today, 07:23 AM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Working...
    X