Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. sellOrBuy=0;        risk=0;     BTCcorrection=BigDecimal.ZERO;
  2.  
  3.  // sellOrBuy<0 = bear
  4.  // sellOrBuy>0 = bull
  5.        
  6.  if(Global.emaCrossTrigger>0){ // calculated elsewhere
  7.      sellOrBuy-=Global.emaCrosspts/Global.holdstrongness;
  8.      points="\n\t\t  -EMA cross";
  9.  }else if(Global.emaCrossTrigger<0){
  10.      sellOrBuy+=Global.emaCrosspts;
  11.      points="\n\t\t  +EMA cross";
  12.  }
  13.  
  14.  if(Global.emaVsPriceTrigger==1){ // calculated elsewhere
  15.      sellOrBuy-=Global.emaVsPricepts/Global.holdstrongness;
  16.      points+="\n\t\t  -EMA vs price";
  17.  }else if(Global.emaVsPriceTrigger==-1){
  18.      sellOrBuy+=Global.emaVsPricepts;
  19.      points+="\n\t\t  +EMA vs price";
  20.  }
  21.  
  22.  if(Global.divergence<-Global.divergence_limit){ // calculated elsewhere
  23.      sellOrBuy-=Global.macdpoints;
  24.      points+="\n\t\t  -MACD";
  25.  }else if(Global.divergence>Global.divergence_limit){
  26.      sellOrBuy+=Global.macdpoints;
  27.      points+="\n\t\t  +MACD";
  28.  }
  29.  
  30.  if(Global.SmaVsPrice<-Global.SmaLimit){ // calculated elsewhere
  31.      sellOrBuy-=Global.SmaPts;
  32.      points+="\n\t\t  -SMA";
  33.  }else if(Global.SmaVsPrice>Global.SmaLimit){
  34.      sellOrBuy+=Global.SmaPts;
  35.      points+="\n\t\t  +SMA";
  36.  }
  37.  
  38.  
  39.  if(Global.vwapVsPrice<-Global.vwapLimit){ // calculated elsewhere
  40.      sellOrBuy-=Global.vwapPts;
  41.      points+="\n\t\t  -VWAP";
  42.  }else if(Global.vwapVsPrice>Global.vwapLimit){
  43.      sellOrBuy+=Global.vwapPts;
  44.      points+="\n\t\t  +VWAP";
  45.  }
  46.  
  47.  double resistPts=0;
  48.  
  49.  if(Global.ratioAvg.size()>=Global.ratioAvgHours*lib.ratioTimesInHour){ // enough data
  50.      
  51.      if(sellOrBuy>0 && Global.ratioTrend<-Global.ratioTrendLimit){
  52.          resistPts-=Global.ratioTrendPoints;
  53.          points+="\n\t\t  -Ratiotrend";
  54.      }else if(sellOrBuy<0 && Global.ratioTrend>Global.ratioTrendLimit){
  55.          resistPts+=Global.ratioTrendPoints;
  56.          points+="\n\t\t  +Ratiotrend";
  57.      }
  58.      
  59.  }
  60.  
  61.  
  62.  /*
  63.   * 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.
  64.   * The reverse is also true, when there are more buyers than sellers the price tends to gain strength
  65.   */
  66.  
  67.  // if bearish and more buyers than sellers (more bids than asks)
  68.  if(sellOrBuy<0 && Global.bidsVsAsks[1]>Global.bidsVsAsks[0] && (1-Global.nearRatio>=Global.asksVsBidsLimit)){
  69.      resistPts+=Global.asksVsBidsPts;
  70.      points+="\n\t\t  +thin asks";
  71.      
  72.  // if bullish and more sellers than buyers (more asks than bids)
  73.  }else if(sellOrBuy>0 && Global.bidsVsAsks[1]<Global.bidsVsAsks[0] && (Global.nearRatio-1>=Global.asksVsBidsLimit)){
  74.      resistPts-=Global.asksVsBidsPts;
  75.      points+="\n\t\t  -thin bids";
  76.  }
  77.      
  78.  
  79. double maxpts;
  80.  
  81.  if(sellOrBuy<0){    
  82.      maxpts=Global.emaCrosspts/Global.holdstrongness
  83.                     +Global.emaVsPricepts/Global.holdstrongness
  84.                     +Global.macdpoints
  85.                     +Global.SmaPts
  86.                     +Global.vwapPts;     
  87.  }else{
  88.      maxpts=Global.emaCrosspts
  89.                     +Global.emaVsPricepts
  90.                     +Global.macdpoints
  91.                     +Global.SmaPts
  92.                     +Global.vwapPts;     
  93.  }
  94.  
  95.  double SmaAdjust=0;
  96.  
  97.  if(!(Global.SmaAdjustsSensitivity==0)){
  98.      if(Global.SmaAdjustsSensitivity==-1){
  99.          SmaAdjust=(1+Math.abs(Global.SmaVsPrice/100));
  100.          if(SmaAdjust>1.999)  SmaAdjust=1.999;
  101.      }else{
  102.          SmaAdjust=(1-Math.abs(Global.SmaVsPrice/100));
  103.          if(SmaAdjust<0.001) SmaAdjust=0.001;
  104.      }
  105.      
  106.      risk=sellOrBuy/(Global.sensitivity*SmaAdjust);  
  107.  }else{
  108.      risk=sellOrBuy/Global.sensitivity;
  109.  }
  110.  
  111.  temprisk=risk; // used in offline-test for pointsCSV to see the real %
  112.  if(risk>1){ // stake can be 100% at max
  113.      risk=1;
  114.  }else if(risk<-1){ // or -100%
  115.     risk=-1;
  116. }
  117.  
  118. tempPrice= Global.ticker.getLast();
  119. tickerLag=lib.unixtime()-Global.ticker.getTime();
  120.  
  121. walletInBTC=Global.balance[0].add(Global.balance[1].divide(tempPrice,8,RoundingMode.HALF_UP)); 
  122.  
  123. // btcBalancer calculates how much BTC you should have with the risk-% ...
  124. // ... it is later used in Trade() method if we are going to sell or buy some
  125. BTCcorrection = btcBalancer(risk);
  126.  
  127. // in config we've set minimum difference so we dont buy/sell at little changes so we do buys and sells in bigger steps
  128. riskAndStakeDifference = Math.abs(Global.inBTC -Global.inBTCpercentWanted);
  129.  
  130. // With the new risk management this is the only way to "resist" trading as there is a min. limit for StakeVsRiskDivergence...
  131. if(BTCcorrection.compareTo(BigDecimal.ZERO)<0 && resistPts>0){
  132.     riskAndStakeDifference*=(1-(resistPts)/maxpts);
  133. }else if(BTCcorrection.compareTo(BigDecimal.ZERO)>0 && resistPts<0){
  134.     riskAndStakeDifference*=(1+(resistPts)/maxpts);
  135. }