Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Too many entries

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

    Too many entries

    I have a problem with my strategy it's making more entries(two) than it should(one), from time to time. I tried a few things, but nothing seems to work.
    My strategy is:
    -buy on Friday's one tick above highest high of last ten days, if the 10 day simple moving average is above the 40 day simple moving average.
    -if I get filled, I exit my position on Monday;

    I want to make only one entry. I made two filters to prevent additional entries:
    -X variable which prevents from extra orders( enter only if X == false);
    -EntriesPerDirection=1,(EntryHandling=EntryHandling .AllEntries);

    but I still get two entries;

    Bellow i Attach a code:
    Code:
            protected override void OnBarUpdate()
            {
    			if(Time[0].DayOfWeek==DayOfWeek.Friday && Time[0].Hour>=OpeningOrderHour && X==false)
    			{
                	if (SMA(BarsArray[1],SMA1Period)[0] > SMA(BarsArray[1],SMA2Period)[0])
                	{
    					Max=MAX(Highs[1],highestHighPeriod)[0];
    					BuyPrice=Max + TickSize;
    					if(Open[0]>BuyPrice)
    					{
    						pozycja=EnterLong();
    						Print("Before " + Time[0].ToString() + " " + X.ToString());
    						SetStopLoss(CalculationMode.Ticks, 100);
    						X=true;
    						Print("After " + Time[0].ToString() + " " + X.ToString());
    					}
                	}
    			}
    			if(Time[0].DayOfWeek!=DayOfWeek.Friday && Time[0].DayOfWeek!=DayOfWeek.Saturday && Time[0].DayOfWeek!=DayOfWeek.Sunday && Time[0].Hour>=closingTradeHour)
    			{
    			ExitLong();	
    			}
    		}
            protected override void OnPositionUpdate(IPosition pozycja)
    		{
    			if(pozycja.MarketPosition==MarketPosition.Long)
    				X=true;
    			if(pozycja.MarketPosition==MarketPosition.Flat)
    				X=false;			
    		}

    I tried Print() method to see what is going on before making entry and right after entry and I still can't figure it out. It's seems like X variable is changing itself from true to false. Example :
    Friday at 7:02 X == false(condition to make entry) then strategy is making entry and changing X to true. X is supposed to be true until Monday morning.
    Friday at 7:09 is making another entry and X is false again(don't know why it changed to false and don't know why strategy is ignoring EntriesPerDirection=1).

    I am attaching results screen shot, with two entries.
    I don't know what to do, please help.
    Attached Files

    #2
    Wintermute,

    What you would want to try is tracking your X variable. Try putting a print for its state outside of all if-statements at the beginning of your OnBarUpdate().
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thanks for Your replay. I did what You said. I put print() outside of all if-statements at the beginning of your OnBarUpdate(). And that's what I got:

      X variable On Bar Update: 2003-01-23 21:57:00 False
      X variable On Bar Update: 2003-01-23 21:58:00 False
      X variable On Bar Update: 2003-01-24 07:01:00 False
      X variable just before entry2003-01-24 07:01:00 False
      X variable right after entry 2003-01-24 07:01:00 False
      X variable On Bar Update: 2003-01-23 22:00:00 True
      X variable On Bar Update: 2003-01-24 07:02:00 False

      X variable On Bar Update: 2003-01-24 07:03:00 False
      X variable On Bar Update: 2003-01-24 07:04:00 False
      X variable On Bar Update: 2003-01-24 07:06:00 False
      X variable On Bar Update: 2003-01-24 07:07:00 False
      X variable On Bar Update: 2003-01-24 07:08:00 False
      X variable just before entry2003-01-24 07:08:00 False
      X variable right after entry 2003-01-24 07:08:00 False
      X variable On Bar Update: 2003-01-24 07:09:00 True
      X variable On Bar Update: 2003-01-24 07:10:00 True

      My session template set's beginning of session at 7:00 and end of session at 22:00. This output is very surprising for me. Seems like strategy is first getting data of 2003-01-24 07:01:00 then it moves back to 2003-01-23 22:00:00 and than again it goes to 2003-01-24 07:02:00(situation colored in red). I checked my data and it seems alright. I am lost, I don't know what's going on.

      Any ideas what can I do to make it right?

      Comment


        #4
        Wintermute, is this a MultiSeries strategy you're working with here?

        Comment


          #5
          Yes it is, Primary Bars are 1 minute $EURUSD and secondary Bars are 1 day $EURUSD.

          Comment


            #6
            You would then need to ensure to filter the OnBarUpdate() for the needed BarsInProgress calls you wish to see, without any restrictions logic is run for each bar update seen :

            Comment


              #7
              Thank You very much. It workes good now.

              Comment


                #8
                I'm glad to hear that, thanks for posting the update.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                0 responses
                666 views
                0 likes
                Last Post Geovanny Suaza  
                Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                0 responses
                377 views
                1 like
                Last Post Geovanny Suaza  
                Started by Mindset, 02-09-2026, 11:44 AM
                0 responses
                110 views
                0 likes
                Last Post Mindset
                by Mindset
                 
                Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                0 responses
                575 views
                1 like
                Last Post Geovanny Suaza  
                Started by RFrosty, 01-28-2026, 06:49 PM
                0 responses
                580 views
                1 like
                Last Post RFrosty
                by RFrosty
                 
                Working...
                X