I've written a strategy which contains a piece of code in the PositionUpdate function that is making me mad.
Indeed, during an Indicore simulation or a TSII backtest, that code works perfectly BUT when I run the strategy in my account it never gets executed...and I get no error, nothing;
Here is the piece of code :
- Code: Select all
if GlobalRateBuy ~=0
then
if (coursclose >= GlobalRateBuy + DisToTarget * (bollsup - GlobalRateBuy)) and row.PL > Com
then
updatedstop = GlobalRateBuy + Com/pipfractionner;
MoveStopBE(updatedstop);
end
elseif GlobalRateSell ~= 0
then
if coursclose <= GlobalRateSell - DisToTarget * (GlobalRateSell - bollinf) and row.PL > Com
then
updatedstop = GlobalRateSell - Com/pipfractionner;
MoveStopBE(updatedstop);
end
end
What does it do ?
It does check a condition on the price (coursclose) and if that condition is met, it calls the MoveStopBE function which puts the stop at breakeven.
A few explanation with the variables :
- GlobalRateBuy and GlobalRateSell are 2 global variables that carry the rate at which the entry order got filled.
- bollsup and bollinf are the value of the upper and lower boll bands for a given tick
- Com is the fee charged by FXCM for round turn orders (expressed in pips)
- And of course PositionUpdate is called in ExtUpdate with the right variables like this PositionUpdate (Source.close[period],BB.BL[period],BB.TL[period])
Below is the code of my MoveStopBE function even if it won't probably be of any help as I think that the function never gets called.
- Code: Select all
function MoveStopBE(newstop)
local enum, row;
enum = core.host:findTable("orders"):enumerator();
row = enum:next();
while (row ~= nil) do
if row.AccountID == Account and row.QTXT == CustomID and row.FixStatus == "W" and row.Type == "S" and not(row.IsBuy)
then
valuemap = core.valuemap();
valuemap.Command = "EditOrder";
valuemap.AcctID = Account;
valuemap.OrderID = row.OrderID;
valuemap.BuySell = "S";
valuemap.Rate = newstop;
GlobalRateBuy = 0;
success, msg = terminal:execute(203, valuemap);
if not(success)
then
terminal:alertMessage(Instrument, instance.bid[instance.bid:size() - 1], "Stop move failed" .. msg, instance.bid:date(instance.bid:size() - 1));
return false;
else return true; ---ajouté le 1er sept
end
elseif row.AccountID == Account and row.QTXT == CustomID and row.FixStatus == "W" and row.Type == "S" and row.IsBuy
then
valuemap = core.valuemap();
valuemap.Command = "EditOrder";
valuemap.AcctID = Account;
valuemap.OrderID = row.OrderID;
valuemap.BuySell = "B";
valuemap.Rate = newstop;
GlobalRateSell = 0;
success, msg = terminal:execute(203, valuemap);
if not(success)
then
terminal:alertMessage(Instrument, instance.bid[instance.bid:size() - 1], "Stop move failed" .. msg, instance.bid:date(instance.bid:size() - 1));
return false;
else return true; ---ajouté le 1er sept
end
end
row = enum:next();
end
end
So again all works fine in simulation and backtest modes (meaning stop gets moved) but does not work in real conditions in a real account.
I guess I must be missing something obvious but I do not get what, so any help will be much appreciated.
Thanks,
Ben.