Announcement

Collapse
No announcement yet.

Adding time as a factor

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

  • #31
    Time Conditions....

    Garth (and others),

    I have done alot of work with times and setting conditions based on times in the markets. If I can be of help, please let me know.

    I looked over the last code posed on this thread and wondered how I could offer help??

    I don't want to just "Jump in" here, so if you feel I can be of assistance, please let me know.

    Best regards,

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #32
      hi guys,

      Garth I posted my answers to your questions and was wondering if you had time to look at them or if the 4pm close has you stumped, in which case maybe doji3333 could help.

      ubo

      Comment


      • #33
        Fellas....

        I've got a copy of the code and am looking at it...

        The first thing that comes to mind is "the close time is set to 13:15"??? When is the system supposed to exit this trade ?? - after the market closes??

        Try setting the end time to 13:00. and make sure you use a chart interval where enough time will be permitted from bar to bar - after 13:00.

        The functions used in the code report the BAR TIME. Thus, if the interval of your chart is 20 minutes, it is unlikely that the system will have time to exit after 13:15 and wait for the next 20 minute bar.

        Some simple suggestions, set your CLOSE TIME = to an interval on your chart (if your chart is a 5 minute, then set the close time to 13:00) - some time that is before 13:15 and guaranteed to appear on the chart.

        I use a little bit different function to handle time, but the outcome is roughly the same - so other than a quick re-write I think we should address the simply things first.

        Brad
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #34
          doji, im using 10 minute bars, that is why in my last post i said close all trades at 16.05 est

          Comment


          • #35
            Alex determined that the cause was the close time vs the interval selected and the time template applied. The code as is will work if you follow Alex's example.

            The problem is that historical data will not give you ticks, but only the values at the bars close. The code should work fine in RT with the original close time and any interval and a TT that allows that close time to be reached.

            This is why I think it would be a good idea for eSignal to add a new flag to the backtester that allows it to exit trades at specified times...the backtest engine can go to a smaller timeframe to grab the correct values and it will reflect more accuarately what we can already do in RT.

            So bottom line is, the code should work, but isn't perfect because on limitations with the eSignal backtester.

            G
            Garth

            Comment


            • #36
              ill run it after im done messing up todays trades tx guys

              nothing like thinking a +12 is a great trade id, until u realize the target was hit at +19....next

              Comment


              • #37
                doji3333,

                as a sidebar, did u ever get my email from the other topic?

                ubo

                Comment


                • #38
                  Time Coding...

                  Hey folks,

                  Been really busy today...

                  Uboinc, please re-post your eariler request (easier for me to look at it again, rather than try to find it in my HUGE list of emails.).

                  Time issues....

                  In my fileshare group, there are a few examples (in the trading system examples) of how I handle time issues.

                  I normally declare global variables for time (outside the main() function).. like this....

                  var vRTHour;
                  var vRTMin;
                  var vHour;
                  var vMin;
                  var vSec;
                  var vDay;
                  var vMonth;

                  I also declare a START and STOP time as user defined variables (global variables). Like this (outside of mai())...

                  var vStartHour = 6;
                  var vStartMin = 30;
                  var vEndHour = 13;
                  var vEndMin = 10;

                  then, within main() - near the top of main() - I use the following to record the time. Notice that I have RT and non-RT time variables. RT time is the current clock time. The non-RT time is the BAR TIME.

                  var vTime = new Date();
                  vRTHour = vTime.getHours();
                  vRTMin = vTime.getMinutes();
                  //---------------------------------------------------
                  // Get Bar Time Variables
                  vTime = getValue("Time", 0);
                  vHour = vTime.getHours();
                  vMin = vTime.getMinutes();
                  vSec = vTime.getSeconds();
                  vDay = vTime.getDate();
                  vMonth = vTime.getMonth() +1;

                  Now, within main(), I use the following IF conditions to determine if it is time to ENTER TRADES. Note, if you code your system properly, you will have two conditions..

                  IF TIME TO ENTER NEW TRADES

                  and

                  IF TIME TO CLOSE ALL TRADES

                  like this...

                  if (((vHour > vStartHour) && (vHour < vEndHour)) || ((vHour == vStartHour) && (vMin >= vStartMin)) || ((vHour == vEndHour) && (vMin <= vEndMin)) ) { //Execute New Entry Orders


                  }


                  if ((vHour > vEndHour) || ((vHour == vEndHour) && (vMin > vEndMin)) ) { //Execute EOD Orders

                  }

                  After you have these two conditions in your code, then you would simply build the other supportive routines (Stops, PTs and others) below the EOD code.


                  if (((vHour > vStartHour) && (vHour < vEndHour)) || ((vHour == vStartHour) && (vMin >= vStartMin)) || ((vHour == vEndHour) && (vMin <= vEndMin)) ) { //Execute New Entry Orders
                  ... Enter new orders
                  }

                  if ((vHour > vEndHour) || ((vHour == vEndHour) && (vMin > vEndMin)) ) { //Execute EOD Orders
                  .... Close EOD orders
                  }


                  if (Strategy.isInTrade) {
                  ... Handle Stops, PTs and anything else...
                  }

                  A simple note for advanced coders. An easy way to convert a BT (back-test) code into an RT code is to simply convert the "Strategy" functions to variables...

                  I normally convert them as follows (by declaring global variables near the top of my file, then forcing the conditions of my system when entry/exits happen...

                  var StrategyisInTrade = false;
                  var StrategyisLong = false;
                  var StrategyisShort = false;

                  Then, go through your code and convert all "Strategy.??" to "Strategy??" and add the logic statements.

                  The only other things needed for most RT files are...

                  1. Use of RT Time (described above).
                  2. Changing your IF statements to test close() instead of high() or low().
                  3. Adding the "if getCurrentBarIndex() == 0" around your MAIN ENTRY/EXIT conditions.

                  Hope helps others.

                  Brad
                  Brad Matheny
                  eSignal Solution Provider since 2000

                  Comment


                  • #39
                    Brad,

                    None of that solves the problem of having to make sure that your close time is a even division of your interval or else historical results of backtesting will have problems.

                    For RT, my more simple solution works well, but both methods will have problems with backtesting due to limitations on eSignals backtester.

                    Garth
                    Garth

                    Comment


                    • #40
                      Garth,

                      Im running a 10 minute chart, which closes at 4.05 then 4.15. the 4.15 wont have any ticks since the market is closed, so ill just adjust the 4.15 close to a 4.05 in ur code. a candle ends there so it should work...right?

                      ubo

                      Comment


                      • #41
                        Yes it should if the bar closes at 16:05 with the TT you use.

                        Garth
                        Garth

                        Comment


                        • #42
                          My earlier post...

                          Garth,

                          My earlier post was meant as a GENERAL HELP post to people trying to develop code to accomplish this type of task.

                          The fact still remains, and end time of 13:15 and simple use of the "Time Templates" is the key to the success of your BT code.

                          I appreciate all of the comments on this thread and hope my additions are taken well.

                          I believe Garth is more than capable of handling this thread. I don't want to step on any toes here. Just trying to add additional content to help others.

                          Brad
                          Brad Matheny
                          eSignal Solution Provider since 2000

                          Comment


                          • #43
                            anything either of you or alex post is greatly appreciated. im just trying to figure out which way is up

                            Comment


                            • #44
                              Brad,

                              You are not stepping on any toes, but since you were not clear on the intent of your post, it needed to be made clear. Otherwise some poor newbie coder might think the post was the answer to the question outstanding, rather than general education. That could lead to days of coding for them, that in the end doesn't get them to where they thought they would be....

                              G
                              Garth

                              Comment


                              • #45
                                I know this is an older thread but I was hoping that the discussion of time limits could extend to my problem.

                                I was wondering if I could use the time on my computer or on eSignal (as opposed to the bar in my chart on whatever timescale) to close a trade at the end of the day. So I would have some simple code like - if systemtime=xxxx and strategy is in trade then close.

                                This could then be applied to a P+F chart or 3PB, for example, where there may not be a specific entry 5min before time or to a 15min chart but to exit 5mins from time.

                                Thanks
                                Rob
                                Last edited by RobMc; 12-12-2003, 08:05 AM.

                                Comment

                                Working...
                                X