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

Position.AvgPrice

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

    Position.AvgPrice

    Hi Guys,
    just a technical question:
    During bar update process, I need to change dynamically stop orders, so I tried to follow two different approaches to valorize my actual position (p&l), the first is Position.AvgPrice-Close[0] or Close[0]-Position.AvgPrice if short, the second one is Position.GetProfitLoss(Close[0], PerformanceUnit.Points).
    Well, the question is: do the following methods get updated at the same time?

    For example, the code below does a partial exit with 2 different stop orders, when I apply it and when I've been executed limit, the first stop order is not cancelled till the end of the bar, while the second stop order, as the second limit one are placed, so during fast market as today under datas, I've been long 2 with 2 stop orders placed.
    I'm running the code with Calculateonbarclose=false.
    In this case which one is the best method I can use?
    That's a piece of code:
    Code:
    if (Position.MarketPosition == MarketPosition.Long){
    					if (Position.Quantity == ctr)
    					{
    					
    						ExitLongLimit(ctr/3, (Position.AvgPrice + target1), "1st Exit", "");
    						ExitLongStop(ctr, (Position.AvgPrice - stop), "1stStop", "");
    					}
    					else if (Position.Quantity == (ctr/3)*2)
    					
    					{
    						ExitLongLimit(ctr/3, (Position.AvgPrice + target2), "2nd Exit", "");
    					    ExitLongStop(Position.Quantity , (Position.AvgPrice - secondstop), "2ndStop", "");
    						
    					}
    Tnaks
    Marce

    #2
    Yes, both approaches will be updated at the same time yielding the same result.

    Based on your code and running tick by tick, you can have a window of time where you can have two stop orders working. This is because, as you stated, the first stop order will not be cancelled until the end of the bar yet, the new stop order is already working.
    RayNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Max238, Today, 01:28 AM
    2 responses
    26 views
    0 likes
    Last Post NinjaTrader_ChristopherJ  
    Started by Shansen, 08-30-2019, 10:18 PM
    25 responses
    949 views
    0 likes
    Last Post NinjaTrader_BrandonH  
    Started by JonesJoker, 04-22-2024, 12:23 PM
    8 responses
    41 views
    0 likes
    Last Post JonesJoker  
    Started by timko, Today, 06:45 AM
    0 responses
    4 views
    0 likes
    Last Post timko
    by timko
     
    Started by Waxavi, 04-19-2024, 02:10 AM
    2 responses
    39 views
    0 likes
    Last Post poeds
    by poeds
     
    Working...
    X