Times of entry and exit

All posts which do not fit into any other sections of the forum.

Moderator: admin

Times of entry and exit

Postby PirataTM » Wed Feb 15, 2012 2:00 pm

Hi all.

1 - You can programmatically run an order of two hours. For example, to enforce an order if it is between 07:00 and 19:00.

2 - It is possible that an order is executed programmatically, if the margin used is less than an amount. For example, not to execute an order if margin is less than 1000.

thank you very much
PirataTM
 
Posts: 14
Joined: Tue Jan 31, 2012 9:36 am

Re: Times of entry and exit

Postby sunshine » Thu Feb 16, 2012 2:09 am

Hi,
If you want to create a market order (i.e. open a trade), you can add the condition to the Update function of your strategy.
Code: Select all
function Init() --The strategy profile initialization
...
    strategy.parameters:addGroup("Time Parameters");
    strategy.parameters:addString("StartTime", "Start Time", "", "07:00:00");
    strategy.parameters:addString("StopTime", "Stop Time", "", "19:00:00");
...
end
function Prepare(nameOnly)     
...
    OpenTime = ParseTime(instance.parameters.StartTime);
    CloseTime = ParseTime(instance.parameters.StopTime);
...
end
...
function Update()
...
    if not(core.host:execute("isTableFilled", "accounts")) then
        return false;
    end

    local acctRow = host:findTable("accounts"):find("AccountID", ACCT)
    if acctRow ~= nil then
            usedMargin = acctRow:cell("UsedMargin");
    end
   if usedMargin > 1000 then
          local now = core.host:execute("getServerTime");
          now = now - math.floor(now);
          if now >= OpenTime and now <= CloseTime then
            -- create a market order (open a trade)
          end
   end
...
end
...
function ParseTime(time)
    local Pos = string.find(time, ":");
    local h = tonumber(string.sub(time, 1, Pos - 1));
    time = string.sub(time, Pos + 1);
    Pos = string.find(time, ":");
    local m = tonumber(string.sub(time, 1, Pos - 1));
    local s = tonumber(string.sub(time, Pos + 1));
    return (h / 24.0 +  m / 1440.0 + s / 86400.0),                          -- time in ole format
           ((h >= 0 and h < 24 and m >= 0 and m < 60 and s >= 0 and s < 60) or (h == 24 and m == 0 and s == 0)); -- validity flag
end
...
sunshine
 

Re: Times of entry and exit

Postby PirataTM » Thu Feb 16, 2012 9:00 am

Sunshine thank you very much.
PirataTM
 
Posts: 14
Joined: Tue Jan 31, 2012 9:36 am


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 1 guest