Thanks.
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
How to stop multiple trades in the same direction
Collapse
X
-
How to stop multiple trades in the same direction
As the title states, Im looking to take a long, short, long, short, and so. The way my strategy works best is not allowing 2 longs in a row or 2 shorts in a row. Looking on information to best achieve this.
Thanks.Tags: None
-
Thanks for the reply. I have 1 entry per direction and unique entries on. I just double checked. And it is still happeneing. Just for clarification, I want my strategy check to see if last trade was a long, If it was, it cannot take a long until a short is taken. vice versa for shorts. also, i have ifFirstTickofBar set to true.
Comment
-
Hello, thanks for the follow up. If your entries have unique signal names then UniqueEntries will allow more than one entry in a given direction. EntryHandling.AllEntries should be used to keep the entry handling global and limit the entires to only one. You can use C# variables at the class level to save data from OnPositionUpdate and track your position:
Kind regards,
-ChrisL
Chris L.NinjaTrader Customer Service
Comment
-
I want my strategy check to see if last trade was a long, If it was, it cannot take a long until a short is taken. vice versa for shorts
Code:protected override void OnExecutionUpdate(Execution execution, string executionId, double price, int quantity, MarketPosition marketPosition, string orderId, DateTime time) { if (marketPosition == MarketPosition.Long &&&&; execution.IsExitStrategy) lastOrderPosition="long"; if (marketPosition == MarketPosition.Short &&&&; execution.IsExitStrategy) lastOrderPosition="short"; }
Code:if ( lastorderPosition != "Long" &&&& ??) //enter long if ( lastorderPosition != "Short" &&&& ??) //enter long
>> this is just a partial example of a way to do it...
Comment
-
Thanks. I was able to implement this in my code. Just had to figure out where to initilize lastOrderPosition. BUT the issue still persist.
A bit of background. I have an indicator that plots an arrow once an condition is met. This indicator calculates onPriceChange. I coded it so i can use it in a strategy. Now that I have a strat, which aslo caculates onPriceChange, it is taking on the initial trade and then immediately entering another trade. I assume its taking on another trade becuase the condition is still true within that same bar. Im thinking of ways to only allow 1 trade per bar. I've tried the following.
1. Creating a bool call tradeTaken -> true. Setting isFirstTickOfBar to true. and So on, discibed to me in this thread. https://forum.ninjatrader.com/forum/...times-in-a-row My stategy still enters a trade when it meets profit target or stop loss.
2. The method provided above.
3. created 2 bools. lastLong and lastShort. Defaulted to true. If long is taken, set lastLong to true and set lastShort to false. and vice versa for shorts. Each type of trade requires the opposite type of entry to be true in oder to enter a trade. This did not stop back to back trades.
Any input on the best way to only take that initial trade and disregard that the condition is still true would be helpful. Thanks
Im going to do this and test it out tonight. https://paul-ninjatrader.tinytake.co...Nl8xNDc5OTg3MgLast edited by amigatlin; 03-23-2023, 07:43 PM.
Comment
-
First, I would install the Microsoft Visual Studio 2019 Community (free): https://visualstudio.microsoft.com/vs/older-downloads/
Then, from the NT strategy builder, "generate" your strat.
Now, from the "NEW" menu, select "Ninja script editor"
This will open the script window.
Press the last button on the right, a weird VS symbol.
This will open VS and connect to NT.
Now open your strat from the list on the right side.
You now can easily edit your strat code (which is C#) and change it to suit your needs.
Try it, it does have a learning curve, but there are NT docs on the basics and various commands.....and you can see the existing strats, indicators, etc...
https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html
.Last edited by waltFX; 03-23-2023, 08:47 PM.
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by sdauteuil, 09-23-2021, 10:16 AM
|
4 responses
1,208 views
0 likes
|
Last Post Yesterday, 11:41 PM | ||
Started by agclub, 04-21-2024, 08:57 PM
|
5 responses
34 views
0 likes
|
Last Post
by agclub
Yesterday, 09:47 PM
|
||
Started by ESHunter, Yesterday, 08:06 PM
|
2 responses
18 views
0 likes
|
Last Post
by ESHunter
Yesterday, 09:27 PM
|
||
Started by ETFVoyageur, 05-07-2024, 07:05 PM
|
19 responses
150 views
0 likes
|
Last Post
by ETFVoyageur
Yesterday, 09:14 PM
|
||
Started by ETFVoyageur, 05-11-2024, 10:13 PM
|
3 responses
26 views
0 likes
|
Last Post
by ETFVoyageur
Yesterday, 09:08 PM
|
Comment