Delete entry order

Moderator: admin

Delete entry order

Postby sivanvega » Mon Nov 08, 2010 4:03 am

Hi,

I would like to know how to remove entry orders. My strategy is currently creating some of them but after some candles are not longer valid so I want to delete them.

Thanks in advance

Sergio.
sivanvega
 
Posts: 1
Joined: Mon Nov 08, 2010 3:55 am

Re: Delete entry order

Postby Timon55 » Mon Nov 08, 2010 6:28 am

Timon55
FXCodeBase: Confirmed User
 
Posts: 43
Joined: Thu Jul 15, 2010 5:35 am
Location: Omsk

Re: Delete entry order

Postby Karlo_Karlo » Fri Jan 07, 2011 6:02 am

The link gives no help unfortunately, because the main problem is to find the OrderID. Would appreciate if somebody gives the idea how to write the whole function.
Karlo_Karlo
Karlo_Karlo
 
Posts: 11
Joined: Fri Jan 07, 2011 4:48 am

Re: Delete entry order

Postby Timon55 » Fri Jan 07, 2011 9:52 am

Hello, Karlo.
You can find my answer in viewtopic.php?f=28&t=3107&p=7251#p7251
Timon55
FXCodeBase: Confirmed User
 
Posts: 43
Joined: Thu Jul 15, 2010 5:35 am
Location: Omsk

Re: Delete entry order/Edit stop order

Postby Karlo_Karlo » Sat Jan 08, 2011 11:16 am

Thank you very much Timon55,

I have implanted the Delete Entry Order code into the system, but could not test it yet - the market was closed.

My next problem is the Edit Stop Order. I still can't figure out how to identify the Market Stop Order which is to be edited. This Stop Order is generated from the Entry order's stop order.

I would very much appreciate your help.

Karlo
Karlo_Karlo
Karlo_Karlo
 
Posts: 11
Joined: Fri Jan 07, 2011 4:48 am

Re: Delete entry order

Postby Timon55 » Mon Jan 10, 2011 5:15 am

IMPORTANT NOTE: I do not test this code in the Marketscope. If you will have any problems please contact me.

Ok. Let's return to my previous example(http://fxcodebase.com/code/viewtopic.php?f=28&t=3107&p=7251#p7251) and make some changes to add a stop order editing feature.

First of all we need to add a variable to store TradeID:
Code: Select all
-- variables
local createOrderCookie = 103; -- cookie for create order command
local editStopOrderCookie = 104; -- cookie for edit stop order command
local aOrderID;
local mTradeId = nil;


Next we need to add a function that will be check for trade created from our entry order:
1. Get a trades table
2. Find row(trade) with OpenOrderID = aOrderID(previously created entry order)
3. If row(trade) is not empty then save TradeID of found row(trade)

Code: Select all
function checkForTrade()
    local tradesTable = core.host:findTable("trades");
    local aTradeRow = tradesTable:find("OpenOrderID",aOrderID);
    if aTradeRow ~= nil then
        mTradeId = aTradeRow.TradeID;
    end
end


And finally we should write a function to change stop order attached to previously found trade:
1. Get a trades table
2. Find row(trade) with TradeID = mTradeId(previously saved TradeID)
3. Check that found row(trade) is not empty
4. Check that found row(trade) has a stop order
5. Create an EditOrder request

Code: Select all
function changeStopOrder()
    local tradesTable = core.host:findTable("trades"); -- find trades table
    local aTradeRow = tradesTable:find("TradeID",mTradeId); -- find row for trade with ID=mTradeId
    if aTradeRow ~= nil then
        if aTradeRow.StopOrderID ~= nil then
            local valuemap = core.valuemap();
            valuemap.Command = "EditOrder";
            valuemap.OrderID = aTradeRow.StopOrderID; -- for limit order you should replace it with aTradeRow.LimitOrderID
            ..................................
            terminal:execute(editStopOrderCookie, valuemap);
        else
            core.host:trace("There is no stop order for the selected trade");
        end
    end
end


Complete code(two examples merged):

Code: Select all
-- variables
local createOrderCookie = 103; -- cookie for create order command
local editStopOrderCookie = 104; -- Cookie for edit stop order command
local aOrderID;
local mTradeId = nil;

function Update()
    checkForTrade(); -- This function will check if trade created from our entry order with ID=aOrderID is exist
    if mTradeId ~= nil then
        changeStopOrder();
    end
end

-- function for creating order
function CreateOrder()
     valuemap = core.valuemap();
      ................................
      terminal:execute(createOrderCookie, valuemap);
end

function changeStopOrder()
    local tradesTable = core.host:findTable("trades"); -- find trades table
    local aTradeRow = tradesTable:find("TradeID",mTradeId); -- find row for trade with ID=mTradeId
    if aTradeRow ~= nil then
        if aTradeRow.StopOrderID ~= nil then
            local valuemap = core.valuemap();
            valuemap.Command = "EditOrder";
            valuemap.OrderID = aTradeRow.StopOrderID; -- for limit order you should replace it with aTradeRow.LimitOrderID
            ..................................
            terminal:execute(editStopOrderCookie, valuemap);
        else
            core.host:trace("There is no stop order for the selected trade");
        end
    end
end

function checkForTrade()
    local tradesTable = core.host:findTable("trades");
    local aTradeRow = tradesTable:find("OpenOrderID",aOrderID);
    if aTradeRow ~= nil then
        mTradeId = aTradeRow.TradeID;
    end
end

function AsyncOperationFinished(cookie, success, message)
    if cookie == createOrderCookie and success then
        aOrderID = message;
    end
    if cookie == editStopOrderCookie then
        if success then
            core.host:trace("Stop order is changed successfully");
        else
            core.host:trace("An error occured while editing stop order: "..message);
        end
    end
end
Timon55
FXCodeBase: Confirmed User
 
Posts: 43
Joined: Thu Jul 15, 2010 5:35 am
Location: Omsk

Re: Delete entry order

Postby Karlo_Karlo » Sun Jan 16, 2011 7:32 am

I very much appreciate your assistance, Timon55,

It took me several days to put it all into my system and adjust all the details: ExtAsynch.. instead of Asynch.., etc. The 'Delete Unused Entry' and 'Edit Stop to Break-even' work now quite well.

What I wanted to suggest is that why don't we make a blog where all these rarely used functions would be given fully for the reference? This is something that you can't find in the SDK's documentation. So, it is very difficult for the newcomers to put the given expressions into the certain functions correctly. This question is addressed to the other members and administrators also.

Thank you again, Timon55. I wish I could do something so much useful like that for you in return.
Karlo_Karlo
Karlo_Karlo
 
Posts: 11
Joined: Fri Jan 07, 2011 4:48 am

Re: Delete entry order

Postby Karlo_Karlo » Wed Jan 19, 2011 4:26 pm

Hallo Timon55,

Once you have helped me to overcome some problems I thought perhaps you would answer to one question more, please.

When the Entry order is set by the system it is not always set on the right position. I have made it to be set 3 pips above/below the high/low of the last candle, but sometimes on some pares it is set right at the high/low point of the last candle. Moreover, sometimes when Entry becomes the Market order, its Stop order does not always move to zero point, as it should do, but goes somewhere close to zero, sometimes even 9 pips below or 6 pips above it.

How do you think, what can be the reason of such a strange behavior? :?

With many thanks
Karlo_Karlo
Karlo_Karlo
 
Posts: 11
Joined: Fri Jan 07, 2011 4:48 am

Re: Delete entry order

Postby Nikolay.Gekht » Fri Jan 21, 2011 12:51 pm

1) I'll check. Probably here is some problems or specific behavior on the server.
2) Condition orders level is just a desired level of the triggering. To be executed, the order must have the real market price which may occur a bit far from he desired price.

For example you set your sell stop at 1.00 price. The tick before the order triggering is 1.05 and then the next tick is 0.95. The condition is met, because the prices crosses/touches the price desired. However, there is no price 1.00 at the market, only 0.95, so the order is executed on that price. This is how external execution works. If you see that conditional orders are executed at the sharp price, that almost full proof that the broker is a "kitchen" (dealing desk) broker.
Nikolay.Gekht
FXCodeBase: Site Admin
 
Posts: 1235
Joined: Wed Dec 16, 2009 6:39 pm
Location: Cary, NC

Re: Delete entry order

Postby cwn6161 » Mon Apr 30, 2012 8:50 am

I took the code here to create an edit stop and edit limit set of functions. While the edit stop seems to be working great, the edit limit never works. I continually get the same error "price specified is invalid". Here is the limit function, I am currently passing in Source.close[period] as the limit value. Any clues as to why my stop edit works? The two functions are nearly identical.

the working edit stop function
Code: Select all
function changeStopOrder(stopValue)
    local tradesTable = core.host:findTable("trades"); -- find trades table
    local aTradeRow = tradesTable:find("TradeID",mTradeId); -- find row for trade with ID=mTradeId
   
    if aTradeRow ~= nil then
        if aTradeRow.StopOrderID ~= nil then
            local valuemap = core.valuemap();
            valuemap.AcctID = Account;
            valuemap.Command = "EditOrder";
            valuemap.OrderID = aTradeRow.StopOrderID;
            valuemap.Rate = stopValue;
            terminal:execute(editStopOrderCookie, valuemap);
        else
            core.host:trace("There is no stop order for the selected trade");
        end
    end
end


the broken edit limit function:
Code: Select all
function changeLimitOrder(limitValue)
    local tradesTable = core.host:findTable("trades"); -- find trades table
    local aTradeRow = tradesTable:find("TradeID",mTradeId); -- find row for trade with ID=mTradeId
   
    if aTradeRow ~= nil then
        if aTradeRow.LimitOrderID ~= nil then
            local valuemap = core.valuemap();
            valuemap.AcctID = Account;
            valuemap.Command = "EditOrder";
            valuemap.OrderID = aTradeRow.LimitOrderID;
            valuemap.Rate = limitValue;
            terminal:execute(editLimitOrderCookie, valuemap);
        else
            core.host:trace("There is no limit order for the selected trade");
        end
    end
end
cwn6161
 
Posts: 5
Joined: Tue Jan 24, 2012 1:22 pm

Next

Return to Indicator Development

Who is online

Users browsing this forum: No registered users and 29 guests