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 Tim-c, Today, 03:54 AM
        0 responses
        3 views
        0 likes
        Last Post Tim-c
        by Tim-c
         
        Started by FrancisMorro, Today, 03:24 AM
        0 responses
        2 views
        0 likes
        Last Post FrancisMorro  
        Started by Segwin, 05-07-2018, 02:15 PM
        10 responses
        1,771 views
        0 likes
        Last Post Leafcutter  
        Started by Rapine Heihei, 04-23-2024, 07:51 PM
        2 responses
        31 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by Shansen, 08-30-2019, 10:18 PM
        24 responses
        945 views
        0 likes
        Last Post spwizard  
        Working...
        X