in.kncsolutions.dhelm.candlepattern.multiline.BullishSidebySideWhiteLines Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of dhelm-candlepattern Show documentation
Show all versions of dhelm-candlepattern Show documentation
This library provides the necessary implementations to screen the following patterns:
Bullish Belt Hold
Bearish Belt Hold
Hammer
Hanging Man
Southern Doji
Northern Doji
Gapping Up Doji
Gapping Down Doji
Takuri Line
One Candle Shooting Star
Bullish Strong Line
Bearish Strong Line
Bullish Harami
Bearish Harami
Bullish Engulfing
Bearish Engulfing
Bullish Kicking
Bearish Kicking
Matching Low
Matching High
Bullish Harami Cross
Bearish Harami Cross
Bullish Doji Star
Bearish Doji Star
Dark Cloud Cover
Piercing Line
Descending Hawk
Homing Pigeon
Bullish Abandoned Baby
Bearish Abandoned Baby
Three Inside Up
Three Inside Down
Three Outside Up
Three Outside Down
Three White Soldiers
Three Black Crows
Morning Doji Star
Evening Doji Star
Morning Star
Evening Star
Upside Tasuki Gap
Downside Tasuki Gap
Bullish Side by Side White Lines
Bearish Side by Side White Lines
Rising Three Method
The newest version!
/**
*Copyright 2018 Knc Solutions Private Limited
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/
package in.kncsolutions.dhelm.candlepattern.multiline;
import java.util.*;
import in.kncsolutions.dhelm.candlebasic.*;
import in.kncsolutions.dhelm.exceptions.DataException;
import in.kncsolutions.dhelm.mathcal.Mathfns;
import in.kncsolutions.dhelm.mathcal.CandleFacts;
/**
*According to literature the bullish side by side white lines pattern is a three line pattern composed of a
*long candle with white body followed by two white candles, where the low of the latter two white candles are above the high of the first long white candle
*and opening and closing of the latter two candles are similar.
*/
public class BullishSidebySideWhiteLines{
private List Open=new ArrayList();
private List High=new ArrayList();
private List Low=new ArrayList();
private List Close=new ArrayList();
private int RefBody;
private int RefLength;
private int RefTrend;;
private double Percentage;
private double []trendPrior={0,0};
private boolean isBullishSidebySideWhiteLines;
/**
*@param open : List of opening prices where first element is the latest data.
*@param high : List of high prices where first element is the latest data.
*@param low : List of low prices where first element is the latest data.
*@param close : List of closing prices where first element is the latest data.
*@param numBody : Number of previous periods w.r.t which it is to be found that if the latest candle's body is greater than the average body length of those past consecutive periods or not.
*@param numLen : Number of previous periods w.r.t which it is to be found that if the latest candle is long or short.
*@param numTrend : Number of previous periods w.r.t which the previous trend have to be approximated.
*@param percentage : The percentage by which if the latest candle is longer than the previous candles, it will be treated as a long candle, otherwise short.
*@throws DataException if sufficient data not available.
*/
public BullishSidebySideWhiteLines(List open,List high,List low,List close,int numBody,int numLen,int numTrend,double percentage)throws DataException{
Open.addAll(open);
High.addAll(high);
Low.addAll(low);
Close.addAll(close);
RefBody=numBody;
RefLength=numLen;
RefTrend=numTrend;
Percentage=percentage;
isBullishSidebySideWhiteLines=false;
if(Open.size()<((RefTrend+3>RefLength) ? RefTrend+3 : RefLength)
|| (Open.size()!=Close.size() || Open.size()!=High.size() || Open.size()!=Low.size() )){
throw new DataException();
}
else{
BullishSidebySideWhiteLines();
}
}
/*
*
*/
private void BullishSidebySideWhiteLines()throws DataException{
if((Close.get(2)>Open.get(2)) && validBasicCandle(3)){
if((Close.get(1)>Open.get(1)) && Low.get(1)>High.get(2)){
if((Close.get(0)>Open.get(0)) && Low.get(0)>High.get(2)){
if(Math.abs(Close.get(1)-Close.get(0))/Math.min(Close.get(1),Close.get(0))<1 && Math.abs(Open.get(1)-Open.get(0))/Math.min(Open.get(1),Open.get(0))<1){
trendPrior=Mathfns.ComputeTrendLine(Close.subList(3,RefTrend+3),Close.subList(3,RefTrend+3).size());
if(trendPrior[0]<0)
isBullishSidebySideWhiteLines=true;
}
}
}
}
}
/*
*
*/
private boolean validBasicCandle(int i)throws DataException{
if(i==3 && (new WhiteCandle(Open.subList(2,Open.size()),High.subList(2,High.size()),Low.subList(2,Low.size()),Close.subList(2,Close.size()),RefBody,RefLength,Percentage)).isWhiteCandle()
|| (new LongWhiteCandle(Open.subList(2,Open.size()),High.subList(2,High.size()),Low.subList(2,Low.size()),Close.subList(2,Close.size()),RefBody,RefLength,Percentage)).isLongWhiteCandle()
|| (new WhiteMarubozu(Open.subList(2,Open.size()),High.subList(2,High.size()),Low.subList(2,Low.size()),Close.subList(2,Close.size()))).isLongWhiteMarubozu(RefLength,Percentage)
|| (new ClosingWhiteMarubozu(Open.subList(2,Open.size()),High.subList(2,High.size()),Low.subList(2,Low.size()),Close.subList(2,Close.size()))).isLongClosingWhiteMarubozu(RefLength,Percentage)
|| (new OpeningWhiteMarubozu(Open.subList(2,Open.size()),High.subList(2,High.size()),Low.subList(2,Low.size()),Close.subList(2,Close.size()))).isLongOpeningWhiteMarubozu(RefLength,Percentage)){
return true;
}
return false;
}
/*
*
*/
private boolean isShort()throws DataException{
double avgCandleLength=CandleFacts.getAverageLength(High.subList(1,High.size()),Low.subList(1,Low.size()),RefLength);
if((High.get(1)-Low.get(1))<=avgCandleLength*Percentage/100)return true;
return false;
}
/**
*@return Returns true if the bullish side by side white lines pattern is generated.
*/
public boolean isBullishSidebySideWhiteLines(){
return isBullishSidebySideWhiteLines;
}
}