I want to develop a simple strategy to enter Market at a specific price when 1st two candles of day are green and supertrend is lower than close . I have written the following script
protected override void OnBarUpdate()
{
if (Bars.BarsSinceNewTradingDay >= 2)
{
bool cond1 = Close[Bars.BarsSinceNewTradingDay] > Open[Bars.BarsSinceNewTradingDay];
bool cond2 = Close[Bars.BarsSinceNewTradingDay - 1] > Open[Bars.BarsSinceNewTradingDay - 1 ];
bool cond3 = TSSuperTrend1.UpTrend[1] < Close[1];
bool cond4 = TSSuperTrend1.UpTrend[Bars.BarsSinceNewTradingDay] < Close[Bars.BarsSinceNewTradingDay];
var buffer = 0.50;
if(Close[0] > 700)
{
buffer = 1;
}
if(Close[0] > 2000)
{
buffer = 4;
}
if(cond1 && cond2 && cond3 && cond4)
{
var buyPrice = 0.00;
var stopLoss = 0.00;
if(High[Bars.BarsSinceNewTradingDay] > High[Bars.BarsSinceNewTradingDay - 1] )
{
buyPrice = High[Bars.BarsSinceNewTradingDay] + buffer;
stopLoss = Low[Bars.BarsSinceNewTradingDay];
}
else
{
buyPrice = High[Bars.BarsSinceNewTradingDay - 1 ] + buffer;
stopLoss = Low[Bars.BarsSinceNewTradingDay - 1] ;
}
EnterLongMIT(buyPrice,"ST");
SetStopLoss("ST",CalculationMode.Price,stopLoss,tr ue);
}
}
When I backtest it , the orders are filled below the buyPrice . I want to enter the market only if it's above buyPrice.
Comment