Timer Reset

Moderator: admin

Timer Reset

Postby ronald3rg » Fri Jan 27, 2017 4:04 pm

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
Right place at the right time

3Rg
ronald3rg
 
Posts: 39
Joined: Tue Oct 18, 2011 6:12 pm
Location: New York

Re: Timer Reset

Postby Apprentice » Sat Jan 28, 2017 9:10 am

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.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 36341
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia

Re: Timer Reset

Postby ronald3rg » Sat Jan 28, 2017 2:15 pm

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.
Right place at the right time

3Rg
ronald3rg
 
Posts: 39
Joined: Tue Oct 18, 2011 6:12 pm
Location: New York

Re: Timer Reset

Postby ronald3rg » Sun Jan 29, 2017 1:38 pm

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
Right place at the right time

3Rg
ronald3rg
 
Posts: 39
Joined: Tue Oct 18, 2011 6:12 pm
Location: New York

Re: Timer Reset

Postby ronald3rg » Sun Jan 29, 2017 3:35 pm

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.
Right place at the right time

3Rg
ronald3rg
 
Posts: 39
Joined: Tue Oct 18, 2011 6:12 pm
Location: New York


Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 8 guests

cron