0
Completed

Calculate Strategy When candle Close

Natalia da Fontoura 1 year ago updated by Андрей Ринас2 (ATAS developer) 1 year ago 1

How I can execute a strategy when the candle is close?For example the code above execute a BUY order when candle is UP else SELL order, but is opening orders during the candle is being created :
protected override void OnCalculate(int bar, decimal value)
{
var candle = GetCandle(bar);

if (ctrlSetup.IsUp(candle))
{
OpenPosition(OrderDirections.Buy);
}
else
{
OpenPosition(OrderDirections.Short);
}

}

Regards,Natalia

Answer

Answer
Completed

You can compare bar number in each call of OnCalculate.

Sample:

int _lastBar=-1;
protected override void OnCalculate(int bar, decimal value)
{
    if(bar==_lastBar)
        return;

    _lastBar=bar;
    //your code
}
Answer
Completed

You can compare bar number in each call of OnCalculate.

Sample:

int _lastBar=-1;
protected override void OnCalculate(int bar, decimal value)
{
    if(bar==_lastBar)
        return;

    _lastBar=bar;
    //your code
}