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

Play audio after 3 consecutive winning/losing trades

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

    Play audio after 3 consecutive winning/losing trades

    Hi,
    I've never using NinjaScript before. I am wondering if it is possible to play a specific wav file every time an order is filled and it is the 3rd winning or losing trade in a row.

    Example: I placed 3 orders and they all get stopped out play [losing.wav] file. If I get stopped out again keep playing [losing.wav] file when order is filled.

    #2
    Thank you for your question, .


    This is possible through NinjaScript.


    • You can track the number of winners or losers in a row in a private Integer variable. These are available through the Strategy Builder in the Inputs and Variables tab. Remember to reset this to 0 if you play a sound, if this value is less than one and the current trade is a winner, or if this is greater than 1 and the current trade is a loser.
    • To tell whether a trade is a winner or a loser, we have some example code here, https://ninjatrader.com/support/foru...ead.php?t=4084
      • The above won't work if you are using the Strategy Builder. In that case you will need to
        • Create a double variable in the Inputs and Variables tab with a name like LastPnL
        • In your last condition set, as an Action, Misc -> Set LastPnL to Strategy -> Realized PnL
        • In any condition set before this you can now compare LastPnL to RealizedPnL


    • To play a sound you can use the example code for PlaySound here. This is also available through the Strategy Builder. https://ninjatrader.com/support/help...?playsound.htm

    Since you mentioned being new to NinjaScript, I recommend attending the Strategy Builder 301 webinar. While this will not require you to do direct coding, the code you generate this way will make it easy to understand how to write your own scripts. That webinar can be found here,



    Watch daily livestreams to learn how to trade futures. Tune in as NinjaTrader experts provide futures market analysis and trading tips. Join us today!
    Jessica P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for provide that. I have a basic strategy working but I want to make it run slightly different. I am wondering if the following is possible?

      1. Make my code run after I manually enter/exit positions using the dom. I've tried OnPositionUpdate/OnOrderUpdate/OnExecutionUpdate but they aren't being called after I manually place trades from the dom.
      2. Keep the strategy enabled after i click "close" on the dom. Currently everytime i click "close" the strategy becomes disabled and stops running.

      thanks

      Comment


        #4
        Hello trader252,

        Strategies are not able to see orders or positions that are made to the account outside of that instance of the strategy. The account position and orders are always separate from the strategy position and orders.

        With NinjaTrader 8 you can use an addon instead of using a strategy and attach an event handler method to the <account>.PositionUpdate event (or <account>.OrderUpdate, <account>.ExecutionUpdate) events.

        Below are public links to the NinjaTrader 8 help guide.




        This is not documented or supported for NinjaTrader 7, however, some users have used undocumented code to attach handlers to account events.


        It will not be possible to prevent a strategy from being closed when clicking the Close button or File > Flatten Everything in NinjaTrader 7.
        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by yertle, Today, 08:38 AM
        5 responses
        14 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by frankthearm, Today, 09:08 AM
        2 responses
        4 views
        0 likes
        Last Post frankthearm  
        Started by adeelshahzad, Today, 03:54 AM
        3 responses
        16 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by bill2023, Yesterday, 08:51 AM
        6 responses
        27 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by NinjaTrader_ChelseaB, 01-08-2017, 06:59 PM
        80 responses
        19,667 views
        5 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X