Dukascopy
 
 
Wiki JStore Search Login

Order display on chart in Historical Tester
 Post subject: Order display on chart in Historical Tester Post rating: 0   New post Posted: Thu 08 Nov, 2012, 13:13 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Dear Support,

I have a quite complicated strategy, which is using 4 indicators. The strategy runs on a 15min period, and creating orders in the onBar() function.

AFAIK, onBar() is called whenever a new bar/candle is created for the standard time frames.
Because of this, the first thing I do in the onBar() is check if the time frame is my selected time frame:
if ( (instrument.equals(selectedInstrument)) && (period.equals(selectedPeriod)))
{
...
}



If I run the strategy in the Historical Tester, sometimes I can see on the chart that an order is created in a candle, or above a candle. Why is this happening?
If I understand the concept properly, the onBar() function execution takes place whenever a candle is finished (and a new one is just started). So I would think that if I submit orders in the onBar() function (on the actual market price, so no conditional orders), they would appear on the opening position of the current candle. And not within the candle, or above the candle.

What I could think of (as the strategy is a bit complicated) is that the time the decision is made to submit an order, ticks passed by and the opening price of the current candle is already history. Could you confirm that this is the case?

I will attach 2 screenshots to indicate the problem.


Attachments:
Capture2.PNG [33.48 KiB]
Downloaded 523 times
Capture.PNG [59.05 KiB]
Downloaded 501 times
DISCLAIMER: Dukascopy Bank SA's waiver of responsability - Documents, data or information available on this webpage may be posted by third parties without Dukascopy Bank SA being obliged to make any control on their content. Anyone accessing this webpage and downloading or otherwise making use of any document, data or information found on this webpage shall do it on his/her own risks without any recourse against Dukascopy Bank SA in relation thereto or for any consequences arising to him/her or any third party from the use and/or reliance on any document, data or information found on this webpage.
 
 Post subject: Re: Order display on chart in Historical Tester Post rating: 0   New post Posted: Thu 22 Nov, 2012, 22:42 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Dear Support,

May I have a reply on this? Really curious what is going on...

Thanks and regards.


 
 Post subject: Re: Order display on chart in Historical Tester Post rating: 0   New post Posted: Thu 13 Dec, 2012, 10:57 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Dear Support,
Couple of weeks have past and I still havent got any reply on the subject. May I have one?
Is this a bug in the historical tester? Is this what I think it is? Or is it something else?
Please, if you have time, help me out here.

Thanks & regards.


 
 Post subject: Re: Order display on chart in Historical Tester Post rating: 0   New post Posted: Thu 13 Dec, 2012, 19:07 
JForex Master
User avatar

User rating:
Joined: Wed 16 Sep, 2009, 18:23
Posts: 1054
Location: Geneva, Switzerland
What is the period you perform the test on? The charts attached look like you do it on ticks? If Ticks, is there any ticks filter?

Do you take into account that the long positions should be compared to the ASK candles?

Whout be great if we could have a sample source code describing the problem. That would answer many questions.


 
 Post subject: Re: Order display on chart in Historical Tester Post rating: 0   New post Posted: Thu 20 Dec, 2012, 15:18 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Dear Support,

Thank you for your reply. I did some investigation during the past days, and here are my answers:

I used different periods (mostly 1min and 5min). I always run the historical tester with tick data, and with process all ticks. And tick filters are disabled on the platform, and in the strategy as well.

Quote:
Do you take into account that the long positions should be compared to the ASK candles?

I was not completely aware of this. I am also not sure if I submit orders properly, based on this ASK/BID candles/prices. Could you confirm that this is to proper way? I am interested in if the indicator calculation (especially the side parameter) is proper.
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException
{
    double RSI9;
    if ( (instrument.equals(selectedInstrument)) && (period.equals(selectedPeriod)))
    {
        //Long side
        RSI9 = indicators.rsi(instrument, selectedPeriod, OfferSide.BID, appliedPrice, 9, 0);
        if (RSI9 < rsiHighLimit)
            engine.submitOrder(createLabel(instrument), instrument, OrderCommand.BUY, amount, 0.0, 0.0, bidBar.getClose()-stopLoss*0.00001, bidBar.getClose()+takeProfit*0.00001);
   
        //Short side
        RSI9 = indicators.rsi(instrument, selectedPeriod, OfferSide.ASK, appliedPrice, 9, 0);
        if (RSI9 > rsiShortLimit)
            engine.submitOrder(createLabel(instrument), instrument, OrderCommand.SELL, amount, 0.0, 0.0, askBar.getClose()+stopLoss*0.00001, askBar.getClose()-takeProfit*0.00001);
    }
}


I have another issue with the above code (next to the initial one, when the order`s price is within a candle):
Whenever I submit an order with the above code, sometime the order`s price is different then the current candle`s open price. This is why we can see the order placed within the candle. When I calculate the stopLoss and takeProfit in the onBar() function, I use bidBar/askBar.getClose() price as a base, and add/substract my stopLoss/takeProfit values to this base price. But this base price (the bidBar/askBar.getClose()) is not the same as the order`s price (the price in which the order was submitted). Because of this, the SL/TP prices are not exactly stopLoss/takeProfit pips away from the order`s price. How can I solve this isseu? Would that be a solution to place the orders without SL/TP, and in the onMessage() function, when the order is filled, set the SL/TP prices using the order.getPrice() as base?


 

Jump to:  

  © 1998-2025 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com