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

Status of a trade?

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

    Status of a trade?

    Folks, how can I tell the gain or loss of a trade? Suppose my code is:

    SetStopLoss(CalculationMode.Ticks, 4);
    SetProfitTarget(CalculationMode.Ticks, 4);
    EnterLong(1);

    Then, how can I tell if my Long was settled at a profit, or loss? Thanks,

    #2
    Hello Timmbbo,

    Thank you for your note.

    You could add the following code under OnBarUpdate, which will print to the output window whether the last trade filled was a stop loss or profit target, thus knowing if the trade was closed for a profit or loss.

    Code:
    	protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time)
    		{			
    			if(execution.Name == "Stop loss")
    			{
    				Print("your stop was filled");
    			}
    		        if(execution.Name == "Profit target")
    			{
    				Print("your Profit target was filled");
    			}
    			
    		}
    I have also attached a sample strategy demonstrating this.

    Please see OnExecutionUpdate section of our helpguide,


    Please let us know if you need further assistance.
    Attached Files
    Last edited by NinjaTrader_AlanP; 02-15-2017, 10:56 AM.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thanks, very helpful. How can I determine at what price I entered the trade at, and the price I exited the trade at? Cheers,

      Comment


        #4
        Hello Timmbbo,

        To see what price you entered at, you could assign your entry order an order Object for which you could print the value for. Please see, OnExecutionUpdate()


        For an example of doing the same but for your exit order, the following reference example provides an useful framework,

        Strategy: Using OnOrderUpdate() and OnExecution() methods to submit protective orders
        The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()


        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by kevinenergy, 02-17-2023, 12:42 PM
        115 responses
        2,699 views
        1 like
        Last Post kevinenergy  
        Started by prdecast, Today, 06:07 AM
        1 response
        4 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by Christopher_R, Today, 12:29 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by chartchart, 05-19-2021, 04:14 PM
        3 responses
        577 views
        1 like
        Last Post NinjaTrader_Gaby  
        Started by bsbisme, Yesterday, 02:08 PM
        1 response
        15 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X