Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

"Exit on time" error on non time based charts

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

    "Exit on time" error on non time based charts

    I´ve set a condition where trades are exited at a given time.

    It is working fine on 1m, 2m, 4min charts, exits the trades and draws the magenta line at 10am.

    It does not work on non time based charts (range etc) or on 3 minute charts, 5 minutes charts etc. The script is ignored then the trades exit on close of session.

    Why is this script not working on non time based charts (and uneven # minute charts)?

    Code:
    // Condition set 2
                if (ToTime(Time[0]) == ToTime(10, 0, 0))
                {
                    ExitLong("", "");
                    ExitShort("", "");
                    DrawVerticalLine("My vertical line" + CurrentBar, 0, Color.Magenta);
                }
    Last edited by ScottieDog; 04-13-2016, 05:25 AM.

    #2
    Hello ScottieDog,


    Your script does not trigger on non time based charts and uneven # minute charts because your condition only allows for your script to trigger at exactly 10AM. Meaning, the current bar would have to end at 10AM to trigger your script.


    If you change your condition to reflect when the time is greater than or equal to, then the script would trigger when the current bar closes on or after 10AM.


    Code:
    [LEFT][FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2](ToTime(Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]]) >= ToTime([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]))[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]        {[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                ExitLong([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                ExitShort([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]                DrawVerticalLine([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"My vertical line"[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]+ CurrentBar,[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2], Color.Magenta);[/SIZE][/FONT]
    [FONT=Courier New][SIZE=2]        }[/SIZE][/FONT][/LEFT]

    Comment


      #3
      Thanks. Only issue is that now it plots the magenta line on every bar after the time hits. How to stop that?

      Comment


        #4
        Hello ScottieDog,


        You could use a range of time in your condition. This will make it so that the script only draws your line within the specified range of time instead of every bar after 10AM.
        Code:
        [LEFT][FONT=Courier New][SIZE=2][COLOR=#0000FF]if[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]((ToTime(Time[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]]) >= ToTime([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2])) && (ToTime(Time[[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]]) <= ToTime([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]10[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]02[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]) ))[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]{[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]    ExitLong([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]);[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]    ExitShort([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]""[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]);             [/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]    DrawVerticalLine([/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800000]"My vertical line"[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2]+ CurrentBar,[/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2], Color.Magenta);[/SIZE][/FONT]
        [FONT=Courier New][SIZE=2]} [/SIZE][/FONT]
        For example.
        [FONT=Courier New][SIZE=2][/SIZE][/FONT]

        [/LEFT]

        Comment


          #5
          Thanks. Understood.

          Out of curiosity, is using a time filter like this the only way to stop a line repeating its print? Or would there be other ways too? Just trying to get a few basic functions etc into my newbie brain :-)

          Comment


            #6
            Hello,

            You could use a bool to act as a switch and stop your script from drawing more lines.

            You would have to reset the bool afterwards. I have included an example showing this.



            Code:
            [COLOR=#000000][FONT=Tahoma][LEFT][LEFT]         protected override void OnBarUpdate()
                    {
                              
                               if ((ToTime(Time[ 0 ]) >= ToTime( 10, 0, 0)) )
                        {               
                                                ExitLong( "", "" );                                     ExitShort( "", "" ); [LEFT]                         
                              if(myBool == true)
                                    {
                                    DrawVerticalLine( "My vertical line" + CurrentBar, 0 , Color.Magenta);
                                    myBool = false;
                                    }
                        }
                              
                               if (ToTime(Time[ 0]) < ToTime( 10, 0, 0))
                              {
                              myBool = true;
                              }
                    }[/LEFT]
            [/LEFT][LEFT][/LEFT][LEFT][/LEFT]
            [/LEFT][/FONT][/COLOR]

            Here is the Basic Syntax Help Guide to assist you further.

            Comment


              #7
              Understood. Thank-you.

              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