Page 1 of 1

Cannot subscribe to events problem

PostPosted: Fri Nov 25, 2016 12:40 pm
by Loggy48
I have a problem which must be in my strategy but I cannot see it.

I am trying to subscribe to events so that I can trace stoploss and other things.

I have a strategy that has been doing this for a long time now without difficulty although it needs some improvement to monitor the CustomID/QTXT so that I avoid interference with any other strategy or manual intervention.

But for some reason I cannot trace the events.

Here is a totally stripped down strategy that doesn't actually trade but should report the events via AsyncOperationFinished:

Code: Select all
function Init()
   strategy:description("No flesh")
local TRADE_EVENT = 1001
local ORDER_EVENT = 1002
local OFFER_EVENT = 1003
local host =
local period = 0
function Prepare(onlyName)
   instance:name(profile:id() .. "(" .. .. ")")
   if onlyName then return end
   host:execute("subscribeTradeEvents", OFFER_EVENT , "offers")
   host:execute("subscribeTradeEvents", ORDER_EVENT , "orders")
   host:execute("subscribeTradeEvents", TRADE_EVENT , "trades")   
function Update()
   period = period + 1
   xprint("Update entered "..period)
function AsyncOperationFinished(cookie, success, message)
   xprint("AOF entered with cookie "..cookie.." success "..success.." message "..message)
function xprint(txt)

As I said, very simple. I can import this and run it.

There are no error messages in the event logger other than the message from Update - ie I do not see a message "AOF entered..... " at all which should occcur whenever an offer, order or trade is made on the instrument.

This occurs on two PCs so I don't think it is a PC setting at all and previously it was working perfectly well.

Re: Cannot subscribe to events problem

PostPosted: Fri Nov 25, 2016 6:56 pm
by Loggy48
(er, yes, it requires a tostring() round the success boolean :) ).

This skeleton strategy (and its more complex relation) appears to work OK both in simulation mode and in backtesting but not on my Demo account on which I was testing it, although I have another strategy that worked OK on the Demo account.

Very puzzling but at least with simulation I can trace what is happening.