I want to buy/sell once the FastMA is above/below SlowMA when there is a minimum spread between them. However I want to buy/sell once the price comes back to touch the slow MA.
Below is my code:
protected override void OnBarUpdate()
{
CalculateOnBarClose = false;
// Condition set 1
if (EMA(8)[0] > EMA(LinReg(80), 32)[0]
&& (EMA(8)[0] - EMA(LinReg(80), 32)[0]) >= 0.00015)
{
if (CrossBelow (GetCurrentAsk(), EMA(LinReg(80), 32),1)) //need to see tick data but stay on 5 min chart!!
{
EnterLong(1, "Long");
}
}
// Condition set 2
if (EMA(8)[0] < EMA(LinReg(80), 32)[0]
&& (EMA(LinReg(80), 32)[0]) - EMA(8)[0] >= 0.00015)
{
if (CrossAbove (GetCurrentAsk(), EMA(LinReg(80), 32),1))
{
EnterShort(1, "Short");
}
}
}
However when using GetCurrentAsk() or Bid() in backtesting it uses the Close().
For example my problem is that when the price closes below the SlowMA i get long, but when it only touches the SlowMA and closes above, I do not get a signal to go long. This is the problem. I have turned the CalculateOnBarClose() = false so that it uses tick data, but because I am using a 5min chart, in the OnBarUpdate() it is still waiting for the close of the 5min candle.
It is driving me crazy. Anyway to set the buy once it touches the slow MA etc.?
Comment