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 dpolyakov, 03-29-2024, 11:30 AM
    3 responses
    126 views
    2 likes
    Last Post sonia0101  
    Started by algospoke, 04-17-2024, 06:40 PM
    4 responses
    33 views
    0 likes
    Last Post algospoke  
    Started by RideMe, 04-07-2024, 04:54 PM
    4 responses
    22 views
    0 likes
    Last Post RideMe
    by RideMe
     
    Started by cre8able, 04-17-2024, 04:16 PM
    6 responses
    53 views
    0 likes
    Last Post cre8able  
    Started by samish18, 04-17-2024, 08:57 AM
    14 responses
    48 views
    0 likes
    Last Post samish18  
    Working...
    X