Hi LordTwig,
I'm not sure if you want to know if the price goes exactly to the 00 level or beyond. Obviously it is entirely possible the price could skip the 00 level so I assume that isn't what you want.
Either way, this kind of stuff is usually achieved by multiplying the number by it's precision, and rounding or taking the floor of the number, and then doing some kind of comparison. Like this:
- Code: Select all
local lastOne = -1;
function ExtUpdate(id, source, period)
local precision = instance.bid:getPrecision();
local n = 2;
local currentPrice = instance.bid[NOW];
local multiplier = math.pow(10, precision - n);
local a = currentPrice * multiplier;
local b = math.floor(a);
if (lastOne == -1) then
lastOne = b;
return;
end
if (a == b) then
core.host:trace("The price is exactly on the 00");
end
if (lastOne ~= b) then
lastOne = b;
core.host:trace("Signal! " .. currentPrice .. " broke " .. (b / multiplier));
else
core.host:trace(currentPrice);
end
end
Gives you the following output. You can see it generates a signal every time we cross the 00 levels.
- Code: Select all
1.34804
1.34802
1.34803
1.34805
1.34807
1.34805
Signal! 1.34796 broke 1.347
1.34797
1.34793
1.34794
1.34794
1.34793
Signal! 1.34804 broke 1.348
1.34806
The price is exactly on the 00
1.348
1.34805
1.34806
1.34815
Is that what you were looking for?
I hope you aren't trying to write a Grid strategy
Cheers,
MooMooFX