TS code using “date of next bar” command with two data sources

Discussion in 'Data Sets and Feeds' started by Jock, Mar 26, 2007.

  1. Hi Jock,

    It should not take long. You can try it out.


    If (marketposition = 0 and entrydate(1) < date) then...

    This is a combination of two boolean. Only when both are True then the combined condition is True. Can EntryDate(1) < Date be False?

    I actaully don't understand what you want to do with:
    If (marketposition = 0 and entrydate(1) < date) then buy at OpenD(0) + 0.3*AvgTrueRange(1) of data2 stop;

    Edited to add:
    When is this order issued?
     
    #11     Mar 28, 2007
  2. Dear Jock,

    You will need to take care of the initial values of DATR when the number of days is less than 20. Something like this:


    Var: NumOfDaysGoneBy(0);
    .
    .
    .

    {Daily TrueRange}
    DTR[19] = DTH - DTL;
    NumOfDaysGoneBy = NumOfDaysGoneBy[1] + 1;
    .
    .
    .

    {Daily ATR}
    if NumOfDaysGoneBy >= 20 then
    DATR = Sum/20;
    Else
    DATR = Sum/NumOfDaysGoneBy;


    Change to suit accordingly.
     
    #12     Mar 28, 2007
  3. Jock

    Jock

    I wish to make no more than one long entry each day therefore…

    marketposition = 0 is to ensure there is no existing open position on the current bar.

    entrydate(1) < date is to ensure that the date of the next entry is not the same date as the previous entry.

    Both conditions need to be true to ensure there is no more than one long entry each day.
     
    #13     Mar 28, 2007
  4. Hi Jock,

    Okay, I was confused by your earlier objective of issuing an order on the last 5-min bar of the day to be good for the first bar of the next day.

    Since in this case, the order is not for that purpose, yes, the earliest it can issue that order is on the close of the first 5-min bar of the day. So no order will be done out of this for the first 5-min bar. The earliest is the second bar of the day.
     
    #14     Mar 28, 2007
  5. Jock

    Jock

    ChoSingKum, after a break I’m back on to this same problem and I can’t get your suggestion of the array to work. Remember that we have 5-minute data as Data1 and daily data as Data2 and that we wish to calculate the daily ATR using Data1. So using the following …

    Code:
    Var: Counter(0), Sum(0), DTH(0), DTL(0), DATR(0);
    Array: DTR[2](0);
     
    {Shift DTR backwards to make room for latest}
    For Counter = 0 to 1 Begin
    DTR[Counter] = DTR[Counter + 1];
    End;
     
    {Daily TrueHigh}
    DTH = MaxList(CloseD(1),HighD(0));
     
    {Daily TrueLow}
    DTL = MinList(CloseD(1),LowD(0));
     
    {Daily TrueRange}
    DTR[2] = DTH - DTL;
     
    {Initialise Sum to zero}
    Sum = 0;
    
    {Summ all the DTR}
    For Counter = 0 to 2 Begin
    Sum = Sum + DTR[Counter];
    End;
    
    {Daily ATR}
    DATR = Sum/3;
    
    

    This code doesn’t generate the Daily Average True Range for the last 3 days. It calculates the Daily True Range in DTR[2] but it averages this true range (DTR) for the last 3 (5-minute) bars instead of last 3 days.
     
    #15     Apr 19, 2007
  6. Hi Jock,

    You miss out this line I wrote:

    "At the last 5-min bar of the day, do the following:

    Use a loop to move the ... "


    Note: I no longer come to this forum regularly.
     
    #16     Apr 23, 2007
  7. Here's part of a system someone shared a long time ago which addresses your *1 long trade per day only* issue.

    Code:
    Inputs: StartTime(935), EndTime(1555);
    Vars: MPos(0),TToday(0);
    
    If Date>Date[1] Then TToday=0;
    
    If MPos<>MarketPosition Then Begin
    	MPos=MarketPosition;
    	If MPos<>0 Then TToday=TToday+1;
    End;	
    
    If TToday=0 AND Time<EndTime AND Time>StartTime Then 
    Begin
            Buy next bar at ......................your logic here......................;
    End;
    
    


     
    #17     Apr 23, 2007