A piece of code that works in simluation but not in real

Moderator: admin

A piece of code that works in simluation but not in real

Postby ilnefopas » Fri Jan 11, 2019 11:13 am

Hi guys,

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.
ilnefopas
 
Posts: 26
Joined: Mon Dec 28, 2015 12:51 pm

Re: A piece of code that works in simluation but not in real

Postby ilnefopas » Tue Jan 15, 2019 12:00 pm

Anyone ?
ilnefopas
 
Posts: 26
Joined: Mon Dec 28, 2015 12:51 pm

Re: A piece of code that works in simluation but not in real

Postby Apprentice » Thu Jan 17, 2019 9:28 am

Most likely it is filtered out by row.FixStatus == "W"
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: A piece of code that works in simluation but not in real

Postby ilnefopas » Thu Jan 17, 2019 12:27 pm

Thanks Apprentice, but can you elaborate a bit cause :

- When I open the position, a S/L is set, so as far as I understand it is in "W" status until it gets hit or modified.
- Then when my condition is met, this S/L initially placed is moved to BE, so to find which order is the right one my understanding is that i need to have this W status filter.

Am I wrong ?
ilnefopas
 
Posts: 26
Joined: Mon Dec 28, 2015 12:51 pm

Re: A piece of code that works in simluation but not in real

Postby ilnefopas » Thu Jan 17, 2019 12:30 pm

PLUS like I said, it is working perfectly in simulation mode. Are the "W" status orders ignored during a simulation ?
ilnefopas
 
Posts: 26
Joined: Mon Dec 28, 2015 12:51 pm


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 8 guests