Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

draw a text on the chart based on time

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

    draw a text on the chart based on time

    hello

    I am trying to put a time limit on the code to draw a text but it is not working and I cant figure out what am I doing wrong... all I want is when the time is between the time variables, to draw Trading... and if not write no trading or something like that... here is the code I am using.


    #2
    I forgot to attach the document.

    protected override void OnBarUpdate()
    {
    if (BarsInProgress != 0)
    return;

    if (CurrentBars[0] < 0)
    return;

    // Set 1
    if ((((Times[0][0].TimeOfDay > Start_Time.TimeOfDay)
    && (Times[0][0].TimeOfDay < End_Time.TimeOfDay))

    ||

    ((Times[0][0].TimeOfDay > Start_Time2.TimeOfDay)
    && (Times[0][0].TimeOfDay < End_Time2.TimeOfDay)))
    && Position.MarketPosition == MarketPosition.Flat
    )
    {
    IsTradingTime = false;
    }

    // Set 2
    if ((((Times[0][0].TimeOfDay > Start_Time.TimeOfDay)
    && (Times[0][0].TimeOfDay < End_Time.TimeOfDay))

    ||

    ((Times[0][0].TimeOfDay > Start_Time2.TimeOfDay)
    && (Times[0][0].TimeOfDay < End_Time2.TimeOfDay)))
    && Position.MarketPosition == MarketPosition.Flat
    )
    {
    IsTradingTime = true;
    }

    // Set 3
    if (IsTradingTime == true)
    {
    Draw.TextFixed(this, @"Test Fixed text_1", trading, TextPosition.TopRight);
    }

    // Set 4
    if (IsTradingTime == false)
    {
    Draw.TextFixed(this, @"Test Fixed text_1", @"no trading", TextPosition.TopRight);
    }

    }
    }
    }

    Comment


      #3
      Hello babouin77,

      Thank you for your inquiry.

      It looks like your conditions in Set 1 and Set 2 are the same, which would cause IsTradingTime to always be set to true if it's between one of those two time periods, so you'd always see it print true unless you're in a trade during one of the two time periods, in which case it would print false. It looks like your strategy was created with the Strategy Builder, is that correct? If you've unlocked that code you could simply do something like this:

      if (((Times[0][0].TimeOfDay > Start_Time.TimeOfDay)
      && (Times[0][0].TimeOfDay < End_Time.TimeOfDay))
      ||
      ((Times[0][0].TimeOfDay > Start_Time2.TimeOfDay)
      && (Times[0][0].TimeOfDay < End_Time2.TimeOfDay)))
      {
      IsTradingTime = true;
      }
      else {
      IsTradingTime = false;
      }

      // Set 3
      if (IsTradingTime == true)
      {
      Draw.TextFixed(this, @"Test Fixed text_1", "trading", TextPosition.TopRight);
      }

      // Set 4
      if (IsTradingTime == false)
      {
      Draw.TextFixed(this, @"Test Fixed text_1", @"no trading", TextPosition.TopRight);
      }

      If you're just wanting that to print based on whether it's between those two times, I wouldn't suggest checking the position, otherwise it'll print "no trading" when in a position during that time frame.

      Now if it's still locked in the Strategy Builder this gets trickier, because you can't really do an else in the Builder. What you could do is in set 1, don't put any conditions, but have it automatically set the IsTradingTime bool to false, and then leave your conditions in set 2 to set IsTradingTime to true. This way, it's false unless you're within those hours and you get the same effect as above.

      Please let us know if we may be of further assistance to you.

      Comment


        #4
        it is not in strateg builder. ill test what you suggested. thanks a lot

        Comment


          #5
          it worked. thanks a lot

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          574 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          333 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          553 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          551 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X