Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Stop Loss not working in a multi time frame strategy

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

    Stop Loss not working in a multi time frame strategy

    Hi,
    I am backtesting a strategy (with NT7 beta14) on a daily timeframe. Trying to improve results I have decided to include a entry condition based on the weekly chart EMA of the same instrument.

    For that, I am trying to use multi frame strategy. But now all the stoploss and profit targets have stop working correctly.

    Before changing any entry condition, I have just added these 2 lines of code to see if I was able to replicate the same results as before, but I am not:

    In the Initialize() method:

    Add(PeriodType.Week, 1);

    And in the OnBarUpdate():

    if (BarsInProgress != 0)
    return;


    These lines do not change any entry / exit condition, but since I have included them in the code I am getting very weird results.

    Thanks for your help!
    Last edited by abc1974; 04-27-2010, 11:22 AM.

    #2
    Hello Abc1974,

    Welcome to our forums!

    You will have to use TraceOrders output to see what may be happening. Add the following line to your Initialize() method.
    TraceOrders = true;

    View by clicking Tools > Output Window.

    Let us know a little about how your entries/exits are defined and we might have some more to go on.
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      If you add another timeframe on the initialize section, then the OnBarUpdate() is going to execute each time a bar finished on each timeframe, but you are discarding the secondary timeframe with a return when BarsInProgress != 0.
      So, on these cases, if the system had an order in progress, this is not going to be refreshed, so cancelled.
      What I do when using multiple timeframes is checking (BarsInProgress == 0) to execute the logic of the system only, and then ALWAYS, execute the Orders Commands ( EnterLongLimit, EnterLongStop, etc )
      pmaglio
      NinjaTrader Ecosystem Vendor - The Indicator Store

      Comment


        #4
        Thanks pmaglio for your comments. As you say, it looks like the stoploss and profit target order are cancelled on the next bar.

        I did a simplified strategy (the code is attached) to be able to show you what it is happening.

        The strategy enters the market if a EMAs crossover happens. And it will only exit if a profit target or stop loss is hit.

        The code works fine until I add in the code the Multi Time Frame lines (Add(PeriodType.Week, 1); if (BarsInProgress != 0) return

        When I do this, I only get one trade at the second (¿?) EMAs crossover. The strategy never exits the market because the stoploss and the profit target orders had been cancelled (I also attached the output from traceorders).

        The other weird thing is that the strategy, after the MTF change, misses the first crossover of the EMAs (¿? it didn’t do it before). And it enters the market after the second one. This does not even appear in the traceorders output.

        I use the instructions: EnterLong(); SetStopLoss(); SetProfitTarget();

        Right now, I'm trying to make a modification to the strategy to test PMAGLIO comments, but yet I was not able to make it work. Anyways, this will imply that once a trade is enter, i have to be sending the stoploss and profit target order every day. Guess this should no be working like this ¿no?

        Thank you very much for your help!

        Crossover Strategy with MTF added in the Initialize()
        MTFStrategy_v1.zip

        This is the output from the TraceOrders intruction;
        output.txt

        Comment


          #5
          Hello abc1974,

          There is currently a bug with this beta edition of NinjaTrader. It will be fixed in the next beta, but right now Set statements cancel after one bar.
          Ryan M.NinjaTrader Customer Service

          Comment


            #6
            Thank you for your prompt reply

            Regards

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by WHICKED, Today, 12:45 PM
            1 response
            10 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by samish18, Today, 01:01 PM
            0 responses
            5 views
            0 likes
            Last Post samish18  
            Started by WHICKED, Today, 12:56 PM
            0 responses
            8 views
            0 likes
            Last Post WHICKED
            by WHICKED
             
            Started by Spiderbird, Today, 12:15 PM
            2 responses
            11 views
            0 likes
            Last Post Spiderbird  
            Started by FrazMann, Today, 11:21 AM
            2 responses
            8 views
            0 likes
            Last Post NinjaTrader_ChristopherJ  
            Working...
            X