braverock / quantstrat

287 stars 115 forks source link

Trying to create a signal for when intraday price crosses SMA or EMA #154

Open jrodzen opened 7 months ago

jrodzen commented 7 months ago

There seem to be plenty of examples of signals for crossovers between moving average functions but how would one go about creating a signal for when an intraday price crosses above or below a moving average? Or is there a function that even would use, for instance, the min price or max price of an equity within each day for comparison to, say, a 9 or 15 day SMA or EMA?

braverock commented 7 months ago

see:

?sigCrossover

sigCrossover takes the names of two columns. one could be your price filter (e.g. a moving average, as per your question) and the other could be a Close price (if using bars) or a Bid of Ask price (if using BBO), or any other column (e.g a 1% depth indicator). sigCrossover doesn't care which columns you want to compare, it just needs two column names in the columns argument.

jrodzen commented 7 months ago

Thanks for the quick reply! I'll give that a try.