• 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

Martingale Bet Sizing

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

    Martingale Bet Sizing

    Hi, converting from 15 years of Tradestation...

    I've used the search function extensively but didn't find anything. Does anyone know if there is a script to double down or implement martingale in nt or on this forum?

    Also, I just set up nt with a gain demo with 3 years of data to test on for free if anyone would like to know how.

    I was also just given a link to download forex data if anyone is interested. It will have to be merged extensively but it goes back to 2000.

    thanks.

    #2
    MP948, welcome to our forums! You can check into this thread here for ideas ( position size in general ) - http://www.ninjatrader-support2.com/...ad.php?t=11614
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Martingale Development

      Dear Sir or Madam,

      I want to thank you for assisting me on the Ninja Trader strategy during these last months.
      I want to inform you that I need your help regarding a Money management section which I believe after looking to different pages and people articles on this forum and elsewhere, unfortunately, without a solution.


      My money Management section will be a partial martingale strategy. Means it will keep doubling up the trade quantity when the previous trade is a loss and keep/come back to the same default quantity that I will enter first in my strategy after a win.

      Now, we all know martingale is not a good strategy if followed completely, as it exponentially increases your risk as T approaches infinity and P approaches 1. But what I want is just follow it for the first X trades to a point where my max loss is reached, then start over.

      For example:

      --------- 1 UNIT-------------------
      1st trade: 1 contract if it is loss than
      2nd trade: 2 contracts if it is loss than
      3th trade: 4 contracts if it is loss than
      4th trade: 8 contacts if it is loss
      5th trade: 16 contracts if it is a loss
      6th trade: 32 contracts if it is a loss “Stop the loop”
      7th trade: 1 contract


      All of the past trades as soon as it will be one win, it will come back to my initial default quantity I entered first which is “1 contact” in this case and by this a will recover all my past losses in the strategy.

      ***********************************
      I tried to create this code that I found from the internet, and solve the bugs in it.… but it didn’t work.
      If you can give me just the first 2 loops, means how to double after a loss and keep the same default quantity after a win I believe I can write the rest of 7 loops
      I really hope that you can help me with this subject. Please.

      I believe I created a good strategy in the last 8 months of work. This is my last piece of it.

      Here is an example of the code I found.

      int CalcQuantity()
      {
      int priorTradesCount=0;
      int priorProfit=0;

      priorTradesCount = Performance.AllTrades.Count;

      if (priorTradesCount > 2)

      {
      if (Performance.AllTrades[priorTradesCount-1].ProfitCurrency * Performance.AllTrades[priorTradesCount-1].Quantity > 0)
      {


      if (Performance.AllTrades[priorTradesCount-2].ProfitCurrency * Performance.AllTrades[priorTradesCount-2].Quantity > 0)
      {
      return3;
      }
      else
      {
      return2;
      }
      }
      else
      {
      return1;
      }
      }
      return1;
      }

      Comment


        #4
        Hello Yassine.Chetouani,

        Thank you for writing in.

        I have created a sample script attached to this post that will double your order quantity if the previous trade was a loser. Otherwise, it will change the quantity to 1 if a winner or if it broke even.

        Please, let me know if you have any questions.
        Attached Files
        Zachary G.NinjaTrader Customer Service

        Comment


          #5
          Mr.Zachary,
          Thank you so much,
          I will try it and answer you. I believe I can create the number of loops that I want for 6 losses consecutive ....
          I believe that I can do it alone now.
          I hope I will receive your help again if I need anything.
          Many many thanks Sir.

          Comment


            #6
            Dear Mr.ZacharyG,

            Thank you for giving time to consider this.

            I want to inform you that I tried to link my code to the order quantity management by creating the related order quantity 7 conditions from the file you sent me. somehow it doesn't work.
            Without the martingale or quantity management conditions the code works cause it is a simple one, so the problem is not with the platform nor the condition, I checked every other possibility, even create a very simple code considering condition by conditions with a close/open comparison , didn't work also, and I didn't have any other choice than contacting you again. So sorry for the disturb.

            Please, can you help me to figure out how to solve it. or how to link the conditions I created for order quantity to the buy/sell actions as I predict it might be the problem, I attached the full strategy "Nominal Bar" with this mail to give you more idea about what I am trying to do. next to the simplest code "Nominal Bar2", Please feel free to modify on my code I sent you.

            Besides, As I told you that after the 7th loop of the sequence the count should return to 0 since I will be loosing a lot of ticks and there is a possibility to recover after the trend changes so I wrote code lines that I wish you can check since you have more expertise in this subject..

            Feel free to ask any more details, I will be here to provide you more information if you need Sir.
            Thank you again.
            Yassine.
            Attached Files

            Comment


              #7
              This might help

              A couple of years ago I helped someone with this very thing on another forum. I don't remember too much from that long ago but apparently for some reason, I thought it was interesting enough to separate the Martingale functionality into a base class that you could apply to any strategy. If it will help, you're welcome to it. As far as how to hook it up into your strategy, I did do that for someone else on the same forum but it's a pretty complicated strategy. You can probably just go to the Martingale section to see what you have to do but the second file is a real, working example for what it's worth. Sorry there's so much to wade through.

              You'll need to know about inheritance but don't worry if you don't. Just look up "Object Oriented programming inheritance" in your favorite search engine and you can learn all you need in a couple of hours.

              This Martingale base class will double up on trades 4 times before it resets back to one. I'm not sure why we chose 4 but it probably had to do with how little money we would ever possibly want to lose. If you want it to go seven times, you can probably add that easily enough.

              All you really need to do is inherit from MartingaleBase and call the base class in OnInitialize(). You can then copy doLong() and doShort() exactly and in your code just call doLong() when your signals indicate long and doShort() when your signals indicate short.

              This was actually kind of fun to do...
              Attached Files
              Last edited by traderpards; 09-03-2016, 12:38 PM. Reason: Make it simpler

              Comment


                #8
                Dear Traderpards,

                Thanks so much for answering me in this short notice.
                I consulted your files, it seems some how more complicated than what I was expecting with reference to the first mail I got from NinjaTrader support team. to speak clear, ı couldn't understand very much what was in there. it seemed a more complicated code with extras.
                so if you accept to help with my case. Actually I attached my code in my previous mail Nominal bar.cs,
                is there any possibility that you can get a look into it and see if you can combine mine with your code using your knowledge, I am not a programmer so my code is very basic stuff unfortunately I developed myself from this forum. I am stuck since a while with this strategy. so the sequence is 1, 2, 3, 4, 6, 9, 14 and as after the 7th is a loss means 14 quantities, the condition of my strategy changes but still I enter with 21 quantities and return the count to 0. everything I tried to explain in the file.
                Please.

                Comment


                  #9
                  Hi Yassine,

                  I was actually drawn to this post by the words "Martingale" which means that you double up on the losers. I remembered that I did something like that for someone else a couple of years ago and wanted to offer you that. After I made my post, I noticed that you are doing something different.

                  I couldn't tell from your posts what is actually wrong with your strategy - what unexpected behavior are you seeing? I told my kid I'd do something with him after I finished this post so if you do that I'll see if I can do something later this afternoon. In the meantime, I swapped out that awful example in my previous post with a far simpler one. Hopefully you'll find that more useful.
                  Last edited by traderpards; 09-05-2016, 01:51 PM.

                  Comment


                    #10
                    Dear traderpards,

                    First of all thank you for your help, I won't accept to take more time from a kid to enjoy the company of his father, so you can answer to this whenever you will be free.
                    So, Actually I started with the martingale objective, I found out that after the 7th sequence which is necessary to my system to work. the quantity is bigger so that I can go broke, I tried to decrease the sequence with fibonacci series in place of martingale which still good, and I optimized it with the historical data of 8 months "manually" with excel sheets which took a lot of time. a week or so with more than 3 000 trades, to come out with the series 1,2,3,4,6,9,14,and 21, which might be working for me. I believe that if I can do martingale I can change it to my series. it is the same process.

                    Regarding your question. as soon as I put the strategy on test it takes just the first trade. that's all. no error no thing to mention
                    So, until NinjaTrader support team or you can help me to solve this problem by re-arranging the code if possible or telling me what to do, I do not have more choice than sit, drink coffee and try to figure out what you sent in the files... Many thanks again Sir, I wasn't expecting to have an answer in week-end. So...Thank you.

                    Best Regards,
                    Yassine.

                    Comment


                      #11
                      Originally posted by Yassine.Chetouani View Post
                      Dear traderpards,

                      First of all thank you for your help, I won't accept to take more time from a kid to enjoy the company of his father, so you can answer to this whenever you will be free.
                      So, Actually I started with the martingale objective, I found out that after the 7th sequence which is necessary to my system to work. the quantity is bigger so that I can go broke, I tried to decrease the sequence with fibonacci series in place of martingale which still good, and I optimized it with the historical data of 8 months "manually" with excel sheets which took a lot of time. a week or so with more than 3 000 trades, to come out with the series 1,2,3,4,6,9,14,and 21, which might be working for me. I believe that if I can do martingale I can change it to my series. it is the same process.

                      Regarding your question. as soon as I put the strategy on test it takes just the first trade. that's all. no error no thing to mention
                      So, until NinjaTrader support team or you can help me to solve this problem by re-arranging the code if possible or telling me what to do, I do not have more choice than sit, drink coffee and try to figure out what you sent in the files... Many thanks again Sir, I wasn't expecting to have an answer in week-end. So...Thank you.

                      Best Regards,
                      Yassine.
                      That isn't your problem. Well, it might be but first you have to get passed your strategy crashing when you load it because Performance.AllTrades.Count = 0 and you're trying to access an array object whose size is zero. In other words, when there aren't any trades yet, you can't try to get the ProfitCurrrency or Quantity from a null object. Likewise, if Performance.AllTrades.Count == 1, you can't try to find out what's in Performance.AllTrades.Count[2] because there isn't any object there.

                      I saw that in NominalBars2. Fix all of that and see if what you have will then work. I bet it might.

                      Comment


                        #12
                        Dear Mr.ZacharyG

                        I want to inform you that I did all the possibilities that was given to me for this order managing system, however I still have the same problem as I explained two days ago to a Mr. who wanted to help me.
                        Can you help me with the subject please.
                        Thank you.

                        Comment


                          #13
                          Hello Yassine.Chetouani,

                          Please take a look at lines in NominalBar2 where you are attempting to access Performance.AllTrades[Performance.AllTrades.Count - x] (where x is some number).

                          You will want to ensure that a value exists at that particular index before trying to access it. Your script does not have any checks before attempting to access these values, therefore you'll run into a runtime error.

                          As an example:
                          Code:
                          Print(Performance.AllTrades[Performance.AllTrades.Count - 1].ProfitCurrency);
                          What happens if I attempt to access the ProfitCurrency value of above when no trades have occurred?

                          Well, first, Performance.AllTrades.Count will be 0 since no trades have occurred.

                          0 - 1 = -1

                          The strategy attempts to access the ProfitCurrency value of Performance.AllTrades[-1].

                          The index -1 is out of bounds and your strategy will disable.

                          How do I prevent my simple example from disabling?
                          Code:
                          if (Performance.AllTrades.Count < 1)
                               return;
                          
                          Print(Performance.AllTrades[Performance.AllTrades.Count - 1].ProfitCurrency);
                          Why does this prevent a run-time error occurring? It prevents the run-time error occurring because the strategy is prevented from accessing an out of bounds index (-1). The print will only occur when at least Performance.AllTrades.Count is 1.
                          Zachary G.NinjaTrader Customer Service

                          Comment


                            #14
                            Thank you Mr.ZacharyG for your assistance
                            Actually I succeeded to create the strategy I was looking for my the help of one of your 3th parties.
                            It was difficult to modify the quantity of the trades, at a certain point I thought it was time for the experts to intervene,
                            By the way, I tried to open a new treat regarding an other subject. somehow the system gave me error that is not logical The following errors occurred with your submission:

                            "The message you have entered is too short. Please lengthen your message to at least 10 characters. "
                            which I added and it still give the same error again and again so I couldn't contact no one. the message is as below
                            -------------------------------------------------------------------------------------------

                            Dear Sir or Madam,

                            I want to inform you that I am using an indicator with Slope degree manually,which I decided lastly to develop a strategy to make it automatic,
                            After trying to call it via the ATM ninja trader to develop the strategy by creating entry points at some degrees that the indicator shows (negative, positive, at certain level)
                            Somehow I couldn't develop/link the strategy to the indicator, since the plot does not succeed to define the slope degrees, and I am asking if there is someone from your support team who can help me to solve this issue, I want to send him/her the indicator and the strategy I developed via mail so he/she can check my error and help me withe the subject if possible. Please...
                            I am really stuck here.

                            The rest, I believe I can do it by myself now, since I developed my abilities about Drawing, entering different type of trades, Order management and on execution process all this by your help in the past where I want to take this opportunity to thank you for all your past support.

                            Thank you,

                            ---------------------------------------------------------------------------
                            I knew that this post should be in the related subject section however I cannot post it.
                            Can you inform your IT guys about the posting issue, since I believe no one can send a message now.
                            Besides, can you forward it to the related person who can help me with the subject if possible, or if you accept to help, you can answer me via a new treat.
                            Thank you so much

                            Comment


                              #15
                              Hello,

                              There was a outage yesterday for maintenance, Could you try re posting your question in the appropriate NinjaScript forum here: http://ninjatrader.com/support/forum...isplay.php?f=6

                              Otherwise if you are unable to post or utilize your account, please email our platform support [at] ninjatrader dot com for further assistance.
                              JesseNinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by supermht, Today, 07:59 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post supermht  
                              Started by mohdhm, Today, 05:13 PM
                              1 response
                              12 views
                              0 likes
                              Last Post nkhoi
                              by nkhoi
                               
                              Started by 3lliot, Today, 05:55 PM
                              0 responses
                              2 views
                              0 likes
                              Last Post 3lliot
                              by 3lliot
                               
                              Started by Fargo, Today, 04:57 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post Fargo
                              by Fargo
                               
                              Started by Johnny Santiago, Today, 03:57 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post Johnny Santiago  
                              Working...
                              X