package jforex.converted;
import java.awt.Color;
import com.dukascopy.api.*;
import com.dukascopy.connector.engine.*;
/** Disclaimer: The folllowing source code is to be used for troubleshooting purposes only.
* Please don't use it for strategy/indicator compilation.
*/
public class DodaStochastic extends MQL4ConnectorIndicator {

protected void initProperties() {
if (properties == null) {
properties = new Properties();
}
properties.setProperty("connector_recalculate_all", "true");
properties.setProperty("connector_calculate_once_per_bar", "true");
properties.setProperty("connector_max_bars", "500");
properties.setProperty("indicator_level1","20");
properties.setProperty("indicator_level2","80");
properties.setProperty("indicator_buffers","2");
properties.setProperty("indicator_maximum","100.00");
properties.setProperty("indicator_minimum","0.00");
properties.setProperty("indicator_separate_window","true");
properties.setProperty("indicator_color2","Red");
properties.setProperty("indicator_color1","Lime");
}
protected Color indicator_color2 = toColor(Red);
protected Color indicator_color1 = toColor(Lime);
@Configurable("") public double Slw=toDouble(8);
@Configurable("") public double Pds=toDouble(13);
@Configurable("") public double Slwsignal=toDouble(9);
@Configurable("") public int Barcount=toInt(2000);
int LastTradeTime = 0;
@IndicatorBuffer ("") public double[] ExtHistoBuffer = new double[0];
@IndicatorBuffer ("") public double[] ExtHistoBuffer2 = new double[0];
boolean BuyAlert=Bool(false);
boolean SellAlert=Bool(false);
public void SetLoopCount(int loops) throws JFException {
return ;
}
public void SetIndexValue(int shift, double value) throws JFException {
ExtHistoBuffer[shift]=value;
return ;
}
public void SetIndexValue2(int shift, double value) throws JFException {
ExtHistoBuffer2[shift]=value;
return ;
}
public double GetIndexValue(int shift) throws JFException {
if(true)return toDouble((ExtHistoBuffer[shift]));return 0.0;
}
public double GetIndexValue2(int shift) throws JFException {
if(true)return toDouble((ExtHistoBuffer2[shift]));return 0.0;
}
public int init() throws JFException {
SetIndexStyle(toInt(0),toInt(DRAW_LINE),toInt(STYLE_SOLID));
SetIndexBuffer(toInt(0),ExtHistoBuffer);
SetIndexStyle(toInt(1),toInt(DRAW_LINE),toInt(STYLE_SOLID));
SetIndexBuffer(toInt(1),ExtHistoBuffer2);
if(true)return toInt((0));return 0;
}
public int start() throws JFException {
double AA = 0.0;
double bb = 0.0;
double aa1 = 0.0;
double cnt1 = 0.0;
int shift = 0;
double cnt = 0.0;
double loopbegin = 0.0;
double loopbegin2 = 0.0;
double loopbegin3 = 0.0;
boolean first = true;
double prevbars = 0.0;
double sum = 0.0;
double smconst = 0.0;
double smconst1 = 0.0;
double prev = 0.0;
double prev1 = 0.0;
double prev2 = 0.0;
double prev3 = 0.0;
double weight = 0.0;
double linear = 0.0;
double MAValue = 0.0;
double MAValue2 = 0.0;
double mavalue3 = 0.0;
String MAstring = "";
double MyHigh = 0.0;
double MyLow = 0.0;
int counter = 0;
double Price = 0.0;
double Price1 = 0.0;
double tmpDevAA = 0.0;
AA = toDouble(0);
bb = toDouble(0);
aa1 = toDouble(0);
cnt1 = toDouble(0);
shift = toInt(0);
cnt = toDouble(0);
loopbegin = toDouble(0);
loopbegin2 = toDouble(0);
loopbegin3 = toDouble(0);
first = Bool(true);
prevbars = toDouble(0);
sum = toDouble(0);
smconst = toDouble(0);
smconst1 = toDouble(0);
prev = toDouble(0);
prev1 = toDouble(0);
prev2 = toDouble(0);
prev3 = toDouble(0);
weight = toDouble(0);
linear = toDouble(0);
MAValue = toDouble(0);
MAValue2 = toDouble(0);
mavalue3 = toDouble(0);
MAstring = toString("");
MyHigh = toDouble(0);
MyLow = toDouble(0);
counter = toInt(0);
Price = toDouble(0);
Price1 = toDouble(0);
tmpDevAA = toDouble(0);
SetLoopCount(toInt(0));
smconst=toDouble(2/(1+Slw));
smconst1=toDouble(2/(1+Slwsignal));
loopbegin=toDouble(loopbegin+1);
shift = toInt(0);
for( shift=toInt(Barcount);greaterThanOrEqualTo(shift, 0);shift--){
prev=toDouble(GetIndexValue2(toInt(shift+1)));
AA=toDouble(0);
tmpDevAA=toDouble((High(toInt(Highest(toInstrument(null),toPeriod(0),toInt(MODE_HIGH),toInt(shift+Pds),toInt(Pds))))-Low(toInt(Lowest(toInstrument(null),toPeriod(0),toInt(MODE_LOW),toInt(shift+Pds),toInt(Pds))))));
if (notEqual(tmpDevAA, 0)){
AA=toDouble(100*((Close(toInt(shift))-Low(toInt(Lowest(toInstrument(null),toPeriod(0),toInt(MODE_LOW),toInt(shift+Pds),toInt(Pds)))))/tmpDevAA));
}
MAValue2=toDouble(smconst*(AA-prev)+prev);
SetIndexValue2(toInt(shift),toDouble(MAValue2));
loopbegin=toDouble(loopbegin-1);
}
loopbegin2=toDouble(loopbegin2+1);
shift = toInt(0);
for( shift=toInt(Barcount-Pds);greaterThanOrEqualTo(shift, 0);shift--){
MyHigh=toDouble(-999999);
MyLow=toDouble(99999999);
counter = toInt(0);
for( counter=toInt(shift);lessThanOrEqualTo(counter, Pds+shift);counter++){
Price=toDouble(GetIndexValue2(toInt(counter)));
if (greaterThan(Price, MyHigh)){
MyHigh=toDouble(Price);
}
if (lessThanOrEqualTo(Pds, 0)){
MyHigh=toDouble(Price);
}
if (lessThan(Price, MyLow)){
MyLow=toDouble(Price);
}
if (lessThanOrEqualTo(Pds, 0)){
MyLow=toDouble(Price);
}
}
prev1=toDouble(GetIndexValue(toInt(shift+1)));
aa1=toDouble(GetIndexValue2(toInt(shift)));
bb=toDouble(0);
if (notEqual((MyHigh-MyLow), 0)){
bb=toDouble(100*(aa1-MyLow)/(MyHigh-MyLow));
}
MAValue=toDouble(smconst*(bb-prev1)+prev1);
SetIndexValue(toInt(shift),toDouble(MAValue));
loopbegin2=toDouble(loopbegin2-1);
}
loopbegin3=toDouble(loopbegin3+1);
shift = toInt(0);
for( shift=toInt(Barcount);greaterThanOrEqualTo(shift, 0);shift--){
prev2=toDouble(GetIndexValue2(toInt(shift+1)));
prev3=toDouble(GetIndexValue(toInt(shift)));
mavalue3=toDouble(smconst1*(prev3-prev2)+prev2);
SetIndexValue2(toInt(shift),toDouble(mavalue3));
loopbegin3=toDouble(loopbegin3-1);
}
if (greaterThan(ExtHistoBuffer[0], ExtHistoBuffer2[0])&&lessThan(ExtHistoBuffer[0], 20.1)&&lessThan(ExtHistoBuffer2[0], 20.1)&&equal(BuyAlert, false)){
Alert("Doda-Stochastic says Buy  ",Instrument()," at ",Close(toInt(0)));
BuyAlert=toBool(true);
SellAlert=toBool(false);
}
if (greaterThan(ExtHistoBuffer2[0], ExtHistoBuffer[0])&&greaterThan(ExtHistoBuffer[0], 80.1)&&greaterThan(ExtHistoBuffer2[0], 80.1)&&equal(SellAlert, false)){
Alert("Doda-Stochastic says Sell  ",Instrument()," at ",Close(toInt(0)));
BuyAlert=toBool(false);
SellAlert=toBool(true);
}return 0;
}

/**/};