![]() |
This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com
|
|||||||
| Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Member
Join Date: Jun 2012
Posts: 87
Thanks: 3
Thanked 1 time in 1 post
|
Can some one please help me figure out how to build a strategy that doubles position size after each lose. I already have a strategy and all I need to do is add another setting to it. Basically I just want to enter a position long and if I on the next trade I exit with a lose then double my position on the next entry and so on. So add a position size logic that always doubles current position (martingale style). Always loser sequence will be as follows; +1 -2 +4 -8 +16 -32 +64 etc.
|
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Hi relogical,
There's lots of ways you could do this. You'll just need to update an order quantity variable when there's a losing trade. You could work with TradePerformance class to get PnL for the last closed trade. Help for using this class is available in the following reference sample: http://www.ninjatrader.com/support/f...ead.php?t=4084 This can be simple or complex depending on your experience working with advanced event handlers and IOrder (to check for exit execution and update your variable then). A simple implementation that works with a conditional exit could look like this: Code:
if (exitConditions)
{
if (Position.GetProfitLoss(Close[0], PerformanceUnit.Points) < 0) //Gets unrealized PnL at time of exit.
customQuantity *= 2;
ExitLong();
}
EnterLong(customQuantity);
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Jun 2012
Posts: 87
Thanks: 3
Thanked 1 time in 1 post
|
How can I do this via the Strategy Editor?
|
|
|
|
|
|
#4 |
|
NinjaTrader Customer Service
Join Date: Sep 2009
Location: Denver, CO
Posts: 8,117
Thanks: 249
Thanked 418 times in 415 posts
|
Unfortunately you will have to work with code to have this level of control.
Ryan M
NinjaTrader Customer Service |
|
|
|
|
|
#5 |
|
Member
Join Date: Nov 2010
Posts: 59
Thanks: 1
Thanked 4 times in 2 posts
|
if(Performance.AllTrades.Count - 1 > 0 && Position.GetProfitLoss(Close[0], PerformanceUnit.Points)< 2.5 ){
OrderQuantity = Position.Quantity + AddPositionAtReversal ; } where you get the current position size from Position.Quantiy and the variable AddPositionAtReversal, then pass the OrderQuantity to EnterLong() or EnterShort() you can write some code to change the size of the AddPositionAtReversal based on the consolidation condition. you can go like 1, -2, +3 , -4 , +5 which I found is safer. if your pocket is deep, you can play aggresive martingale. |
|
|
|
|
The following 3 users say thank you to solvmatic for this post: |
|
|
|
#6 |
|
Junior Member
Join Date: Feb 2013
Posts: 11
Thanks: 2
Thanked 1 time in 1 post
|
I tried searching with no luck. Does anyone know if there is a sample strategy that includes a martingale system? I don't have a lot of experience with coding and I would like to see what a functioning version looks like, so I can try to add it to my strategy. Any help would be greatly appreciated.
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Position Size based on account size | Adamdetx | Strategy Development | 3 | 04-13-2012 09:10 AM |
| Dynamic Position Size | ciaranfryan | Strategy Development | 11 | 12-29-2010 07:59 AM |
| position size | junkone | Charting | 9 | 12-22-2010 06:48 AM |
| Overfill triggers market order doubling position size | adamus | Version 7 Beta General Questions & Bug Reports | 17 | 10-05-2010 03:55 PM |
| Recalculating position size based on account size, % risked and stop loss | clivehunt | Strategy Development | 18 | 03-22-2009 11:25 AM |