finding highest/lowest entry price in "trades"-table?

Section for discussions related to indicators, use of indicators, and building of trading stategies using indicators.

Moderator: admin

finding highest/lowest entry price in "trades"-table?

Postby lalala987 » Mon Nov 11, 2013 4:28 am

Dear all

I'd like to find the highest/lowest entry price in the open trades table and return that as value (storage1) of a function.
Therefore i wrote 2 functions findhighestprice () and find lowestprice():


Code: Select all
function findhighestprice()
   local storage1, enum2, row2={},{};
   enum2 = core.host:findTable("trades"):find("TradeID", instance.bid:instrument()).Open;
    row2 = enum2:next();
 
   while row2 ~=nil do
     if row2.OPEN>storage1 then
      storage1=row2.OPEN;
     end;
     row2=enum2:next();
   end
 
   return storage1
 
end
 
function findlowesprice()
   local enum2, row2={},{};
   enum2 = core.host:findTable("trades"):find("TradeID", instance.bid:instrument()).Open;
    row2 = enum2:next();
 
   while row2 ~=nil do
     if row2.OPEN<storage1 then
      storage1=row2.OPEN;
     end;
     row2=enum2:next();
   end
 
   return storage1
 
end


I am getting the error: attempt to index a nil value for the line

Code: Select all
  enum2 = core.host:findTable("trades"):find("TradeID", instance.bid:instrument()).Open;


Q
    a) Is that an efficient way at all?
    a) What's the problem with the error message?

tnx & best regards!
lalala987
 
Posts: 28
Joined: Wed Jan 02, 2013 5:31 pm

Re: finding highest/lowest entry price in "trades"-table?

Postby Victor.Tereschenko » Mon Nov 11, 2013 11:23 pm

lalala987 wrote:Dear all

I'd like to find the highest/lowest entry price in the open trades table and return that as value (storage1) of a function.
Therefore i wrote 2 functions findhighestprice () and find lowestprice():


Code: Select all
function findhighestprice()
   local storage1, enum2, row2={},{};
   enum2 = core.host:findTable("trades"):find("TradeID", instance.bid:instrument()).Open;
    row2 = enum2:next();
 
   while row2 ~=nil do
     if row2.OPEN>storage1 then
      storage1=row2.OPEN;
     end;
     row2=enum2:next();
   end
 
   return storage1
 
end
 
function findlowesprice()
   local enum2, row2={},{};
   enum2 = core.host:findTable("trades"):find("TradeID", instance.bid:instrument()).Open;
    row2 = enum2:next();
 
   while row2 ~=nil do
     if row2.OPEN<storage1 then
      storage1=row2.OPEN;
     end;
     row2=enum2:next();
   end
 
   return storage1
 
end


I am getting the error: attempt to index a nil value for the line

Code: Select all
  enum2 = core.host:findTable("trades"):find("TradeID", instance.bid:instrument()).Open;


Q
    a) Is that an efficient way at all?
    a) What's the problem with the error message?

tnx & best regards!

Try this code:
Code: Select all
function findhighestprice()
    local storage1, enum2, row2={},{};
    enum2 = core.host:findTable("trades"):enumerator();
    row2 = enum2:next();

    while row2 ~= nil do
        if row2.Instrument == instance.bid:instrument() and
           row2.Open>storage1 then
            storage1=row2.Open;
        end

        row2 = enum:next();
    end
    return storage1;
end
...
“There are only three sports: bullfighting, motor racing, and mountaineering; all the rest are merely games.” (c) Ernest Hemingway
Victor.Tereschenko
FXCodeBase: Confirmed User
 
Posts: 121
Joined: Fri Nov 19, 2010 8:55 am

Re: finding highest/lowest entry price in "trades"-table?

Postby lalala987 » Tue Nov 12, 2013 1:35 am

Thank you very much, I got it working now!
lalala987
 
Posts: 28
Joined: Wed Jan 02, 2013 5:31 pm


Return to Discussions

Who is online

Users browsing this forum: No registered users and 5 guests