![]() |
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: Feb 2008
Location: Wellsville, Ut
Posts: 81
Thanks: 0
Thanked 0 times in 0 posts
|
Hi,
I've used the Sample Price Modification strategy code to have an autostrategy stop trading if it accumulated X amount of Real PnL. ie, quit trading if Real PnL > $100. Now I have an autostrategy calling an ATM and the Real PnL stop trading limit doesn't work. It looks like the Real PnL is attributed to the ATM it calls instead of the strategy itself, so the strategy doesn't see any Real PnL and just keeps on rolling. Is there a way to still have the autostrategy quit trading after X PnL with an ATM being called? I guess it would have to be able to add up the ATM Real PnL and recognize that somehow ???? If so, how would you do that? Thanks, Joe |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
|
Hi Joe, you could try incorporating GetAtmStrategyRealizedProfitLoss() in your code and use this to check - http://www.ninjatrader-support.com/H...rofitLoss.html
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#3 |
|
Member
Join Date: Feb 2008
Location: Wellsville, Ut
Posts: 81
Thanks: 0
Thanked 0 times in 0 posts
|
Thank Bertrand,
Looks like the example shows a Print function. I'll play with it and see if I can make it turn into a value I can use in the strat so it won't trade if the value is > some amount. The explanation in the Help Guide says what it does but not how to use it. I guess it's for more experienced programmers. Joe |
|
|
|
|
|
#4 |
|
Member
Join Date: Feb 2008
Location: Wellsville, Ut
Posts: 81
Thanks: 0
Thanked 0 times in 0 posts
|
Hey Bertrand,
Sorry to bother you, but I can't seem to get it to work. I used examples of a similar nature but to no avail. Would you mind looking at this code and see if there's something obviously wrong or missing? Under Variables (realPnL defined) private double realPnL = 90.000; private string atmStrategyId = string.Empty; private string orderId = string.Empty; Under OnBarUpdate (I defined PnL to compare against realPnL. Is the GetAtm statement correct? 2 Point is name of the ATM strategy which I assume is the ATM strategyID.) double PnL = GetAtmStrategyRealizedProfitLoss("2 Point"); // Check for valid condition and create an ATM Strategy // Condition set 3 if (ToTime(Time[0]) >= ToTime(7, 50, 0) && ToTime(Time[0]) <= ToTime(14, 0, 0) && PnL <= realPnL && Position.MarketPosition == MarketPosition.Flat && orderId.Length == 0 && atmStrategyId.Length == 0 && highestHigh > 0 && Close[0] > highestHigh) { atmStrategyId = GetAtmStrategyUniqueId(); orderId = GetAtmStrategyUniqueId(); AtmStrategyCreate(Action.Buy, OrderType.Limit, highestHigh, 0, TimeInForce.Day,orderId , "2 Point", atmStrategyId); } It's calling the ATM just fine and placing orders. I just don't want it to place any orders if the total realized PnL for the ATM on the day is greater than $90. Thanks, Joe |
|
|
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
double PnL = GetAtmStrategyRealizedProfitLoss("2 Point");
"2 Point" is not your strategyId. Please use your atmStrategyId. Position.MarketPosition == MarketPosition.Flat Does not work for ATM orders, designed for NinjaScript orders. Instead use this: http://www.ninjatrader-support.com/H...yPosition.html
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Member
Join Date: May 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
When i do this in my code all it returns is 0 no matter what the profit or loss for the days trading is.
Print("PnL is " + GetAtmStrategyRealizedProfitLoss("AtmStrategyId"). ToString()); What am i doing wrong? |
|
|
|
|
|
#7 |
|
Member
Join Date: Feb 2008
Location: Wellsville, Ut
Posts: 81
Thanks: 0
Thanked 0 times in 0 posts
|
Josh,
Where do I find the atmStrategyID? All I can find in Help is that one is generated. It doesn't say how to find it, or when it's generated. In the ATM Sample Strat code I copied, down where it calls the ATM after the conditions are met it says atmStrategyId = GetAtmStrategyUniqueId(); Do I simply put the Word atmStrategyId between the quotes? Or is there somewhere else I have to look for the atmStrategyId? IF this is the case and I can simply put the word atmStrategyId between the quotes, do you see anything else obvious that would prevent it from checking the realized PnL before calling the ATM and submitting another order? I can remove the marketposition = flat since I don't think it's really needed but it's good to have your reference link in case I do. Thanks!!!!! Joe |
|
|
|
|
|
#8 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
In your code:
"AtmStrategyCreate(Action.Buy, OrderType.Limit, highestHigh, 0, TimeInForce.Day,orderId , "2 Point", atmStrategyId);" You've made your own atmStrategyId. Yes, you just put atmStrategyId into there. It is the variable you made to hold your ID. You do not put it between quotes. You just put it inside the parenthesis with no quotes.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Member
Join Date: Feb 2008
Location: Wellsville, Ut
Posts: 81
Thanks: 0
Thanked 0 times in 0 posts
|
Thank You Josh!
And thanks for your explanation. It also cleared up something else. I guess I can make atmStrategyId anything I want it to say. It's starting to come together for me now. Again, many thanks!!! I'll give this a shot. Joe |
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
|
Hi Trade1953, you are correct. Or just use
Code:
GetAtmStrategyUniqueId()
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: May 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
What would cause it to return 0 no matter what trades the atm takes?
Print("PnL is " + GetAtmStrategyRealizedProfitLoss(AtmStrategyId). ToString()); What am i doing wrong? |
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,404
Thanks: 252
Thanked 973 times in 956 posts
|
Hi cirion, are sure you reference the correct AtmStrategyId? Also, you will not access to this historical values in the PnL with this call, you will need to save those yourself in a cumulative variable.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#13 | |
|
Member
Join Date: May 2008
Posts: 68
Thanks: 0
Thanked 0 times in 0 posts
|
Quote:
Code:
if (orderId.Length == 0 && atmStrategyId.Length == 0 && buypostion == true)
{
atmStrategyId = GetAtmStrategyUniqueId();
orderId = GetAtmStrategyUniqueId();
AtmStrategyCreate(Action.Buy, OrderType.Limit, Close[0], 0, TimeInForce.Day, orderId, "AutoATM", atmStrategyId);
exitbar = Close[0];
}
Code:
if (X == X)
{
Print("The current ATM Strategy realized PnL is: " + GetAtmStrategyRealizedProfitLoss(atmStrategyId));
}
|
|
|
|
|
|
|
#14 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
|
Realized profit won't show up until the trade has closed.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Member
Join Date: Feb 2008
Location: Wellsville, Ut
Posts: 81
Thanks: 0
Thanked 0 times in 0 posts
|
Josh,
I have pretty much the same issue as cirion does. My strat trades many times a day yet even after the profit threshold has been reached it just keeps trading. It's almost like it sees every trade as starting with a 0 profit. (I don't have a buy position = true requirement). Would you happen to have a working Sample Strategy that calls an ATM and has the "stop trading if X Realized PnL" working? "A picture is worth a thousand words". Thanks! Joe PS- I hope they are paying you well for dealing with frustrated beginners like me!! |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Unrealized and Realized PnL in points/pips and % in stead of only $ | whitegun | Suggestions And Feedback | 22 | 11-14-2008 05:54 PM |
| problems wit realized PnL | dedomraz | Miscellaneous Support | 9 | 09-23-2008 10:11 AM |
| ATM from script | MelbourneRich | Automated Trading | 1 | 09-19-2008 09:38 AM |
| ATM Strategy with Ninja Script | suitguy1 | Automated Trading | 1 | 07-22-2008 01:34 PM |
| Why did you remove "Realized + Unrealized PnL" from the Columns list? | shawnj | Market Analyzer | 7 | 05-28-2008 11:34 AM |