• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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():
    http://www.ninjatrader-support.com/H...inceEntry.html

    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,
        http://www.ninjatrader-support2.com/...ad.php?t=19289

        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, 05: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 madankumars, Today, 10:12 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_Jim  
            Started by pjsmith, Today, 10:10 AM
            0 responses
            7 views
            0 likes
            Last Post pjsmith
            by pjsmith
             
            Started by sandman55, Yesterday, 08:00 PM
            2 responses
            9 views
            0 likes
            Last Post koganam
            by koganam
             
            Started by ArmKnuckle, Today, 01:44 AM
            2 responses
            15 views
            0 likes
            Last Post koganam
            by koganam
             
            Started by TazoTodua, Today, 04:35 AM
            4 responses
            11 views
            0 likes
            Last Post koganam
            by koganam
             
            Working...
            X