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

Consecutive Losers in Strategy Question

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

    Consecutive Losers in Strategy Question

    Hey guys, quick question. I download the file "SampleTradeObjects" from Forum here. and its great, because it Stop Strategy after 3 Consecutive losers. However, it won't allow trading again until New session.

    Any suggestion on what logic I can write that after the "Stop Strategy" after the 3 consecutive Losers becomes True. That the "lastThreeTrades" counter can become 0 if I manually reset the strategy.

    Basically, I want the Strategy to STOP after 3 losers (which I already have), but I want to be able to come in and turn it on again.

    any ideas?
    Attached Files

    #2
    Hello,

    In the code the lines:

    if (Bars.FirstBarOfSession && FirstTickOfBar)
    {
    lastThreeTrades = 0;
    priorSessionTrades = Performance.AllTrades.Count;
    }

    is where lastThreeTrades is reset to 0.

    You would need to be able to reset this. You could add logic that if lastThreeTrades > 2 && Position.MarketPostion == MarketPosition.Flat and reset it as well. This would reset after 3 trades and the position was flat.

    Or you could make a button and reset it with a button..


    The idea is, you want to set lastThreeTrades to 0 when you want to reset.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes I agree about the resetting to 0. but you mentioned something interesting. about the "Button" any more info on how to do that? that would make it easier.

      Comment


        #4
        Hello ginx10k,

        Below is a link to an example that demonstrates a button.
        http://www.ninjatrader.com/support/f...tid=-1&lpage=1

        Officially, buttons are not supported in NinjaTrader, but they are possible.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          thanks. 2nd question. Does the
          "AllTrades" in a strategy Check Only for Trades that occur on one chart that the strategy is on. or does it check for Every trade on every chart?

          (i.e.: Lets say I had another strategy that loss 2 trades in EUR/USD, but my current strategy was on GBP/USD and loss 1.

          Do they combine to equal a Loss of 3. or is it only per strategy per chart?

          Comment


            #6
            Hello ginx10k,

            AllTrades refers to the trades by that instance of the strategy. (If you had two of the same strategy on the same chart, they would be independent)
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Thanks for your help.

              I do have another question though. How do I make my Strategy Close all Current Trades and Cancel All Limit/Stop Orders if ("anything I want happens"); ?

              I tried
              Code:
              if("something") 
              setVariable = true; 
              return;

              but When another condition comes true and makes that variable set to True the strategy continues Trading.

              Comment


                #8
                Hello ginx10k,

                You can trigger the flatten everything and this would close all trades, cancel all orders, and disable all scripts.

                Or if you do not want to disable the script and flatten everything you can do the everything with code. This would involve checking your position and close it if there is one, and keep trades in IOrders so that you can cancel these if they are working.

                if (/* condition to close */)
                {

                if (Position.MarketPosition == MarketPosition.Long)
                ExitLong();

                if (Position.MarketPosition == MarketPosition.Short)
                ExitShort();

                if (myOrder != null && (myOrder.OrderState == OrderState.Working || myOrder.OrderState == OrderState.Accepted)
                CancelOrder(myOrder);
                }
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  I typed "Flatten Everything" in Ninja Guide. can't find it. how does the command Look?

                  Comment


                    #10
                    Hello ginx10k,

                    Calling flatten everything from a script is not supported to do so you will not find this in the help guide.

                    The code is something like;
                    NinjaTrader.Gui.SuperDom.SuperDom.FlattenEverythin g();

                    Again this is unsupported and we cannot assist with using this.
                    Last edited by NinjaTrader_ChelseaB; 03-27-2015, 07:12 AM.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hello ginx10k,

                      You can check the order state in OnExecution or OnOrderUpdate and if the order is filled cancel the second order.

                      private IOrder entryOrder1;
                      private IOrder entryOrder2;

                      protected override void OnExecution(IExecution execution)
                      {
                      if (execution.Order == entryOrder1 && entryOrder1.OrderState == OrderState.Filled)
                      {
                      CancelOrder(entryOrder2);
                      }
                      }
                      }
                      Chelsea B.NinjaTrader Customer Service

                      Comment


                        #12
                        Thanks

                        Thank you Chelsea

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by cre8able, Yesterday, 01:16 PM
                        3 responses
                        11 views
                        0 likes
                        Last Post cre8able  
                        Started by ChartTourist, Today, 08:22 AM
                        0 responses
                        6 views
                        0 likes
                        Last Post ChartTourist  
                        Started by LiamTwine, Today, 08:10 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post LiamTwine  
                        Started by Balage0922, Today, 07:38 AM
                        0 responses
                        5 views
                        0 likes
                        Last Post Balage0922  
                        Started by JoMoon2024, Today, 06:56 AM
                        0 responses
                        6 views
                        0 likes
                        Last Post JoMoon2024  
                        Working...
                        X