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 set max losing / winning trades

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

    How to set max losing / winning trades

    Hi there. Im trying to build my strategy using the strategy builder. Ive tried to find a way to set a numeric quantity for losing trades and winning trades, but still nothing. I want my strategy to stop working when it reaches 1 losing trade, or two winning trades. Since the loss and the profit vary (it's not always the same amount of money) i dont want to set it in a currency mode. I want to create an input where I can set ''1 losing trades max'' or ''two winning trades max''. I dont want the ammount of money lost or won to matter but the outcome of the taken trades. I have almost zero knowledge on C#. I thought this could be a while loop but I have no idea how to do it. If theres a way to do it through the strategy builder wizard, Id like to know. Thank you.

    #2
    Hello camtrading,

    Welcome to the NinjaTrader forums!

    This will take some custom coding.

    My recommendation would be to use a counter integer. On each new order increment the counter. In the condition to place the new order require the counter to be less than the number you would like. This would not be something that could be done in the strategy builder, as this would require incrementing the integer.

    Below is a link to some example code of using a counter.


    Also, below is a link to a forum post with helpful information about getting started about NinjaScript.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi camtrading,
      This reminds me of my early days in NinjaTrader. With NinjaScript, this is very easy and with an incrementing counter only takes a few lines of code.
      However, as long as you are not yet familiar with NinjaScript, you can try to manually achieve this in StrategyBuilder.
      Not nice, but at least doable as long as the number of max. Winners and max. Losers are pretty low.
      You will need a few variables, including Winners, Losers and a few "Sets" of conditions. Here is the idea.
      (Only) If RealizedPnL is not equal to your variable dRealizedPnL, a new trade was closed. If RealizedPnL > dRealizedPnL, you have a winner (and vice versa).

      If you have a winner and
      Winner is 0,
      set dRealizedPnL to RealizedPnL,
      set Winner to 1,

      If you have a winner and
      Winner is 1,
      set dRealizedPnL to RealizedPnL,
      set Winner to 2,
      ...

      If you have a loser and
      Loser is 0,
      set dRealizedPnL to RealizedPnL,
      set Loser to 1,

      If you have a loser and
      Loser is 1,
      set dRealizedPnL to RealizedPnL,
      set Loser to 2,
      ...

      In your entry conditions, (also) check if Winner and Loser are below your respective limits before entering a trade.
      If you have reached your limit, determine how long to pause and when to reset Winner and Loser to 0.
      If condition for reset is true (example: new Day) and Winner or Loser are greater or equal to their limit, reset them to 0 and start over again.

      Add Prints to your code to see how the variable dRealizedPnL, Winner and Loser are updated on the fly. Illustrative example attached.
      Give it a try and have fun.
      NT-Roland
      Attached Files

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Rapine Heihei, Today, 08:19 PM
      1 response
      8 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by Rapine Heihei, Today, 08:25 PM
      0 responses
      6 views
      0 likes
      Last Post Rapine Heihei  
      Started by f.saeidi, Today, 08:01 PM
      1 response
      9 views
      0 likes
      Last Post NinjaTrader_Manfred  
      Started by Rapine Heihei, Today, 07:51 PM
      0 responses
      8 views
      0 likes
      Last Post Rapine Heihei  
      Started by frslvr, 04-11-2024, 07:26 AM
      5 responses
      98 views
      1 like
      Last Post caryc123  
      Working...
      X