Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Profit calculation

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

    Profit calculation

    Question 1)

    If I have multiple entries:
    entry= sma>xyz {enter long}
    entry2 = sma > abc {enter long2}
    entry3 = sma > cvb {enter long3}

    when I

    Code:
    				SetProfitTarget(@"", CalculationMode.Percent, 0.01);
    will it calculate the profit based on average price of the above THREE entries? It seems it's calculating the profit based on individual entry price.

    Question 2)

    Instead of using
    Code:
    SetProfitTarget(@"", CalculationMode.Percent, 0);
    I created a condition:

    Code:
    Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) > 0.01
    ..if true, {exit}

    but the above also seem to behave erratically.

    My expectations are: if I have 3 different long entries, I want to calculate my profit target based on the average price of the three difference entries, then exit all at the same time, but instead, n8 seems to exit all of them at different times

    #2
    Hello calhawk01,

    Thanks for the post.

    Using SetProfitTarget() with no signal name will apply the profit target to each existing order/position individualy based upon the current market price and each average entry price individualy. To calculate a profit percentage based on the average price of your strategy position, you would have to get the AveragePrice from the Position class, calculate a target percentage based on that price, then once you have that percentage, you would use SetProfitTarget() to apply that target to your position. Using a signal name is the only way to have direct control of each order, so when using SetProfitTarget() with a signal name, you can specify custom stops for each order if they need to be different.

    More information on the Position class here (used to get average strategy position):
    https://ninjatrader.com/support/help.../?position.htm

    To debug your code and make sure everything is happenng the way you want, you can use Print() statements before and after entry/exit to make sure the calculations are producing expected results. Adding Print() statements can also help visualize the flow of control in your script. You can view the output of print statements via the NinjaScript output window (New>NinjaScript output)

    A short example:

    Code:
    OnBarUpdate(){
    
        
        
        Print("About to set profit target");
        if(myCondition){
            Print("Condition met for SetProfitTarget");
            SetProfitTarget(CalculationMode.Percent, myPercentage);
        }
    
        Print("About to exit long");
        if(Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]) > 0.01)
            Print("Condition met for Exit");
            Print(Position.GetUnrealizedProfitLoss(PerformanceUnit.Currency, Close[0]));
            ExitLong(3);
    
    }
    You can also use trace orders to give detailed information about orders and help you debug anything that might be going wrong at the time of order entry.

    Here is the help guide page on Trace Orders, you just have to set TraceOrders == true in State.SetDefaults to subscribe to trace orders.

    https://ninjatrader.com/support/help...raceorders.htm

    This forum post goes into more detail about trace orders:
    https://ninjatrader.com/support/foru...ead.php?t=3627

    Please see this post that goes into more detail about debugging your code:
    https://ninjatrader.com/support/foru...ead.php?t=3418


    If we may be of any further assistance, please let us know.
    Chris L.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by JTizz, Today, 01:20 PM
    0 responses
    4 views
    0 likes
    Last Post JTizz
    by JTizz
     
    Started by omermirza, Today, 12:39 PM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by mballagan, Today, 01:02 PM
    0 responses
    5 views
    0 likes
    Last Post mballagan  
    Started by larkmail, Today, 12:30 PM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Kate  
    Started by Danila, Today, 11:08 AM
    1 response
    11 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X