Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

ProfitTarget as difference between entry price and indicator value

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

    ProfitTarget as difference between entry price and indicator value

    Hi,

    I'm working on coding a strategy and having trouble with the profit target. Also couldn't find any similar threads.

    I'll use a made up up scenario for the sake of explaining. Let's say we enter a short trade when NQ is at 13,500.00 and the EMA is currently at 13,400.00. That would be a 400 tick difference.

    How would I code such a scenario where I want to use that amount as the profit target or set the profit target as entry price minus indicator value like the example above? Or even a multiple like....1.5 times the difference between entry price and current EMA value like Entry(13,500) - EMA (13,400) = 400 ticks*1.5= 600tick profit target.

    Thanks for any guidance. I've been trying to code this the following way to no avail....

    SetProfitTarget(CalculationMode.Ticks, (Position.AveragePrice-EMA[0]*1.5);

    #2
    Hello Deep_ITM_Puts,

    With Set methods, use CalculationMode.Price to set the order to a specific price and not to a distance in ticks.
    https://ninjatrader.com/support/help...ofittarget.htm

    Use a different variable name than EMA as this is already used for the EMA indicator and causes ambiguity.

    private EMA myEMA;

    myEMA = EMA(13);

    Print out 'Position.AveragePrice - myEMA[0] * 1.5' to see if this is the value you are looking for.
    Code:
    if (Position.MarketPosition != MarketPosition.Flat)
    {
    Print(string.Format("{0} | Position.AveragePrice: {1} - myEMA[0]: {2} * 1.5 = {3}", Time[0], Position.AveragePrice, myEMA[0], (Position.AveragePrice - myEMA[0] * 1.5)));
    }
    https://ninjatrader.com/support/foru...121#post791121

    Reset set methods before placing a new entry by calling the set method with a number of ticks, as these cannot be unset.

    Below is a link to an example ProfitChaseStopTrailSetMethodsExample_NT8 which demonstrates.
    https://ninjatrader.com/support/foru...269#post802269

    I am also including a link to a forum post with helpful resources on getting started with C# and NinjaScript.
    https://ninjatrader.com/support/foru...040#post786040
    Last edited by NinjaTrader_ChelseaB; 05-05-2022, 03:46 PM.
    Chelsea B.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

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