Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

how to store an entry price in a variable?

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

    how to store an entry price in a variable?

    is there a function to store an entry price in a variable that can be used for another calculation? For example, lets say I have an initial position in EURUSD at 1.5 and then I add to my position at 1.46 I want to hold on making any additional buys until price falls below(outside) the distance between my first entry and my second entry (.04) in order to keep from leveraging up too soon in a downturn.

    how do I store any particular entry price in a variable so it can be part of another calculation?

    #2
    Hello ShruggedAtlas,

    Thank you for the question.

    This could be accomplished in a few ways, the most accurate being the use of the OnExecutionUpdate override and Order variables.

    After defining a variable in the scope you wanted (private variable or local variable) you could use the value of either the Close price or the executions average fill price in your calculation. If you take a look at the examples in the following page you can see how the execution information can be used: https://ninjatrader.com/support/help...ub=onexecution

    In a script where the calculation is needed in other areas such as OnBarUpdate, you may want to use a private Order variable like the following:

    Code:
    private Order entryOrder;
    
    protected override OnBarUpdate()
    {
       if(entryOrder != null)
       {
            //do my calculation here
            Print(entryOrder.AverageFillPrice);
       }
    }
    
    protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId,DateTime time)
    {
      if (execution.Order.Name == "myEntryOrder")
          entryOrder = execution.Order;
    }
    As this would only work for one fill, you need to also reset the Order variable later in your logic. We have a more complete example of using order information in the following link: https://ninjatrader.com/support/help...and_onexec.htm

    I look forward to being of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by NullPointStrategies, Today, 05:17 AM
    0 responses
    29 views
    0 likes
    Last Post NullPointStrategies  
    Started by argusthome, 03-08-2026, 10:06 AM
    0 responses
    124 views
    0 likes
    Last Post argusthome  
    Started by NabilKhattabi, 03-06-2026, 11:18 AM
    0 responses
    64 views
    0 likes
    Last Post NabilKhattabi  
    Started by Deep42, 03-06-2026, 12:28 AM
    0 responses
    41 views
    0 likes
    Last Post Deep42
    by Deep42
     
    Started by TheRealMorford, 03-05-2026, 06:15 PM
    0 responses
    46 views
    0 likes
    Last Post TheRealMorford  
    Working...
    X