# Try to see how to create an intraday strategy

**URL:** <https://forums.collective2.com/t/try-to-see-how-to-create-an-intraday-strategy/8770>\
**Category:** Seetu\
**Created:** [July 6, 2016, 6:46am UTC](https://forums.collective2.com/t/try-to-see-how-to-create-an-intraday-strategy/8770 "2016-07-06T06:46:06Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![XinXu](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/xinxu/32/1487_2.png) [@XinXu](https://forums.collective2.com/u/XinXu)\
**Post date:** [July 6, 2016, 6:46am UTC](https://forums.collective2.com/t/try-to-see-how-to-create-an-intraday-strategy/8770/1 "2016-07-06T06:46:06Z")

</div>

Hi:  
I am new to seetu. Try to create a intraday strategy (day trade only). I am using **5min** bar.  
Looked the reference of all function and sample code, still have many questions, let me ask one by one:  
1, how to get the highest/lowest price in first 30mins? (frm 9:30 to 10AM, within six 5min bar)?  
2, How to do if I want to put a BUY or SELL if 3 consecutive bars above lowest(or below highest)price?

Let me start with the two questions 😄, thanks in advance.

---

<div class="post-metadata">

**Author:** ![BobSvan2](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/bobsvan2/32/21391_2.png) [@BobSvan2](https://forums.collective2.com/u/BobSvan2)\
**Post date:** [July 8, 2016, 10:15am UTC](https://forums.collective2.com/t/try-to-see-how-to-create-an-intraday-strategy/8770/2 "2016-07-08T10:15:52Z")

</div>

Hi!  
I think we need to implement some functions from the Lowest/Highest category for that.  
Stay tuned!

---

<div class="post-metadata">

**Author:** ![XinXu](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/xinxu/32/1487_2.png) [@XinXu](https://forums.collective2.com/u/XinXu)\
**Post date:** [July 9, 2016, 6:07am UTC](https://forums.collective2.com/t/try-to-see-how-to-create-an-intraday-strategy/8770/3 "2016-07-09T06:07:16Z")

</div>

Thanks Bob! Will wait for that.

---

<div class="post-metadata">

**Author:** ![BobSvan2](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/bobsvan2/32/21391_2.png) [@BobSvan2](https://forums.collective2.com/u/BobSvan2)\
**Post date:** [July 14, 2016, 8:46pm UTC](https://forums.collective2.com/t/try-to-see-how-to-create-an-intraday-strategy/8770/4 "2016-07-14T20:46:56Z")

</div>

Hello!  
I have something for you.  
Try the following code.

```
SetOption("Periodicity",MINUTE5);
SetOption("ApplytoRecentDays", 120);

// Get times to the array
tn = TimeNum();
// Time range - adjust to your needs
startTime = 093000; // start in HHMMSS format
endTime = 100000; // end in HHMMSS format

// Prepare TRUE where your time range is valid
timeOK = tn >= startTime AND tn <= endTime;

// We need to know when a new day starts
day = GetDay();
dayChange = day != Ref( day, -1 );

// When a new day starts, get first bars (when your time range is defined) and following bars filled by zero.
// In that array find the higest value. 
// All bars following the defined time range will be filled by the highest value found.
HH6 = GetHighestSinceEvent(dayChange, High * timeOK);

// The same for lowest value. But we have a problem with zeros here.
// Zeros are lower than prices in the Low array.
// Solution: get the first bars and fill remaining array slots by the infinite value.

prepareLows = IIF(timeOK,Low,Inf);

// All bars following the defined time range will be filled by the lowest value found.
LL6 = GetLowestSinceEvent(dayChange, prepareLows);

// Define times for Buy and Sell. 
// The main reason is to exclude our time range defined at the beginning of the day from investigation,
// because we are looking 3 bars back after that time range and we don't want to look there.
// It also means that the first Buy / Sell can be at endTime + 3 bars at first.
buySellTimeOK = tn >= 101500 AND tn <= 154500;

// Strategy logic
Buy = buySellTimeOK
      and Ref(Close,-1) < Ref(LL6,-1)
      and Ref(Close,-2) < Ref(LL6,-2)
      and Ref(Close,-3) < Ref(LL6,-3);

Sell = buySellTimeOK
      and Ref(Close,-1) > Ref(HH6,-1)
      and Ref(Close,-2) > Ref(HH6,-2)
      and Ref(Close,-3) > Ref(HH6,-3);

// Use Exploration to visualize data
FILTER = 1;
AddColumn(Close,"Close");
AddColumn(High,"High");
// AddColumn(HH6,"HH6");
AddColumn(Low,"Low");
// AddColumn(LL6,"LL6");
AddColumn(Buy,"Buy");
AddColumn(Sell,"Sell");

```

Not bad running for MSFT! 👍 (If my code is correct of course.)

![](https://yyz2.discourse-cdn.com/flex028/uploads/collective2/3153/7a46af70693e8dc8.png)

Happy trading!

---

<div class="post-metadata">

**Author:** ![XinXu](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/xinxu/32/1487_2.png) [@XinXu](https://forums.collective2.com/u/XinXu)\
**Post date:** [July 15, 2016, 7:17am UTC](https://forums.collective2.com/t/try-to-see-how-to-create-an-intraday-strategy/8770/5 "2016-07-15T07:17:57Z")

</div>

thanks a lot Bob! Looks like a great start.  
I tried it on one symbol -AGN, 2016-07-11, it is a perfect example to buy the bottem.  
from 9:30 to 10:00, first 6 bar lowest close price is ~237.9. 3 bar from 10:15 to 10:25 close price is higher than 237.9.  
It shall trigger buy, but i didn’t see buy = 1. Can you check why?  
Attaching the chart and exploration result.  
 ![](https://yyz2.discourse-cdn.com/flex028/uploads/collective2/3156/b217aab2065bb20c.jpg) ![](https://yyz2.discourse-cdn.com/flex028/uploads/collective2/3157/356b915e7cbedfd9.jpg)  
Also how to get the actual price at the buy time(when buy triggered)?  
How to set stop price or close at the market close (since this is day trade only)?

---

<div class="post-metadata">

**Author:** ![BobSvan2](https://yyz2.discourse-cdn.com/flex028/user_avatar/forums.collective2.com/bobsvan2/32/21391_2.png) [@BobSvan2](https://forums.collective2.com/u/BobSvan2)\
**Post date:** [July 15, 2016, 12:07pm UTC](https://forums.collective2.com/t/try-to-see-how-to-create-an-intraday-strategy/8770/6 "2016-07-15T12:07:02Z")

</div>

Ehh… I read your specification wrong and was trying to buy low and sell high. 😅

According your spec it should be:

```
Buy = buySellTimeOK
      and Ref(Close,-1) > Ref(LL6,-1)
      and Ref(Close,-2) > Ref(LL6,-2)
      and Ref(Close,-3) > Ref(LL6,-3);

Sell = buySellTimeOK
      and Ref(Close,-1) < Ref(HH6,-1)
      and Ref(Close,-2) < Ref(HH6,-2)
      and Ref(Close,-3) < Ref(HH6,-3);

```

But I am afraid that your spec needs some other algorithm modifications because it leads to many many trades and it is a clear loser even without commissions.

This is a result per your spec for MSFT (without any commissions!):

> [@XinXu](#):
>
> Also how to get the actual price at the buy time(when buy triggered)?

Try this filter for exploration:

```
FILTER = Buy;
AddColumn(Open,"Open");
AddColumn(Close,"Close");
AddColumn(Buy,"Buy");
AddColumn(Buyprice,"Buyprice");

```

You will find that the “BuyPrice” variable is used as a prices array for Buy and it contains values of “Close” by default.  
It can be changed to other values in the strategy code. For example: BuyPrice = Open;  
Other similar variables are SellPrice, ShortPrice and CoverPrice.

> [@XinXu](#):
>
> How to set stop price or close at the market close (since this is day trade only)?

Add this command after your Sell logic:

```
Sell = Sell or tn > 155000; // adds Sell if time > 15:50

```
