Page 1 of 1

confusion on the implement of strategy on demo account

PostPosted: Tue Jan 08, 2019 1:21 pm
by csshine
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

Re: confusion on the implement of strategy on demo account

PostPosted: Fri Jan 11, 2019 8:40 am
by Apprentice
If Market order is used, the price can vary based on current market conditions.
This is especially noticeable if you trade smaller time frames.

Re: confusion on the implement of strategy on demo account

PostPosted: Thu Jan 24, 2019 3:48 am
by timgleason
the price varies depending on the market conditions.