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

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.
    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by trilliantrader, 04-18-2024, 08:16 AM
    4 responses
    18 views
    0 likes
    Last Post trilliantrader  
    Started by mgco4you, Today, 09:46 PM
    1 response
    7 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by wzgy0920, Today, 09:53 PM
    0 responses
    9 views
    0 likes
    Last Post wzgy0920  
    Started by Rapine Heihei, Today, 08:19 PM
    1 response
    10 views
    0 likes
    Last Post NinjaTrader_Manfred  
    Started by Rapine Heihei, Today, 08:25 PM
    0 responses
    10 views
    0 likes
    Last Post Rapine Heihei  
    Working...
    X