Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can't figure out why position is not getting closed?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Can't figure out why position is not getting closed?

    Two scripts are running with several instruments on two sub-accounts...
    Market position of first script is transferred to second:
    first script:
    public class Trade1 : Strategy
    #region Variables
    ...
    public static double MyProfit1;
    public static double ExitAll;
    #endregion
    protected override void OnBarUpdate()
    {
    ...
    MyProfit1 = GetCurrentBid() - Position.AvgPrice;
    if (MyExitAll==1) ExitLong(Position.Quantity);
    }


    second script:
    public class Trade2 : Strategy
    ...
    protected override void OnBarUpdate()
    {
    MyProfit2 = GetCurrentBid() - Position.AvgPrice;
    ...
    if (Trade1.MyProfit1 + MyProfit2 >= targetProfit0 * TickSize)
    {ExitShort(Position.Quantity); Trade1.MyExitAll=1;}
    }

    Any ideas? Wanted to know if it is correct to use global declarations like that? Does it work this way? Positions are getting opened but script doesn't want close them even if Target Profit is reached...

    Any help is highly appreciated.

    #2
    greed999, NinjaTrader strategies are designed to work completely independent of each other. It could be possible to use some sort of global variable to share information, but that would be unsupported. I have seen it working before though, you'll have to code up one strategy as the master and another as the slave/client and run pretty much everything through the master strategy. There are other solutions of course, such as reading/writing information to a database/flat text file, or using Windows forms.

    Please let me know if you have any other questions.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Austin View Post
      you'll have to code up one strategy as the master and another as the slave/client and run pretty much everything through the master strategy. There are other solutions of course, such as reading/writing information to a database/flat text file, or using Windows forms.

      Please let me know if you have any other questions.
      Thank you, Autin, for your response! You guys are very quick and attentive. Text file is way too slow... I'm thinking of DB but again have some fears that performance might be compromised... Windows forms - sounds nice bit it requires lots of declarations and variables and etc... The script would be quite "heavy" i think...

      Thats the way my strategy works: 2nd orders 1st script what to do... I do understand all pros and cons... nevertheless, can I check if parameters are passed somehow? Some sort of built in debug? Or you are suggesting that I use text for testing purpose?.. I'll try

      Comment


        #4
        greed999, the suggested method of debugging is to use the Print() method to send text to the output window (Tools -> Output Window). However, you can connect NinjaTrader to Visual Studio for debugging purposes.
        AustinNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        85 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        48 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        29 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        32 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        67 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X