Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Forex position in auto strategy

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

    Forex position in auto strategy

    Hello fellow traders,

    I'm test driving NinjaTrader FXCM demo at the moment. For the purpose of testing auto strategy, I use exactly the same strategy that I have been using on futures without any problem. However, when applied it on Forex, I noticed:

    1. when in a position, both short and long, the strategy tab didn't display the current position and average entry price;
    2. position tab showed the correct position, entry price and open P/L;
    3. I set exit on close, but all forex position didn't get exited on close, even after Friday's close. And It's Saturday now the positions are still there.

    I wonder if, in NinjaTrader, forex's position is handled differently than it does with futures position. And hence, what should I do to get position closed upon Friday session close? Don't want to hold position over the weekend.

    Any thoughts would be appreciated.

    TIA.

    Edit: I just checked the log: each time a new position was established, log file showed the correct position, quantity and direction. Each day at 30 seconds before 5pm "Exit on Close" handling started, as it's supposed to be, but no position exits.

    Also checked the execution against backtest, the entries were all correctly executed, but position just stays there, no exit ever executed. In my strategy I use:
    if position != flat then {if exit rule then exit}, and
    if position == flat then{if entry rule then enter},
    As I said above, exactly the same strategy works on futures for the last three months without any error. It seems to me that the exit rules are ignored, both from the strategy and from "exit on close" handling.
    Last edited by leizhenhua; 04-11-2015, 03:13 AM.

    #2
    Hello,

    You are correct that forex sessions are handled a bit differently. To mimic the Exit on Close behavior, I recommend adding a time filter into your code manually that will close the position at a certain time on Friday (4pm EST, for example). That should take care of the exit on close issue. You can find more information on setting up a time filter at the link below:

    http://www.ninjatrader.com/support/f...ead.php?t=3226

    You mentioned that you other exit logic is not executing, as well. Can you tell me what that other exit logic is?

    To troubleshoot the disparity between the Strategies window and the Position tab, I would need to test an export of your code. If that is okay with you, please send an export to platformsupport [at] ninjatrader [dot] com, and reference ticket # 1294992
    Dave I.NinjaTrader Product Management

    Comment


      #3
      Hello Dave,

      Thanks for the heads up on forex session handling, and the reference to the code example. I will modify my code later.

      Let me summarize my problems/issues:

      Scenario:

      Exact same strategy applied on forex pairs and futures, parameters changed to suit individual instrument; forex order quantity is set to 1000, futures order quantity set to 1; other settings are identical.

      On backtesting, as expected, strategy for both forex and futures generate entry and exit orders. Both generate a few trades per day.

      On live trading (forex on FXCM demo connection, futures on NTB Continuum):

      1. When strategy generates entry orders for forex, on "Orders" tab, it appears "PendingSubmit" and then "FIlled" the next second. Futures orders get filled right away.

      2. The forex positions don't show up on "strategies" tab, but on "Positions" tab; futures positions show up on both tabs.

      3. On "Executions" tab, forex executions have the name of "External"; futures executions have the names of buy, sell, sell short, buy to cover, etc.

      4. checked against backtest result, strategies applied on forex only generate the first entry order for each pairs and that's it until data feed disconnected; strategy on futures generate entries and exits very close (acceptable) to backtest result.

      5. exit on close doesn't do anything on forex positions; does what it's supposed on futures.

      With my observation and search on this forum, I have an impression that the issue is related to FXCM demo data feed.

      I don't feel comfortable giving my code, but thanks for your offer to test. I have tested my code on back testing and live account trading futures, and I haven't seen this even once. I cannot guarantee but am very positive that the code is fine.

      I wonder if an FXCM live account data feed would solve it?

      Comment


        #4
        BTW, I use a single broker lifetime license to connect both NTB Continuum and NTB FXCM demo. I'm not sure if this setup has anything to do with it. I was told I can connect up to 3 NinjaTrader technologies simultaneously.

        Comment


          #5
          More observation:

          I just noticed one thing I probably ignored before, when the strategy generates a new entry, on "orders" tab, the order with my strategy ID is "PendingSubmit", with the correct quantity remaining, and then an external order generated with the same entry price and quantity and got filled straight after. As a result, in the strategy's eye the original entry order was still pending hence no further exit order or entry order, or exit on close order will be generated; in the platform's eye, the order was filled the same way as a manual order filled, hence the position is there forever until manually closed. This would explain every issue I've observed.

          Comment


            #6
            Hello,

            I'm glad to hear that you've got it figured out, and without being able to test the code I will not be able to look further into the cause behind the odd behavior.

            The way I understand it, the FXCM demo data feed is identical to the data feed provided by the live account, with the only difference being that the live feed connects to a live account.

            Please let me know if I can assist further.
            Dave I.NinjaTrader Product Management

            Comment


              #7
              Hi,

              I developed a simple strategy for EUR/USD with the following requirements:
              1. Subtract today's close from the close two days ago (not yesterday but the day before). Thus, close (day one) - close (day three) equals the 2-period rate of change.
              2. Add this number to yesterday's closing price (day two).
              3. This will be our short-term pivot number. We want to go home long if we have been on a sell signal and the price then closes above this pivot number.We will look to short if the 2-period rate of change flips from a buy to a sell and the price is going to close below the short-term pivot number.
              4. Allow Entry only when 16.1 < ADX < 35.1
              5. Exit on the closure of the day of entry (would also like to test for exit the following day)

              The entry condition seems to work OK, however the exit takes far too many days, instead of exiting the following day. This skews the results of the strategy.

              Could you please advise what is wrong and how to address?

              Regards

              protected override void OnBarUpdate()
              {
              double two_per_roc = (Close[1] - Close[3]);
              double short_term_pivot = (Close[2] + two_per_roc);
              double adx = ADX(14)[0];
              if ((Close[0] < short_term_pivot) && (Close[0] > Open[0]))
              {
              DrawTriangleDown("t2" + CurrentBar,false, 0, High[0] + 100 *TickSize, Color.Red);
              DrawText("tag1", "Close:" + Close[0], CurrentBar, High[0] +50*TickSize, Color.Black);
              DrawText("tag1", "Pivot: " + short_term_pivot, CurrentBar, High[0] +50*TickSize, Color.Black);
              if ((adx > 16.1) && (adx < 35.1))
              {
              EnterShort(DefaultQuantity, "Short");
              Print("Short: "+"Pivot: " + short_term_pivot + " Price: " + Close[0]);
              }
              }
              else if ((Close[0] > short_term_pivot) && (Close[0] < Open[0]))
              {
              DrawText("t1" + CurrentBar, "", 0, 0, Color.Green);
              DrawTriangleUp("t1" + CurrentBar,false,0,Low[0] - 100 *TickSize, Color.Green);
              if ((adx > 16.1) && (adx < 35.1))
              {
              EnterLong(DefaultQuantity, "Long");
              Print("Long: "+"Pivot: " + short_term_pivot + " Price: " + Close[0]);
              }
              }
              if (ToTime(Time[0]) > 235900)
              //((BarsSinceEntry("Long") > 1) && (BarsSinceEntry("Long") < 2))
              {
              Print(" BarsSinceEntry: " + BarsSinceEntry("Long"));
              ExitLong("Long");
              //return;
              }
              if (ToTime(Time[0]) > 235900)
              //((BarsSinceEntry("Short") > 1) && (BarsSinceEntry("Short") < 2))
              {
              Print(" BarsSinceEntry: " + BarsSinceEntry("Short"));
              ExitShort("Short");
              //return;
              }
              }

              Comment


                #8
                Hello vtechdir,

                Thank you for your post.

                Are you submitting the orders to your FXCM demo account?

                What Bar Type and Interval are you testing? For example: 1 Minute

                Comment


                  #9
                  Hi Patrick,

                  Thank you very much for your prompt reply.
                  The bar type is daily and the strategy does not exit in Backtest mode; neither BarsSinceEntry(), nor ToTime() functions.

                  Please let me know if there is any additional information required?

                  Regards

                  Comment


                    #10
                    Hello vtechdir,

                    Thank you for your response.

                    Are you submitting the orders to your FXCM demo account?

                    Comment


                      #11
                      Dear Patrick,

                      Thank you very much for your prompt reply. I do not submit the strategy to FXCM nor to another broker. Before taking any financial risk I am testing the trading idea in Backtest mode, evaluating Win, Sharpe ratios, in other words the validity of the idea.
                      The Strategy is only run in backtest mode and does not what I desired to do by using either function. I attach the Strategy to provide additional information.

                      Kind Regards
                      Virgil
                      Attached Files

                      Comment


                        #12
                        Hello vtechdir,

                        Thank you for your response.

                        On a Daily chart for one of your Currency Pairs, what time does the bar close? You can check this by enabling the Data Box and hovering over the bar to see the close time/timestamp.

                        Comment


                          #13
                          Dear Patrick,

                          Thank you very much for your prompt reply. I provided both the requirements and the Strategy's source code. It appears to me that you are referring to a different post, which requires some manual identification.

                          I found the BarsSinceEntry() function and I have a check against values of this function in order to automatically exit from the trade:

                          if ((BarsSinceEntry("Short") > 1) && (BarsSinceEntry("Short") < 2))
                          ExitShort("Short");

                          My post is referring to the fact that in spite of the check condition, to exit after one bar (>1 and <2), the strategy does not exit automatically.
                          Are you able to identify something wrong in my script, since the trades are exited after inconsistent and different number of days (bars) ?
                          It compiles OK (thus the syntax is correct), maybe the function works in a different way or something else, which you being close to developers have the ability to help.

                          Looking forward to your help.

                          Kind Regards
                          Virgil

                          Comment


                            #14
                            Hello Virgil,

                            Thank you for your response.

                            The value cannot be greater than 1 but smaller than 2. While the syntax is fine and it compiles, the logic does not make sense. What bar are you looking to exit after entry?

                            Comment


                              #15
                              Thank you Patrick, good point. all good now.

                              Regards

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by algospoke, Today, 06:40 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post algospoke  
                              Started by maybeimnotrader, Today, 05:46 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post maybeimnotrader  
                              Started by quantismo, Today, 05:13 PM
                              0 responses
                              7 views
                              0 likes
                              Last Post quantismo  
                              Started by AttiM, 02-14-2024, 05:20 PM
                              8 responses
                              168 views
                              0 likes
                              Last Post jeronymite  
                              Started by cre8able, Today, 04:22 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post cre8able  
                              Working...
                              X