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 andrewtrades, Today, 04:57 PM
        1 response
        8 views
        0 likes
        Last Post NinjaTrader_Manfred  
        Started by chbruno, Today, 04:10 PM
        0 responses
        6 views
        0 likes
        Last Post chbruno
        by chbruno
         
        Started by josh18955, 03-25-2023, 11:16 AM
        6 responses
        436 views
        0 likes
        Last Post Delerium  
        Started by FAQtrader, Today, 03:35 PM
        0 responses
        7 views
        0 likes
        Last Post FAQtrader  
        Started by rocketman7, Today, 09:41 AM
        5 responses
        19 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Working...
        X