sellOrBuy=0; risk=0; BTCcorrection=BigDecimal.ZERO;
// sellOrBuy<0 = bear
// sellOrBuy>0 = bull
if(Global.emaCrossTrigger>0){ // calculated elsewhere
sellOrBuy-=Global.emaCrosspts/Global.holdstrongness;
points="\n\t\t -EMA cross";
}else if(Global.emaCrossTrigger<0){
sellOrBuy+=Global.emaCrosspts;
points="\n\t\t +EMA cross";
}
if(Global.emaVsPriceTrigger==1){ // calculated elsewhere
sellOrBuy-=Global.emaVsPricepts/Global.holdstrongness;
points+="\n\t\t -EMA vs price";
}else if(Global.emaVsPriceTrigger==-1){
sellOrBuy+=Global.emaVsPricepts;
points+="\n\t\t +EMA vs price";
}
if(Global.divergence<-Global.divergence_limit){ // calculated elsewhere
sellOrBuy-=Global.macdpoints;
points+="\n\t\t -MACD";
}else if(Global.divergence>Global.divergence_limit){
sellOrBuy+=Global.macdpoints;
points+="\n\t\t +MACD";
}
if(Global.SmaVsPrice<-Global.SmaLimit){ // calculated elsewhere
sellOrBuy-=Global.SmaPts;
points+="\n\t\t -SMA";
}else if(Global.SmaVsPrice>Global.SmaLimit){
sellOrBuy+=Global.SmaPts;
points+="\n\t\t +SMA";
}
if(Global.vwapVsPrice<-Global.vwapLimit){ // calculated elsewhere
sellOrBuy-=Global.vwapPts;
points+="\n\t\t -VWAP";
}else if(Global.vwapVsPrice>Global.vwapLimit){
sellOrBuy+=Global.vwapPts;
points+="\n\t\t +VWAP";
}
double resistPts=0;
if(Global.ratioAvg.size()>=Global.ratioAvgHours*lib.ratioTimesInHour){ // enough data
if(sellOrBuy>0 && Global.ratioTrend<-Global.ratioTrendLimit){
resistPts-=Global.ratioTrendPoints;
points+="\n\t\t -Ratiotrend";
}else if(sellOrBuy<0 && Global.ratioTrend>Global.ratioTrendLimit){
resistPts+=Global.ratioTrendPoints;
points+="\n\t\t +Ratiotrend";
}
}
/*
* It is very easy to see via the market depth when there are more sellers than buyers and when this happens the price tends to weaken.
* The reverse is also true, when there are more buyers than sellers the price tends to gain strength
*/
// if bearish and more buyers than sellers (more bids than asks)
if(sellOrBuy<0 && Global.bidsVsAsks[1]>Global.bidsVsAsks[0] && (1-Global.nearRatio>=Global.asksVsBidsLimit)){
resistPts+=Global.asksVsBidsPts;
points+="\n\t\t +thin asks";
// if bullish and more sellers than buyers (more asks than bids)
}else if(sellOrBuy>0 && Global.bidsVsAsks[1]<Global.bidsVsAsks[0] && (Global.nearRatio-1>=Global.asksVsBidsLimit)){
resistPts-=Global.asksVsBidsPts;
points+="\n\t\t -thin bids";
}
double maxpts;
if(sellOrBuy<0){
maxpts=Global.emaCrosspts/Global.holdstrongness
+Global.emaVsPricepts/Global.holdstrongness
+Global.macdpoints
+Global.SmaPts
+Global.vwapPts;
}else{
maxpts=Global.emaCrosspts
+Global.emaVsPricepts
+Global.macdpoints
+Global.SmaPts
+Global.vwapPts;
}
double SmaAdjust=0;
if(!(Global.SmaAdjustsSensitivity==0)){
if(Global.SmaAdjustsSensitivity==-1){
SmaAdjust=(1+Math.abs(Global.SmaVsPrice/100));
if(SmaAdjust>1.999) SmaAdjust=1.999;
}else{
SmaAdjust=(1-Math.abs(Global.SmaVsPrice/100));
if(SmaAdjust<0.001) SmaAdjust=0.001;
}
risk=sellOrBuy/(Global.sensitivity*SmaAdjust);
}else{
risk=sellOrBuy/Global.sensitivity;
}
temprisk=risk; // used in offline-test for pointsCSV to see the real %
if(risk>1){ // stake can be 100% at max
risk=1;
}else if(risk<-1){ // or -100%
risk=-1;
}
tempPrice= Global.ticker.getLast();
tickerLag=lib.unixtime()-Global.ticker.getTime();
walletInBTC=Global.balance[0].add(Global.balance[1].divide(tempPrice,8,RoundingMode.HALF_UP));
// btcBalancer calculates how much BTC you should have with the risk-% ...
// ... it is later used in Trade() method if we are going to sell or buy some
BTCcorrection = btcBalancer(risk);
// in config we've set minimum difference so we dont buy/sell at little changes so we do buys and sells in bigger steps
riskAndStakeDifference = Math.abs(Global.inBTC -Global.inBTCpercentWanted);
// With the new risk management this is the only way to "resist" trading as there is a min. limit for StakeVsRiskDivergence...
if(BTCcorrection.compareTo(BigDecimal.ZERO)<0 && resistPts>0){
riskAndStakeDifference*=(1-(resistPts)/maxpts);
}else if(BTCcorrection.compareTo(BigDecimal.ZERO)>0 && resistPts<0){
riskAndStakeDifference*=(1+(resistPts)/maxpts);
}