Page 1 of 1

closing a trade and then immediately open a trade

PostPosted: Wed Aug 10, 2016 10:29 am
by nixlike
In my live account, I recently encountered a scenario where my code closed a trade successfully and then was supposed to enter a trade. The code that selects which side to enter does not appear to be executing, so the trade did not open. I suspect that this is the culprit for the live environment not opening the trade.

Code: Select all
if (not haveTrades(nil)) then

function haveTrades(BuySell)
   local enum, row;
   local found = false;
   enum = core.host:findTable("trades"):enumerator();
   row = enum:next();
   while (not found) and (row ~= nil) do
      if row.AccountID == account and
      row.OfferID == offer and
      row.QTXT == "perry" and
      (row.BS == BuySell or BuySell == nil) then
         found = true;
      end
      row = enum:next();
   end

   return found;
end


I suspect the trade tables have not been updated when the trade is closed. This code works in the strategy tester.

I would like to understand what I can do to implement some code that will work in the strategy tester and also live.

Thank you.

Jim Barker

Re: closing a trade and then immediately open a trade

PostPosted: Thu Aug 11, 2016 9:18 am
by Julia CJ
Hi Jim,

It is true. The table is updated a little bit later after closing. There is not the universal decision of your problem.
It is necessary to develop an algorithm specifically for the strategy. Usually, in this situation it would be better to create the flag “ to open the position at the first opportunity” and when such chance appears, you are able to open it.

Re: closing a trade and then immediately open a trade

PostPosted: Thu Aug 11, 2016 10:12 am
by nixlike
Thank you Julia for the confirmation. I also found corresponding documentation here regarding that.

http://www.fxcodebase.com/bin/beta/IndicoreSDK-3.0/help/web-content.html#terminal.execute.html

I will implement what you suggested.

Regards,
Jim Barker