Anyways, as we know if we use the ChartData.Close(1) method to get the previous bar close price, it will return the close price of the time frame selected in the builder, let's say in the builder I select the lower timeframe.
But as the block I want to develop is used in a multi timeframe strategy, I need the close price of the daily bar.
So I used the method ChartData.CloseD(1) to get the previous day close price. But unfortunately it doesn't return the previous day close price. It always return the value 0.
Same thing for other daily price methods OpenD(), LowD() and HighD().
so this is just an example code, lets say we want to get a signal if yesterday close was bigger than two days ago close
package SQ.Blocks.Indicators.CandlePatterns; import SQ.Internal.ConditionBlock; import com.strategyquant.lib.*; import com.strategyquant.datalib.*; import com.strategyquant.tradinglib.*; @BuildingBlock(name="Example Patern", display="Example Patern before (#Shift#) bars", returnType = ReturnTypes.Boolean) @Help("Is triggered when Example Patern is formed") public class ExamplePatern extends ConditionBlock { @Parameter public ChartData Chart; @Parameter(defaultValue="1") public int Shift; //------------------------------------------------------------------------ //------------------------------------------------------------------------ //------------------------------------------------------------------------ @Override public boolean OnBlockEvaluate() throws TradingException { double C = Chart.CloseD(Shift); double C1 = Chart.CloseD(Shift+1); if (C > C1) { return true; } return false; } }
the code above will not give any signal, it is because I used Chart.CloseD(), but if Instead I used Chart.Close() it will work correctly in the above code.
But again as I said before, for the block I'm trying to develop, it's used in multi timeframe strategy, so can't use Chart.Close() because it will give back the lower timeframe close price, this lower time frame is selected in the builder