Wrong open rate in the strategy tester. Bug ? Expand / Collapse
Author
Message
Posted 6/9/2010 5:54:42 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 8/6/2010 5:11:58 PM
Posts: 4, Visits: 17
Hello

I have developed a simple strategy that opens a position when a new candle is created. I use a simple CreateOrder, the opening rate of the trade is logically the opening rate of the new candle.

procedure OnNewCandle;
begin

  CreateOrder(History.Instrument, Account, Amount, bsBuy, ...);

  (...)

end;

I noticed significant differences between test mode and live mode (real) :

In live mode (left on the picture bellow), positions are open to the opening rate of the candles. This is normal.

In testing (right on the picture), it seems that the positions are open to the high rate of the candles, sometimes very far from the opening rate, which makes no sense.

Obviously, the performance of the strategy vary greatly between test mode and real mode.

Is this a bug?

Thanks for your help !

Johann

Post #1646
Posted 6/10/2010 11:05:15 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 8/6/2010 5:11:58 PM
Posts: 4, Visits: 17
Maybe an answer here: How about inputting a custom spread when backtesting?

I understand that the tester must extrapolate the intermediate rates but I thought the opening and closing was reliable ...

Is there any workaround to this issue ?

Thanks !

Johann
Post #1650
Posted 8/3/2010 4:47:19 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 8/6/2010 5:11:58 PM
Posts: 4, Visits: 17
Too many problems with ActTrader, crashes, bugs ... bye ActTrader, welcome MT4(5) !
Post #1828
Posted 8/5/2010 8:29:13 AM


Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 1/27/2012 12:53:25 PM
Posts: 201, Visits: 295
Hi, Johann
I like ActFX and would like to support my favorite language a bit.
Too many problems for a person who hasn’t enough time and desire to read manuals for some additional features that are unique in ActTrader.
As for other systems, there are a lot of problems in every platform: some of them are due to users' lack of knowledge, others are caused by the very platform.
As for the tester, there are several topics on this Forum according to these questions.
Your choice is your choice. Minds vary from man to man.

Best regards!

Edited: 8/5/2010 8:34:15 AM by eMoe
Post #1832
Posted 8/6/2010 4:46:51 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 8/6/2010 5:11:58 PM
Posts: 4, Visits: 17
Hi eMoe !

Thanks for your message.

I was sure that my message would provoke reactions! Too bad they do not come earlier ...

Which manual are you talking about? http://www.actfx.com/Manuals.aspx is a tutorial, not a manual (look at http://docs.mql4.com/ or http://www.mql5.com)
I am software architect, I have read hundreds of books and I think having some ideas about programming. I don't see which function is specific to ActTrader. Way be you can tell me ?
Is it possible to run a backtest over 10 years, during the weekend ? I think not, and I need it.
Another example : the expert that generates me the most regular profits uses (calls directly) an external .NET module for computing, among others, supports and resistances. Is this possible with ActFx ?

I took my first steps on algorihmic trading with ActFx. It was great and I thank it for that, but I think it lacks more (a lot of) advanced features and stability.

When a new version of ActFX becomes available, I will be happy to test it !

Johann

Post #1834
Posted 8/7/2010 7:54:35 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 2/3/2012 12:14:37 AM
Posts: 444, Visits: 817
Your Strategy may have to become a bit more complicated to get a more accurate picture of what is going on. Here is what I mean.


Two problems to consider, according to my system and my broker, at least:

1. Say that I run an Hour Strategy. This means that I want my OnNewCandle procedure to start every new candle at the top of the hour every hour. Well, it doesn't. Not for me at least. Sometimes the new candle starts at the top of the hour. Sometimes it starts at 20 minutes after the hour. Maybe it even starts at 10 minutes after the hour sometimes. To test your system and broker with the Tester, to see what time your candle opens, add the script "log('Time: ' +DateTimeToStr(Now));" directly under the OnNewCandle "begin." The results will show up under the "Log" tab. You may have to increase the line value in the Log-tab-box to see everything from start to finish. The scripting to use would look like this:

procedure OnNewCandle;
begin
  log('Time: ' +DateTimeToStr(Now));
  Point := History.Instrument.PointSize;


2. As has been noted here and there in this forum, the spread may make a difference. This is because the Spread seems to be activated at the beginning of the launch of a new open position. This means that your broker gets his money first... which is okay by me. In addition, there may be a difference based on which close/open price your broker supplies... the ask or the bid.


It seems to me that if you fix #1 above, #2 will be bearable. The fix for #1 has to do with using the lowest possible time scale that you can. The lowest possible time scale is the "1 Minute" time scale. Some Traders would say that the lowest is the Tick, and they might be right. But sometimes there is no Tick exactly at the top of the hour. And if there is, how do you determine which Tick it is? At least with the 1-Minute, you get the current Tick at the end/beginning of the correct minute. If it happens to be 20 seconds into the minute (remember, the 1-Hour History.Last(1).Close is often 20 minutes into the hour), at least it is much closer to the top of the hour than the 1-Hour History.Last(1).Close is.


So how do you find the minute that is at the top of the hour? Look at 2 o'clock. How do you find the exact minute at 2 o'clock... the minute that looks like "2:00:00"? Here it starts to get complicated. Here's what you need to do:

1. Set your Strategy to run in the 1-Minute History mode:
2. Next, use Delphi Pascal's "Copy" function as a substring finder to get the top of every hour.
3. Use a simple "for" loop to find the highest high and the lowest low for the hour. (But you may not need these, or the open price with your particular Strategy.)

Also, some of the standard ActTrader indicators will not work with this method. You may have to design your own indicators, from scratch, from formulae that you can find on the Internet. Because of this, you may be tempted to run in 1-Minute mode and simply extend the standard indicators time period to work with minutes.

For example. Let's say you are running a Linear Regression of 14 periods in the 1-Hour mode. Since there are 60 minutes to the hour, you might be tempted to multiply 60 x 14 (840), and run the Linear Regression at 840 on the 1-Minute mode. Doing this will not produce the same results as running a Linear Regression of 14 on a 1-Hour mode. Because of this, you will need to test and re-test.


One other thought. The Tester does not run the time periods the same way the Demo and Live run them. Your Strategy may run very well in the Tester, but produce bad results Live. Also, a Strategy that produces bad results in the tester, might be the ideal dream, Live, but you never find out because the bad Tester results scare you away from using it Live.


Below is a little script that is designed to find the minute that is at the top of the hour, and the Open, High, Low, and close for the minute ending at the top of the hour. It uses the Delphi Pascal "Copy" function. You will need to adapt the pieces to your particular Strategy. I use it for testing, and in some of my scripts. If you find a flaw in the script, please let me know. Other than that, see if you can figure out how it works.

//////////////////////////////////////////////////////////////////////////////////

const
  StrategyName = 'Historical Data';

var //declaration of the variables
  History: TCandleHistory;
  Account: TAccount;
  OpenOpen, HighHigh, LowLow, CloseClose, Point: Double;
  IntMin, IntMinPast, IntMinPastPast, LengthMin, i: Integer;
  NewMin, TextMin, SpaceMessage, SpaceHolder: String;
  CurMin, PreviousTime: TDateTime;

procedure OnCreate;
begin
  AddCandleHistorySetting(@History, 'History', '', CI_1_Minute, 100); //setting up the chart history
  History.OnNewCandleEvent := @OnNewCandle; //indicating the procedure to run when a new candle opens
  AddAccountSetting(@Account, 'Account', ''); //the account number
  AddStringSetting(@SpaceMessage, 'Log... 1 Day equals', '1440 Minutes.'); //spaceholder

end;

///////////////////////////////////////////////////////////////////////////

procedure OnStart;
begin
  Point := History.Instrument.PointSize;
  HighHigh:=0;
  LowLow:=History.Last(1).Low;
end;

///////////////////////////////////////////////////////////////////////////

procedure OnNewCandle;
begin
  Point := History.Instrument.PointSize;


  CurMin:=Time;
  TextMin:=TimeToStr(CurMin);
  LengthMin := Length(TextMin);


  if (LengthMin = 11) then
  begin
    NewMin:=Copy(TextMin, 4, 2);
    log('Length Min: ' +IntToStr(LengthMin)+ ' Eleven: ' +TextMin+ ' Sub Time Minute: ' +NewMin);
  end;

  if (LengthMin = 10) then
  begin
    NewMin:=Copy(TextMin, 3, 2);
    log('Length Min: ' +IntToStr(LengthMin)+ ' Ten: ' +TextMin+ ' Sub Time Minute: ' +NewMin);
  end;

  IntMin:=StrToInt(NewMin);

//********************

if (IntMin > IntMinPast)
and (IntMinPastPast > IntMinPast) then
begin

  OpenOpen:=History.Last(60).Open;
  HighHigh:=History.Last(1).High;
  LowLow:=History.Last(1).Low;
  CloseClose:=History.Last(1).Close;

  for i:=61-1 downto 1 do
  begin
    if (History.Last(i).Close > HighHigh) then
    begin
      HighHigh:=History.Last(i).Close;
    end;
    if (History.Last(i).Close < LowLow) then
    begin
      LowLow:=History.Last(i).Close;
    end;
  end;

  log('Time: ' +DateTimeToStr(Now)+ ' Open: ' +FloatToStr(OpenOpen)+ ' High: ' +FloatToStr(HighHigh)+ ' Low: ' +FloatToStr(LowLow)+ ' Close: ' +FloatToStr(CloseClose));

end;

//********************

IntMinPastPast:=IntMinPast;
IntMinPast:=IntMin;

end; // End OnNewCandle Procedure.




Edited: 8/7/2010 7:57:58 PM by black
Post #1836
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 (0 guests, 0 members, 0 anonymous members)
No members currently viewing this topic.
Forum Moderators: Admin

All times are GMT -5:00, Time now is 8:28pm


© 2009 Actforex.com Terms of Use