• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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,



    https://ninjatrader.com/Webinar/Strategy-Builder-301
    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.
        https://ninjatrader.com/support/help...tionupdate.htm
        https://ninjatrader.com/support/help...tionupdate.htm
        https://ninjatrader.com/support/help...rderupdate.htm

        This is not documented or supported for NinjaTrader 7, however, some users have used undocumented code to attach handlers to account events.
        http://ninjatrader.com/support/forum...967#post470967

        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 jrp2099, 01-19-2019, 11:20 AM
        3 responses
        24 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by jxz1995, 12-23-2018, 10:44 PM
        4 responses
        25 views
        0 likes
        Last Post NinjaTrader_PatrickG  
        Started by sergey_z, Today, 03:42 AM
        5 responses
        11 views
        0 likes
        Last Post NinjaTrader_PaulH  
        Started by U0000999, Today, 04:24 AM
        0 responses
        4 views
        0 likes
        Last Post U0000999  
        Started by lehula, 01-18-2019, 08:13 PM
        1 response
        17 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X