Comparing Price to Support

Back

I'm trying to basically set a trade to fire when the price of the current symbol goes above the 125 day high

but I'm confused on how to compare max to the current price dynamically. Line 34 is where my problem is.

namespace QuantConnect
{
public class MaxMinFutures : QCAlgorithm
{
private Maximum _max125;
private Maximum _max7;

public override void Initialize()
{
SetStartDate(2017, 1, 1);
var equity = AddEquity("SPY");
var future = AddFuture(Futures.Indices.SP500EMini);
future.SetFilter(TimeSpan.Zero, TimeSpan.FromDays(60));

// Indicators
_max125 = MAX(equity.Symbol, 125);
_max7 = MAX(equity.Symbol, 7);
}

public override void OnData(Slice slice)
{
if (!Portfolio.Invested)
{
foreach(var chain in slice.FutureChains)
{
var contract = (
from futuresContract in chain.Value.OrderBy(x => x.Expiry)
where futuresContract.Expiry > Time.Date.AddDays(5)
select futuresContract
).FirstOrDefault();

if (contract != null)
{
var _price = Securities[Symbols].Price;
if (_price > _max125){
var quantity = 1;
MarketOrder(contract.Symbol, quantity);
}
}
}
}
}

public override void OnEndOfDay() {
Liquidate();
}
}
}

 

Update Backtest







 
0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Hi Sean,

We can set the class's symbol member in Initialize

symbol = AddEquity("SPY").Symbol;

Then to get the latest price, we could use

var _price = Securities[symbol].Price;

See the attached backtest for reference.

Best,
Derek Melchin

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Update Backtest





0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.


Loading...

This discussion is closed