First of all, I only tested this on backtesting since we are saturday.
I created a List<TickData> named tickRecord, which stores the following struct :
public struct TickData
public double Variation;
public void SetVariation(double _newPrice, double _oldPrice)
if (_newPrice > _oldPrice)
Variation = _newPrice - _oldPrice;
else if (_newPrice < _oldPrice)
Variation = -(_oldPrice - _newPrice);
Variation = 0;
When I try to set the Variation property through a for loop like this :
for (int i = tickRecord.Count - 1; i >= 0; i--)
if (i = 0)
// Do nothing
tickRecord[i].SetVariation(tickRecord[i].Bid, tickRecord[i - 1].Bid);
It doesn't work, Variation stays the same :
for i = 1 : 1,12879 - 1,12879 = 0
for i = 2 : 1,12879 - 1,12879 = 0
for i = 3 : 1,1288 - 1,12879 = 0
for i = 4 : 1,12879 - 1,1288 = 0
for i = 5 : 1,1288 - 1,12879 = 0
From my research I'd say, tickRecord[i].SetVariation(); is the problem.
But I can't find anywhere how to make it work or why does it do that.
I tried to do it outside of the loop like this :
bool isFirstTick = true;
currentData.Time = Server.Time;
currentData.Ask = Symbol.Ask;
currentData.Bid = Symbol.Bid;
currentData.Variation = 0;
isFirstTick = false;
currentData.SetVariation(currentData.Bid, tickRecord[tickRecord.Count - 1].Bid);
It still didn't work, same results...
I solved the problem by making a class instead of a struct