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

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 llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    10 views
    0 likes
    Last Post burtoninlondon  
    Started by AaronKoRn, Yesterday, 09:49 PM
    0 responses
    15 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Yesterday, 08:42 PM
    0 responses
    11 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Yesterday, 07:51 PM
    0 responses
    14 views
    0 likes
    Last Post strategist007  
    Working...
    X