Page 1 of 1

Timer Reset

PostPosted: Fri Jan 27, 2017 4:04 pm
by ronald3rg
Hello,

I need some help with this. Am trying to figure out how to reset a timer after my contingent order is set.

I created a timer to set an expiration time to open orders but I need it to reset if order is executed for the order that follows.

Code: Select all
--timer start
if UseCOexpiry then
                Timer3 = core.host:execute("SetTimer", 777, (COxTimer*60))
   end


Currently it will run for set time and delete orders as set by user on a continuous basis but I need it to reset when a specific event happens. any ideas?


Best
Ron

Re: Timer Reset

PostPosted: Sat Jan 28, 2017 9:10 am
by Apprentice
Try a completely different approach.
Create a loop.
Inside the loop, go through the open entry orders, check the difference between the current time and position opening time, and subsequently close it if the difference exceeds the set parameters.

Re: Timer Reset

PostPosted: Sat Jan 28, 2017 2:15 pm
by ronald3rg
Thanks Apprentice I'll try that next if this doesn't work.

I created a separate function to start timer and its called upon when events are triggered. So at the commencement of a new contingent order I killtimer and then call upon the function to start the timer again.

Re: Timer Reset

PostPosted: Sun Jan 29, 2017 1:38 pm
by ronald3rg
Hello Apprentice,

Okay my method failed so am trying to implement your suggestion but am having trouble calling open time for order from table. this is what I have created.

Startegy already has loop that checks for conditions every second now within the loop I implemented your suggestions that calls upon the opetime of previous trades like so:

Code: Select all

 if UseCOexpiry then

          local opentime;
         

         opentime = getOpenTime("OCO");
          -- Delete CO1 after set  CO expiry Logic
         if haveTrades(nil, "OCO") and haveOrders(nil, "CO1")  and currentTime >= (opentime(nil,"OCO") + COxTimer) then
             core.host:trace("Deleting CO1 Time Expired. "..message)
             logger:info("   Deleting CO1 Time Expired. "..message);
            deleteOrders();
         end
end


So logic calls upon the getOpenTime function but am certain i am calling on the wrong information by using "open"
Code: Select all
-- returns open time of trade if ctxtadd matches trade's StoredValueCustomTXT
function getOpenTime(ctxtadd)
   local enum, row;
    local found = false;
   local opentime;
    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
           getRawCustomTXT(row.QTXT) == getRawCustomTXT(CustomTXT) and
           getStoredValueCustomTXT(row.QTXT) == ctxtadd then
           found = true;
         opentime = row.Open
        end
        row = enum:next();
    end
   
    return opentime;
end








any suggestions?

Best
Ron

Re: Timer Reset

PostPosted: Sun Jan 29, 2017 3:35 pm
by ronald3rg
I did replace

Code: Select all
opentime = row.Open


with
Code: Select all
  opentime = row.Time


However, it results in attempt to call local 'opentime' (a number value) before that when i replaced with time it was a nil value.