Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
NT7 - Strategies not fully isolated and disabling each other when using Add() for FX
I have developed a risk positioning feature inside my Ninjatrader strategy for FX that calculates the lot-size for my strategy.
I have finished the risk positioning part of my strategy for Forex, that allows for correct calculation of the amount of units of a FX currency-pair to trade based on the TickValue, PointValue, stopLinePrice, entryLinePrice and a Risk_parameter (initially 0.1% - 3% risk).
It works great, BUT when I am running this code on a different chart (different currency pair), then once an order is being triggered on the second chart, it cancels out the orders on the first chart. This means that my strategies are not being isolated from each other.
I have used the function Add() inside Initialize() to add other currencypairs for this FX lot-size calculation.
The ONLY time this strategy is working, is when my second chart is running on the exact same currency pair, but as soon as I open a new chart with a different currency pair, then unfortunately the new chart with my strategy execution interferes with my previous charts running the same strategy. I think it has something to do with the Add() function and how all my potential currency pairs are loaded each time I open my strategy.
I have re-created this problematic behavior in both my eSignal datafeed as well as my Simulated datafeed.
This is my function for adding all currency-pairs for my risk positioning calculation:
LoadAllCurrencyPairs(int minute_chart) is being triggered from within Initialize() as:
this.LoadAllCurrencyPairs(1);
A summary of HOW the erroneous behaviour occurs:
I run 2 independent charts on 2 different currency pairs running my strategy.
Chart 1 got an order entry.
When entry on chart number 2 is enabled, it enters its Deactivation() function in my strategy on Chart 2 ( I use a message box for debugging), that disables the strategy on Chart 1.
In other words, after Chart 1 is in position and when Chart 2 enables its entry then the strategy in Chart 1 is disabled from the code in my strategy on Chart 2, but there is NO message box showing up on Chart 1.
I added this message box for debugging purposes.
Also noticed:
When I have a chart number X running my strategy that has taken an entry position, and then I go to my Positions tab and Close an open position I entered manually before, than this close ALSO disables my strategy in chart X
Also noticed:
WHEN, and only WHEN I run my strategy on 2 or more charts using the very same currency pair (Barsinprogress==0) then this erroneous behaviour does NOT appear.
It only appears when I use different chart windows with different currency pairs.
My thoughts:
What this means is that the strategies are NOT fully isolated, and I think this has something to do with HOW I add the other currency pairs into my primary barsinprogress==0 chart. I have attached the function that adds my other currency pairs (barsinprogress !=0) in this thread.
Maybe the problems occurs when I open a new chart with a currency pair that has been already opened as a secondary currency pair in the first chart through my Add() function?!?
Can you help answer these questions from other members on NexusFi?
After putting MessageBoxes everywhere where the CancelAllOrders() native functions is being called I found out that it is inside OnPositionUpdate() in my code that the CancelAllOrders() function is being called that cancel my other strategies:
The "Deactivation" logic and code is below, and it does NOT intentionally disable other strategies. What happens is that when my first chart window, trading a currencypair is being activated and gets an entry, then when I open a different chart, trading a different currencypair. When this 2:nd chart gets an entry, then somehow it goes to Deactivation() function in strategy running on chart 2, and suddenly disables the 1:st chart window and strategy, so it stops working. As I explained above, it is almost like these strategies somehow effect eachother. BUT, this behaviour does NOT happen if I open a second chart using the same currencypair as I used on the first chart.
Let me know if this makes sense?
After doing further debugging I have replaced CancelAllOrders() with CancelOrder() as CancelAllOrders() is NOT supported in NT7, and it is still NOT working, and I get the very same erroneous behaviour using CancelOrder(), this is how my new SetNotActive() function looks like where this problem occurs predominantly.
if (_currentExitOrder50 != null) CancelOrder(_currentExitOrder50);
if (_currentExitOrder75 != null) CancelOrder(_currentExitOrder75);
if (_currentExitOrder100 != null) CancelOrder(_currentExitOrder100);
if (_currentExitOrderOther != null) CancelOrder(_currentExitOrderOther);
if (_currentExitOrderSTOP != null) CancelOrder(_currentExitOrderSTOP);
BUT, can I really use CancelOrder() IF I am ONLY using market order type throughout my strategy and NOT limit order type for all my orders?
I am only using EnterLong(), EnterShort() together with ExitLong() and ExitShort() functions in my strategy due to the previous problem with incompatibility problems between using eSignal as preliminary datafeed and then placing LimitOrders through Ninjatrader7 and executing them through FXCM. This did NOT work at all unfortunately!