Announcement

Collapse
No announcement yet.

functions used on limited time (upon entry until exit)

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

  • functions used on limited time (upon entry until exit)

    Hello Forum,

    I got a problem, and after trying to realize different ideas without success, kindly ask for your help. Now, I will try to decompose the problem in different topics.

    1. I would like to have the analysis on 10 minutes interval, although the chart is showing 1 minute interval. I understood, that therefor I need to use 'efsInternal' to make the calculation on 10 minutes time frame.

    2. I want to do a calculation just if I am long, to analyze the relationship between the current bar one hand side and the last bar and the entry bar on the other hand side.
    Unfortunately, I don't understand how to avoid the function calculating all bars, but to let it start just on the day of entry.
    Basically I am looking for creating a series on a limited time beginning from the entry, ending at the exit.

    I deeply appreciate any help in that matter.

  • #2
    Well, let me ask some questions before I try to offer any help.

    You mention "one hand side" and "other hand side". Can you define these better for me? Are you talking "long/short"?

    Of so, what are you defining as your entry bars, exit bars and others?? Is this information entered into your code or in a database?? Or are these based on a system you've developed and have working in efs?

    Handling anything in EFS is somewhat simple in nature. I've learned you build arrays of data as needed and work with that data. Controlling long/short/flat can be handled many different ways. For anything that runs in REALTIME and operates TICK BY TICK, I like creating three simple logical values and using them to control my systems.

    var strategyisLong = false;
    var strategyisShort = false;
    var strategyisInTrade = false;

    If you can offer more info about your needs, I'll continue to try to help.
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      details of problem

      Hi Brad,

      Thank you very much for your help offered.


      The entry is triggered by an indicator and this is solved already.
      The stopp-calculation is based on a set of rules (on 10 minutes time frame, while the chart is showing 1 Minute data), and the problem ist within this.
      It is quite comparable to the Candlestick –'inside day' shape:

      Let's say the entry bar/period is #0, the bar before # -1 and the bar after the entry #+1 and so on.

      Once, when I know the finished entry bar # 0 in the 10 minutes-frame, (at beginning of bar #1) I want to check if # 0 is an inside bar against # -1 .
      if yes, then check if # 0 and # -1 is inside bar even against # -2
      if no, then finish the comparison

      According # 0 and # -1 against # -2:
      if yes, then check if #0 and # -1 and # -2 is inside bar even against # -3 and so on.
      if no, then finish the comparison
      and so on.

      When the bar # +1 is finished, I check (at beginning of # +2)
      # +1 against # 0,
      if yes, then # +1 and # 0 against # -1 etcetera.

      So, it is going forward and looking THEN back a few bars, and just if 'strategyisLong= true'.


      You write: I've learned you build arrays of data as needed and work with that data.
      In fact, for the purpose of backtesting, I tried to realize it with efsInternal (because of the shift of the time-frame) and series and variables. But I understand (not sure if it is right), that a series is calculated for all data in the beginning and whenever it is called by 'efsInternal'.
      However in the case described above,
      1. there is no use of doing it initially, because at that time, it is not known, when 'strategyisLong= true'.
      2. Furthermore, when 'strategyisLong= true' then there is no need to calculate all data, as just a few bars are checked against each other like written above.

      Hope, to have described the problem understandable.

      WS

      Comment


      • #4
        OK. There is an easy way to address this (IMHO).

        First, you need to store the ENTRY BAR TIME. This is the 1 minute (or whatever) time represented by the BAR that reflects the TIME OF ENTRY. This will be used to identify IF you are allowed to check the 10 minute data for the price formation.

        Second, you need to determine when you want to start checking for the 10 minute price formation. I assume from your post that you want this checked on the FIRST AVAILABLE NEW 10 MIN Bar after the entry bar.

        So, if the trade entered at 10:03, then you want to start checking for the 10 minute price formation at the END OF THE 10:10 bar (or the beginning of the 10:20 bar) - right?

        In order to store the BAR TIME for the entry, use the following code.

        vTime = getValue("Time", 0);
        vHour = vTime.getHours();
        vMin = vTime.getMinutes();
        vSec = vTime.getSeconds();
        vDay = vTime.getDate();
        vMonth = vTime.getMonth() +1;
        BarTime = (vHour*100)+vMin;

        (All of these have to be declared as VARs outside of main).

        The BarTime value will represent the LOCAL CHART (1 min) bar time for the trade entry (once you store it) - like this.

        nLongEntryTime = BarTime;

        You'll have to then use MATH to figure out when you can begin checking the 10 minute data for the price formation.

        First, you'll have to truncate the entry time to a whole 10 min value represented in time. This function should do what you want.

        function fTruncateTime2(nTime ,Interval) {
        // Interval should be passed as 10
        var tempHour = Math.floor(nTime/100);
        var tempMin = nTime - (tempHour * 100);
        // This will give you unique hour and minute values for the passed time.

        // now, we have to truncate the time as needed.
        tempMin = (Math.floor(tempMin/10)) * 10;


        return ((tempHour*100)+tempMin);
        }

        Then, inside main when you ENTER your trades, you'll want to call this truncate function to return the "rounded" time to your system.

        if (!Strategy.isLong()) {
        Strategy.doLong();
        Check10MinTime = fTruncateTime2(BarTime, 10);
        }

        At this point, you have truncated the entry time and stored the values needed to start checking for the 10 minute price formations.

        Next, you need to create some logic to handle the 10 min price formations and WHEN to check for them.

        So, in your main function, you'll need something like this..

        if ((strategy.isLong()) && (BarTime >= Check10MinTime+(2*10))) {
        // This is set to check 2 BARS after the truncated time.
        // Look for INSIDE BAR on 10 Minute Data
        if ( (high(-1, inv("10")) - low(-1, inv("10"))) <
        (high(-2, inv("10")) - low(-2, inv("10"))) ) {
        // Inside Bar - notice that I'm using -1 and -2 to look for this price formation. This is because I only want the LAST COMPLETED 10 min bars, not the CURRENT BAR (which may still be ticking).
        }

        }


        I really hope this helps and I know it's a lot of code to digest. If you have any further questions, please let me know?
        Last edited by Doji3333; 08-12-2009, 10:24 AM.
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          thanks

          Hello Brad,

          Thank you so much for your help! Without doubts, I would have never found this way my own.

          I THINK I understood your way to go and will give a try to build a study accordingly. It might take some time when new questions arise...

          Thank you sincerly once again and best regards.
          WS

          Comment

          Working...
          X