Wrong Index in Buffer

How to create strategies and indicators
Message
Author
SquareMeal
Posts: 40
Joined: Wed Sep 15, 2010 6:52 am

Wrong Index in Buffer

#1 Postby SquareMeal » Wed Dec 29, 2010 11:47 pm

I'm trying to filter out tick data so my logic will only execute on the first tick of each new bar. I'm using the following logic to do the filtering:

Code: Select all

 if (Time(0)<>PrevTime) then
    begin
      PrevTime := Time(0);
    end
  else
    begin
    exit;
    end;

  if (Bars <= (3*24*2)) then exit;


However, this doesn't seem to be working. I suspect that many ticks which should be filtered out are falling past this point -- executing a trade before my internally managed averages are adequatly preloaded with enough bars.

Also, the indicators that are referenced lower in the program are giving me the following error messages (for example):

Wrong Index In Buffer: 1 (Stochastic)
Wrong Index In Buffer: 2 (Stochastic)
Wrong Index In Buffer: 1 (RSI)
Wrong Index In Buffer: 2 (RSI)

Eventually, I stop getting these error messages and everything seems to work fine from that point on.

Any ideas as to what is causing this?
creativity + willful purpose

FT Support
Posts: 905
Joined: Sat Jul 11, 2009 10:54 am

#2 Postby FT Support » Thu Dec 30, 2010 5:43 am

Hello,

Please try somehing like this:

Code: Select all


if (iOpen(Symbol, 1, 0) = iClose(Symbol, 1, 0) = iHigh(Symbol, 1, 0) = iLow(Symbol, 1, 0)) then
begin
...
end;

Check our other product here:
http://www.forexcopier.com

SquareMeal
Posts: 40
Joined: Wed Sep 15, 2010 6:52 am

#3 Postby SquareMeal » Thu Dec 30, 2010 9:25 pm

I tried it but got a compile error with the cursor blinking immediately after the first close parenthesis:

if (iOpen(Symbol,1,0)[cursor here]...

The error message reads: Incompatible types: got "Boolean" expected "Double"

I changed the line to the following format and it compiled to a clean DLL:

if (iOpen(Symbol,1,0) = iClose(Symbol,1,0)) and (iHigh(Symbol,1,0) = iLow(Symbol,1,0)) then...

When I ran the program, I got the following error messages:

2009.04.01 00:00:00 Error in strategy: ox40
2009.04.01 00:00:00 Wrong index in buffer: 1 (Moving average)
2009.04.01 00:00:00 Wrong index in buffer: 1 (RSI)
2009.04.01 00:00:00 Wrong index in buffer: 2 (RSI)
2009.04.01 00:00:00 Wrong index in buffer: 1 (Stochastic)
2009.04.01 00:00:00 Wrong index in buffer: 2 (Stochastic)
2009.04.01 00:00:00 Instant order #1 (USDJPY, buy, lot: 0.10, price: 99.39, sl: 0.00, tp: 0.00) was placed at price 99.39
2009.04.01 00:00:30 Wrong index in buffer: 1 (Moving average)
2009.04.01 00:00:30 Wrong index in buffer: 1 (Moving average)
etc.
Last edited by SquareMeal on Thu Dec 30, 2010 10:41 pm, edited 1 time in total.
creativity + willful purpose

SquareMeal
Posts: 40
Joined: Wed Sep 15, 2010 6:52 am

#4 Postby SquareMeal » Thu Dec 30, 2010 10:38 pm

I figured out my problem -- programmer error!

I did not realize that the "exit" command only takes you out of the current procedure or function. I thought it would exit my strategy and go back to ForexTester (which is only true if you are in the first procedure "GetSingleTick".

I had created a subroutine procedure to skip ticks (among other small tasks) until the end of bar -- so when I said "exit" it went back to GetSingleTick and fell into subsequent logic.

The following code is working for me. It only processes the first tick after the close of each bar:

Code: Select all

// in ResetStrategy...
PrevBars := -9999;

// then later in...
procedure GetSingleTick; stdcall;
begin
  if Symbol <> string(Currency) then exit;
  SetCurrencyAndTimeframe(Symbol, TimeFrame);
  GetCurrencyInfo(Symbol, info);
  if (PrevBars = -9999) then PrevBars := Bars;
  if (Bars = PrevBars) then exit else PrevBars := Bars; 
   
creativity + willful purpose


Return to “FT API”

Who is online

Users browsing this forum: No registered users and 10 guests