Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

intraday strategy, with daily conditions

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

    intraday strategy, with daily conditions

    Hello, i am totally new to strategy development and i have a problem i am not able to solve on my own.

    What i itend to do is:

    today (Day 0) at 9:31: if Open on Day -1 > High on Day -2
    and ((Open on Day -1 minus Close on Day -2)/ Close on Day -2) > 2%
    then Enter Long Position at 09:32 on Day 0
    and Exit Long Position at 15:00 on Day 0

    My Code is the following:

    Code:
    public class XY : Strategy
        {
            #region Variables
            	private TimeSpan _StartTime = new TimeSpan(9,31,0);
    		private TimeSpan _ExitTime = new TimeSpan(15,0,0);
    	#endregion
    
           protected override void Initialize()
            {
    		Add(PeriodType.Day, 1);
    		CalculateOnBarClose = true;
            }
    
            protected override void OnBarUpdate()
            {
    			if(Time[0].TimeOfDay == _StartTime
    				&& Opens[1][1]>Highs[1][2])
    				&& ((Opens[1][1]-Closes[1][2])/Closes[1][2])>0.02))
    			{
    				EnterLong(0, 1, "Long");
    			}
    			
    			if(Time[0].TimeOfDay == _ExitTime)
    			{
    				ExitLong("Exit Long", "Long");
    			}
    	        }
    I run Strategy Analyzer on 1 minute intervall with Last price.

    When i check the orders manually it shows that the condition of 2% change does not hold, but the Long Position is entered.
    I have no clue where exactly the fault is.

    Is my time structure totally wrong and i do not use the bars i itend to?

    Any hint what to modify would be a big present.

    #2
    Hello denahl,

    Thanks for your post and Welcome to the forums!

    Your time structure is valid. I think the if statement you posted is missing a "(".

    To debug code questions what I recommend is that you break down your logic by adding print statements and using market replay data to verify that your logic is executing as you expect and that the results will be what you expect. With market replay you can set the start time to 9:29 and then run it through quickly to see the results, then jump to another day at 9:29. Once you have validated with market reply then you can run your backtesting with confidence of the logic. Here is an example with your evaluation statement broken down with print statements so that each of the 3 conditions can be independently verified:
    Code:
    if(Time[0].TimeOfDay == _StartTime)   // begin level 1 check
    {
    Print ("Level 1: CBS: "+CurrentBars[0]+" "+CurrentBars[1]+" time: "+ Time[0].TimeOfDay+"ST:"+_StartTime);  // Check bar numbers, check time of day and start time
    Print ("Level1: O11 ="+Opens[1][1]+ " H11 = "+Highs[1][2]);  // Check 2nd level values now
    Print("Level 1: o11-C12/C12>0.02 "+ (Opens[1][1]-Closes[1][2])/Closes[1][2]);  // Check 3rd level values now
    
    if (Opens[1][1]>Highs[1][2]) // begin level 2 check
    {
    Print ("Level2: O11 ="+Opens[1][1]+ " H11 = "+Highs[1][2]);
    Print("Level2: 11-C12/C12>0.02 "+ (Opens[1][1]-Closes[1][2])/Closes[1][2]);
    
    if (((Opens[1][1]-Closes[1][2])/Closes[1][2])>0.02)  // begin level 3 check
    {
    Print("Level3: o11-C12/C12>0.02 "+ (Opens[1][1]-Closes[1][2])/Closes[1][2]);
    Print ("CB: "+CurrentBars[0]+" EnterLong(0, 1, Long");   
    }
    }
    Please let me know if you have any questions.

    Comment


      #3
      Thanks a lot for your immediate help!

      The Tip to use "print output" was a big thing.

      I still have no clue why i does not work that way i tried to make it work.

      Somehow the "Opens[1][1]>Highs[1][2]" both did not grab the bar i expected.

      Now i change it to:

      Code:
      && (Bars.GetDayBar(1).Open>Bars.GetDayBar(2).High)
      && (((Bars.GetDayBar(1).Open-Bars.GetDayBar(2).Close)/Bars.GetDayBar(2).Close))>0.02)
      And as far as i can see it works as expected.

      Thanks a lot.

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      633 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      364 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      105 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      567 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      568 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X