confusion on the implement of strategy on demo account

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

Moderator: admin

confusion on the implement of strategy on demo account

Postby csshine » Tue Jan 08, 2019 1:21 pm

My strategy on demo account seems running strange.
Image
Look at the image and will find that the close order rate exceeds the low and high rate of bar. It is very strange. Isn't the rate inside the bar? Same thing happened on the open order rate, too.
Why did this happen?
Here below is my code:
Code: Select all
-- enter into the specified direction
function MarketOrder(BuySell)
    valuemap = core.valuemap();

    valuemap.Command = "CreateOrder";
    valuemap.OrderType = "OM";
    valuemap.OfferID = OfferID;
    valuemap.AcctID = Account;
    valuemap.Quantity = Amount * BaseSize;
    valuemap.BuySell = BuySell;

    if IsNeedTrailing then
        valuemap.TrailStepStop = (IsNeedDynamicTrailing and 1 or TrailingStop);
    end

    if (not CanClose) and (instance.parameters.SetStop or instance.parameters.SetLimit) then
        valuemap.EntryLimitStop = 'Y'
    end

    success, msg = terminal:execute(200, valuemap);

    if not(success) then
        terminal:alertMessage(instance.bid:instrument(), instance.bid[instance.bid:size() - 1], "Open order failed" .. msg, instance.bid:date(instance.bid:size() - 1));
        return false, msg;
    end

    return true, msg;
end


Code: Select all
function closeOrder(TradeID)
    enum = core.host:findTable("trades"):enumerator();
    row = enum:next();

    while row ~= nil do
        if row.TradeID == TradeID and
                row.AccountID == Account then
            -- close trades immediatelly if we can close
            local valuemap = core.valuemap();
            valuemap.Command = "CreateOrder";
            valuemap.OrderType = "CM";
            valuemap.OfferID = row.OfferID;
            valuemap.AcctID = Account;
            valuemap.Quantity = row.Lot;
            valuemap.TradeID = row.TradeID;
            if row.BS == "B" then
                valuemap.BuySell = "S";
            else
                valuemap.BuySell = "B";
            end
            local success, msg = terminal:execute(200, valuemap);
            if not (success) then
                core.host:trace("current order close order failed:");
            else
                core.host:trace("current order close order success");
            end
        end
        row = enum:next();
    end
end
Attachments
111111111.png
csshine
 
Posts: 11
Joined: Wed Nov 28, 2018 6:16 am

Re: confusion on the implement of strategy on demo account

Postby Apprentice » Fri Jan 11, 2019 8:40 am

If Market order is used, the price can vary based on current market conditions.
This is especially noticeable if you trade smaller time frames.
User avatar
Apprentice
FXCodeBase: Confirmed User
 
Posts: 20385
Joined: Thu Dec 31, 2009 11:59 am
Location: Zagreb, Croatia


Return to Discussions

Who is online

Users browsing this forum: No registered users and 3 guests