Error in SQ_Ichimoku

I found a bug in SQ_Ichimoku when strategy was generated with Ichimoku.


In pseudo code:

//--------------------------------------------------------------------

// Trading rule: Trading signals (On Bar Open)

//--------------------------------------------------------------------                  

LongEntrySignal = ((BollingerBands(Main chart,92, 1.9, PRICE_CLOSE).Upper[5] < Close(Main chart)[5])

   and (Ichimoku(Main chart,9, 26, 12).ChikouSpan[1] < Close(Main chart)[1]));


ShortEntrySignal = ((BollingerBands(Main chart,92, 1.9, PRICE_CLOSE).Lower[5] > Close(Main chart)[5])

   and (Ichimoku(Main chart,9, 26, 12).ChikouSpan[1] > Close(Main chart)[1]));


And in el language,

//------------------------------------------------------------------

// Rule: Trading signals

//------------------------------------------------------------------

Value1= SQ_BollingerBands(Close, 92, 1.9, 0)[5];

Value2= Close[5];

Value3= SQ_Ichimoku(9, 26, 12, 4)[1];

Value4= Close[1];

LongEntrySignal = (Value1 < Value2) and (Value3 < Value4);




Value1= SQ_BollingerBands(Close, 92, 1.9, 1)[5];

Value2= Close[5];

Value3= SQ_Ichimoku(9, 26, 12, 4)[1];

Value4= Close[1];

ShortEntrySignal = (Value1 > Value2) and (Value3 > Value4);



But in the function, 


// line = 4 ??

Switch (Line)
Begin
 case 0: begin // tenkan sen
  SQ_Ichimoku = Tenkan_Sen;
  end;
  
 case 1: begin // kinjun sen
  SQ_Ichimoku = Kinjun_Sen;
  end;
 
 case 2: begin // senkou span a
  SQ_Ichimoku = Senkou_Span_A;
  end;
 
 case 3: begin // senkou span b
  SQ_Ichimoku = Senkou_Span_B;
  end;
End;


And I google that 

• Chikou span – plots the current closing price, 26 periods back;   (ref:  https://thesecretmindset.com/trade-ichimoku/)

It's the close 26 bars ago.

And I guess the calculation in SQ is wrong too. 

 SQ_Ichimoku(9, 26, 12, 4) is always ZERO. So there is only long trades, because that  the short condition will never be true. 


I have tested it with different backtest engine in SQ.






Attachments
No attachments
  • Votes 0
  • Project StrategyQuant X
  • Type Bug
  • Status Fixed
  • Priority Normal

History

e
#1

eastpeace

02.11.2019 08:03

Task created

e
#2

eastpeace

02.11.2019 08:40

Attachment Strategy 432250.sqx added

"It's the close 26 bars ago."

What I said is not correct.

Chikou span Line means  the current close shifted to left.  And it means comparing the current close and  the close 26 bars ago equivalently, I guess.

OR it may be not a good indicator value for strategy generating. 

What does "(Ichimoku(Main chart,9, 26, 12).ChikouSpan[1] < Close(Main chart)[1]));" really mean?

TB
#3

Tomas Brynda

18.02.2020 17:00
Hi eastpeace,

we have already dealt with this problem in past.


Chikou span is ussually current Close price plotted 26 bars ago. Programmatically it is quite a problem. 

All of the Ichimoku indicators found online deal with this simply graphically. They just plot current close price at the position 26 bars before current bar.


But to be able to compare backtest results between SQ and trading platforms, we need to have the data handled in-memory. 

Unfortunately, it can't be done, because we are unable to change past indicator buffer values, we can set values for the current bar only.


This problem has probably no other solution than just to ignore Chikou Span and don't use it in strategies. 


Best regards,

Tomas

b
#4

bentra

20.02.2020 23:15
What does "(Ichimoku(Main chart,9, 26, 12).ChikouSpan[1] < Close(Main chart)[1]));" really mean?

It actually means comparing the close of last bar with the close of a bar that hasn't even occurred yet...
TB
#5

Tomas Brynda

21.02.2020 10:04
That's right Bentra, thanks for the explanation.


Basically we can completely ignore ChikouSpan and use simple Close price instead.

TB
#6

Tomas Brynda

17.03.2020 16:04

Status changed from New to Fixed


Votes: 0

Drop files to upload

or

choose files

Max size: 5MB

Not allowed: exe, msi, application, reg, php, js, htaccess, htpasswd, gitignore

...
Wait please