Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bars before next trade?

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

    Bars before next trade?

    Hi, I have created a Strategy Analyzer using the Wizard and all is going smoothly so far. The only problem I have is trying to stop it from taking a new entry too soon after an exit.

    I tried a condition like,

    BarsSinceExit() >2
    then next condition

    But that stop it from doing any trades obviously because at the start there is no exit! How would I turn this condition on AFTER the first trade is taken.

    #2
    Hello,

    You could use BarsSiknceEntry():


    Or a bool flag system may be better:
    if(time_to_trade && EMA(5)[0] > EMA(18)[0] )
    {
    EnterLong();
    time_to_trade =
    false;
    }


    if (EMA(5)[0] < EMA(18)[0] && time_to_trade == false)
    {
    ExitLong();
    time_to_trade =
    true;
    }

    Note: this code is not complete, over simplified and untested but it should give you an idea on where to start. Post questions.
    DenNinjaTrader Customer Service

    Comment


      #3
      Thanks, But BarsSinceEntry() will have exactly the same result as BarsSinceExit() . Because when you start you haven't had an entry or exit therefore if you reference that you always get false and nothing starts.

      What I need is a condition like this,

      "If Trade # is > 1 THEN BarsSinceExit() >2"

      That is, I'm looking to first check that the strategy has taken 1 trade.

      I have got around it in a funny way by having two entries both the same except 1 has,
      Performance.AllTrades.TradesPerformance.Currency.C umProfit == 0 For the first trade And for the second and all other trades,
      Performance.AllTrades.TradesPerformance.Currency.C umProfit != 0 Then adding my BarsSinceExit() >2 condition.

      Not perfect but a solution.

      Comment


        #4
        Hi
        I'm trying to modify the "Stopping a strategy after consecutive losers" Reference sample at,


        By slowing down how many bars after the last trade if it was another loss before it gets to 3 losses and stopping. But am having no luck with my first attempt at coding,

        I have the same code as per the reference sample but from line 86 I am trying to add an extra condition with BarsSinceExit(), Basically its not working just taking trades as soon as one is exited!!


        /* If lastThreeTrades = -3, that means the last three trades were all losing trades.
        Don't take anymore trades if this is the case. This counter resets every new session, so it only stops trading for the current day. */
        {
        if (lastThreeTrades == -3)
        return;

        if (lastThreeTrades >= 0
        && Position.MarketPosition == MarketPosition.Flat
        && CurrentDayOHL().CurrentLow[0] < CurrentDayOHL().CurrentLow[1]
        && BarsSinceExit() > 10);
        {
        EnterLong(DefaultQuantity, "");
        }


        if (lastThreeTrades == -1
        && Position.MarketPosition == MarketPosition.Flat
        && CurrentDayOHL().CurrentLow[0] < CurrentDayOHL().CurrentLow[1]
        && BarsSinceExit() > 20);
        {
        EnterLong(DefaultQuantity, "");
        }

        if (lastThreeTrades == -2
        && Position.MarketPosition == MarketPosition.Flat
        && CurrentDayOHL().CurrentLow[0] < CurrentDayOHL().CurrentLow[1]
        && BarsSinceExit() > 20);
        {
        EnterLong(DefaultQuantity, "");
        }
        }



        Where have I gone wrong here?
        Last edited by Tremblinghandtrader; 11-04-2009, 06:04 AM.

        Comment


          #5
          Tremblinghandtrader, I would suggest adding print statements to check if all your strategy makes it to all those code sections first, next remove the BarsSinceExit logic you added - does it work then as you would expect?

          If not, try to remove the different lastThreeTrades scenarios and just address and test one by one, you can always add later, but simpifying makes it easier to debug for you.

          You should also work with TraceOrders to debug your order behavior in the output window as you work with strategies - http://www.ninjatrader-support2.com/...ead.php?t=3627
          BertrandNinjaTrader Customer Service

          Comment


            #6
            Got it to work. Way too many {} thingo's

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by DanielSanMartin, Yesterday, 02:37 PM
            2 responses
            13 views
            0 likes
            Last Post DanielSanMartin  
            Started by DJ888, 04-16-2024, 06:09 PM
            4 responses
            12 views
            0 likes
            Last Post DJ888
            by DJ888
             
            Started by terofs, Today, 04:18 PM
            0 responses
            11 views
            0 likes
            Last Post terofs
            by terofs
             
            Started by nandhumca, Today, 03:41 PM
            0 responses
            8 views
            0 likes
            Last Post nandhumca  
            Started by The_Sec, Today, 03:37 PM
            0 responses
            7 views
            0 likes
            Last Post The_Sec
            by The_Sec
             
            Working...
            X