is enabled but when position was created by strategy that is applied to the chart it did not change to Exit Short?
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!
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
NinjaTrader
Strategy using PositionAccount vs Strategy Position
Collapse
X
-
Hello DTSSTS,
Thanks for your reply.
Sorry, I may not have been clear, I suggested using the strategy LongShortToolbar as an example of using buttons on the chart to accomplish your goals. The action of the buttons will only affect the orders with the strategy the buttons are in and would not affect any other strategy. You would have to incorporate the button coding into your code (or vice versa). The LongShorttoolsbars is basically an example of how to create/add buttons and then use their actions within a strategy context.Paul H.NinjaTrader Customer Service
Comment
-
PaulH In my indicator development with buttons to trade a secondary instrument with some help from NinjaTrader Staff (you I believe) we came up with this for entries
Order mar****rder = account.CreateOrder(NinjaTrader.Cbi.Instrument.Get Instrument(Symbol2), OrderAction.Buy, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, DefaultQuantity, 0, 0, string.Empty, "Long2 conditional", new DateTime(), null);
account.Submit(new Order[] { mar****rder });
works as expected
I am now adding a button for exits and have 2 issues I have not resolved with about 20 different approaches here is what i have for exit which i believe will work BUT I WOULD LIKE TO CHANGE DefaultQuanitity to current position of that secondary instrument AS we might scale in after initial DefaultQuantity and position would be a greater number of contracts. I have tried many replacements for the code DefaultQuantity without success
Order mar****rder = account.CreateOrder(NinjaTrader.Cbi.Instrument.Get Instrument(Symbol2), OrderAction.Sell, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, DefaultQuantity, 0, 0, string.Empty, "", new DateTime(), null);
account.Submit(new Order[] { mar****rder });
2nd issue is I would also like to have the exit include condition to insure there is an Open Position before the Exit order can be triggered. without that then the button could actually create another unwanted position
Again i have tried many unsuccessful attempts and research many help guide pages without success - below are some of those
// && NinjaTrader.NinjaScript.Alert.AlertCallback(NinjaT rader.Cbi.Instrument.GetInstrument(Symbol2) == (NinjaTrader.Cbi.Position.MarketPosition.Long))
// && NinjaTrader.NinjaScript.Alert.AlertCallback(NinjaT rader.Cbi.Instrument.GetInstrument(Symbol2) == (NinjaTrader.NinjaScript.Alert.AlertCallback(Ninja Trader.Cbi.Position.MarketPosition.Long))
// && (((NinjaTrader.Cbi.Position.MarketPosition) Instrument.GetInstrument(Symbol2))) == (NinjaTrader.Cbi.Position.MarketPosition.Long)
// && (((NinjaTrader.Cbi.Position.MarketPosition.get) Instrument.GetInstrument(Symbol2))) == (MarketPosition.Long)
// && (NinjaTrader.Cbi.Position.MarketPosition == NinjaTrader.Cbi.Position.MarketPosition.Long)
Thanks for any assistance
Comment
-
Hello DTSSTS,
Thanks for your post.
NinjaTrader_Chris will be responding to your e-mail where you are asking similar if not the same questions.
Account.CreateOrder() and account.submit would create orders that are not part of a strategy and would not exist in the strategy. "DefaultQuantity" is a strategy property.
If you are wanting to work with a strategy framework then you can use the managed approach Entry/exit methods and Position.QuantityPaul H.NinjaTrader Customer Service
- Likes 1
Comment
-
This is an indicator with buttons on the chart. the examples from Chris do not show anything with NinjaTrader.Cbi yada yada yada and I have search for hours last night in the help guide and very little information is there as well. and nothing is addressing the secondary symbol - so I have no resolution to my issues
Thanks
Comment
-
yes with Position.Quantity my error is CS0120
An Object reference is required for the non-static field, method, or property 'NinjaTrader.Cbi.Position.Quantity.get'
I am just not familiar with that also likely needs to address the Symbol2 to check that quantity - any help appreciated
Order mar****rder = account.CreateOrder(NinjaTrader.Cbi.Instrument.Get Instrument(Symbol2), OrderAction.Sell, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, Position.Quantity, 0, 0, string.Empty, "", new DateTime(), null);
account.Submit(new Order[] { mar****rder });
2nd issue is I would also like to have the exit include condition to insure there is an Open Position before the Exit order can be triggered. without that then the button could actually create another unwanted position
thanks
- Likes 1
Comment
-
Hello DTSSTS,
Thanks for your reply.
I would suggest double-checking with a print statement that Symbol2 is the syntactically correct instrument name.
For the position side of thing, as you are working with the Account class, you will need to use Account.Positions. See the help guide for an example looping through positions: https://ninjatrader.com/support/help...ns_account.htm
foreach (Position pos in myAccount.Positions)
{
if (pos.Instrument == NinjaTrader.Cbi.Instrument.GetInstrument(Symbol2))
{
Print(pos.Quantity);
}
}
Paul H.NinjaTrader Customer Service
Comment
-
if (pos.Instrument == NinjaTrader.Cbi.Instrument.GetInstrument(Symbol2))
how does the above tell me if i have a Long Position
and yes Symbol2 is correct
this is my entry order and it works as expected, so how could Symbol2 not be correct
Order mar****rder = account.CreateOrder(NinjaTrader.Cbi.Instrument.Get Instrument(Symbol2), OrderAction.SellShort, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, DefaultQuantity, 0, 0, string.Empty, "Short2 conditional", new DateTime(), null);
account.Submit(new Order[] { mar****rder });
// }
and below is my short exit with DefaultQuantity as the Quantity, as i can get that to compile. but sometimes the default quantity is the the current position
Order mar****rder = account.CreateOrder(NinjaTrader.Cbi.Instrument.Get Instrument(Symbol2), OrderAction.BuyToCover, OrderType.Market, OrderEntry.Automated, TimeInForce.Day, DefaultQuantity, 0, 0, string.Empty, "Short2 Exit", new DateTime(), null);
account.Submit(new Order[] { mar****rder });
both of those work as expected
thanks
Comment
-
Hello DTSSTS,
Thanks for your reply.
"how does the above tell me if i have a Long Position"
t doesn't. It tells you that when you are looping through the account positions that the one you want will match your instrument.
Look at the help guide example I provided and look for position.MarketPosition.
"this is my entry order and it works as expected, so how could Symbol2 not be correct"
Sorry, I was under the impression it did not work.
Paul H.NinjaTrader Customer Service
Comment
-
OK not sure if this makes a difference but we have an input for the account in the indicator
account = Account.All.FirstOrDefault(a => a.Name == AccountNametoTrade);
and I am still not clear how to get something other that DefaultQuantity to compile , I guess are looking for Position.Quantity to compile (which presently will not
NEXT WHERE IN THE CODE DOES THE LOOP NEED TO BE LOCATE, ie State.DataLoaded or State.Configure etc
OR is it in the condition area with the other Exit condtiions
THIS CODE (am i suppose to change myAccount to AccountNametoTrade
foreach (Position pos in myAccount.Positions)
{
if (pos.Instrument == NinjaTrader.Cbi.Instrument.GetInstrument(Symbol2))
{
Print(pos.Quantity);
}
}
thanks
Comment
-
foreach (Position pos in AccountNametoTrade.Positions)
{
if (pos.Instrument == NinjaTrader.Cbi.Instrument.GetInstrument)
{
Print(pos.Quantity);
}
}
testing this WITHOUT a Secondary Symbol ie Symbol2
will not compile with error as below CS1061
'string does not contain a definition for 'Positions' and no extension method 'Positions' accepting a first argument of type 'string' could be found
the help guide link is just a menu, I cannot find anything about what you said "Look at the help guide example I provided and look for position.MarketPosition. "
thanksLast edited by DTSSTS; 12-12-2021, 03:26 PM.
Comment
-
Hello DTSSTS,
Thanks for your post.
Sorry about the link error, I have corrected it in post #24, here it is again: https://ninjatrader.com/support/help...ns_account.htm
Paul H.NinjaTrader Customer Service
Comment
-
Looking back to where you help me with this about a year ago
in State.SetDefaults area I have only 1 line of code
AccountNametoTrade = null;
THEN IN THE State.DataLoaded are I have
account = Account.All.FirstOrDefault(a => a.Name == AccountNametoTrade);
if (account != null)
account.OrderUpdate += Account_OrderUpdate;
************************************************** ****************************
I do not have what the example is showing about "lock" in any section
do i need to add in the State.SetDefaults area
lock (Account.All)
and/or in the State.DataLoaded area
lock (myAccount.Positions) <<--- in my case (AccountNametoTrade.Positions)
Thanks
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rocketman7, Today, 01:00 AM
|
1 response
9 views
0 likes
|
Last Post Today, 07:22 AM | ||
Started by wzgy0920, 04-23-2024, 09:53 PM
|
3 responses
76 views
0 likes
|
Last Post Today, 07:22 AM | ||
Started by JonesJoker, 04-22-2024, 12:23 PM
|
9 responses
46 views
0 likes
|
Last Post Today, 07:21 AM | ||
Started by timko, Today, 06:45 AM
|
1 response
7 views
0 likes
|
Last Post
by gaz0001
Today, 07:18 AM
|
||
Started by Waxavi, 04-19-2024, 02:10 AM
|
3 responses
41 views
0 likes
|
Last Post
by gaz0001
Today, 07:14 AM
|
Comment