Try to see how to create an intraday strategy

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 :smile:, thanks in advance.

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

Thanks Bob! Will wait for that.

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! :+1: (If my code is correct of course.)

Happy trading!

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.

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)?

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

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!):

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.

Add this command after your Sell logic:

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