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 ScalperPilotAdvisor extends MQL4ConnectorStrategy {

protected void initProperties() {
if (properties == null) {
properties = new Properties();
}
properties.setProperty("link","http:");
properties.setProperty("copyright","Copyright �2007 Forex on Autopilot");
}
@Configurable("") public int MinPrfofit=toInt(6);
@Configurable("") public int MaxLoss=toInt(5);
@Configurable("") public int Delta=toInt(3);
@Configurable("") public int BB_Period=toInt(1);
@Configurable("") public int BB_Deviation=toInt(2);
@Configurable("") public boolean FixLotMM=Bool(false);
@Configurable("") public double FixLotSize=toDouble(0.001);
@Configurable("") public double RiskPercent=toDouble(10.0);
@Configurable("") public int Slippage=toInt(0);
@Configurable("") public String Comm=toString("ScalperPilot Advisor");
boolean gi_128=Bool(true);
int g_magic_132 = 0;
int gi_unused_136 = 0;
double g_stoplevel_140 = 0.0;
double g_spread_148 = 0.0;
double g_maxlot_156 = 0.0;
double g_minlot_164 = 0.0;
double g_lotstep_172 = 0.0;
double g_lots_180 = 0.0;
double gd_188 = 0.0;
public int init() throws JFException {
gi_unused_136=toInt(0);
g_magic_132=toInt(StringGetChar(toString(Instrument()),toInt(0))+77704+StringGetChar(toString(Instrument()),toInt(1))*2+3*StringGetChar(toString(Instrument()),toInt(3))+StringGetChar(toString(Instrument()),toInt(4))<<2+10000*Period());
g_stoplevel_140=toDouble(MarketInfo(toInstrument(Instrument()),toInt(MODE_STOPLEVEL)));
g_spread_148=toDouble(MarketInfo(toInstrument(Instrument()),toInt(MODE_SPREAD)));
g_maxlot_156=toDouble(MarketInfo(toInstrument(Instrument()),toInt(MODE_MAXLOT)));
g_minlot_164=toDouble(MarketInfo(toInstrument(Instrument()),toInt(MODE_MINLOT)));
g_lotstep_172=toDouble(MarketInfo(toInstrument(Instrument()),toInt(MODE_LOTSTEP)));
HideTestIndicators(toBool(true));
if(true)return toInt((0));return 0;
}
public int start() throws JFException {
String ls_0 = "";
double l_price_8 = 0.0;
double l_price_16 = 0.0;
double ld_24 = 0.0;
boolean li_32 = true;
boolean li_36 = true;
int l_pos_40 = 0;
double l_ibands_44 = 0.0;
double l_ibands_52 = 0.0;
if (Bool(gi_128)){
ls_0=toString("http://ForexAutopilot.com");
Comment(ls_0);
}
if (!IsTradeAllowed()){
Comment("Error: This currency pair is not allowed or connection failed");
if(true)return toInt((0));}
Comment("");
if (Bool(FixLotMM)){
g_lots_180=toDouble(FixLotSize);
} else {
g_lots_180=toDouble(AccountFreeMargin()/1000.0*(RiskPercent/100.0));
}
if (lessThan(g_lots_180, g_minlot_164)){
g_lots_180=toDouble(g_minlot_164);
} else 
if (greaterThan(g_lots_180, g_maxlot_156)){
g_lots_180=toDouble(g_maxlot_156);
} else {
;
for( gd_188=toDouble(g_minlot_164);lessThanOrEqualTo(gd_188, g_lots_180);gd_188+=g_lotstep_172){
}
g_lots_180=toDouble(gd_188-g_lotstep_172);
}
for( l_pos_40=OrdersTotal()-1;greaterThanOrEqualTo(l_pos_40, 0);l_pos_40--){
OrderSelect(toInt(l_pos_40),toInt(SELECT_BY_POS));
if (notEqual(OrderSymbol(), Instrument())||notEqual(OrderMagicNumber(), g_magic_132)){
if(true)continue;}
if (equal(OrderType(), OP_BUY)){
ld_24=toDouble(Bid-OrderOpenPrice());
if ((greaterThan(MinPrfofit, 0)&&greaterThanOrEqualTo(ld_24, MinPrfofit*Point))||(greaterThan(MaxLoss, 0)&&lessThanOrEqualTo(ld_24, (-1*MaxLoss)*Point))){
OrderClose(toInt(OrderTicket()),toDouble(OrderLots()),toDouble(Bid),toInt(Slippage),toColor(Purple));
if(true)return toInt((0));}}
if (equal(OrderType(), OP_SELL)){
ld_24=toDouble(OrderOpenPrice()-Ask);
if ((greaterThan(MinPrfofit, 0)&&greaterThanOrEqualTo(ld_24, MinPrfofit*Point))||(greaterThan(MaxLoss, 0)&&lessThanOrEqualTo(ld_24, (-1*MaxLoss)*Point))){
OrderClose(toInt(OrderTicket()),toDouble(OrderLots()),toDouble(Ask),toInt(Slippage),toColor(Red));
if(true)return toInt((0));}}
if(true)return toInt((0));
}
l_ibands_44 = toDouble(iBands(toInstrument(Instrument()),toPeriod(0),toInt(BB_Period),toInt(BB_Deviation),toInt(0),toInt(PRICE_OPEN),toInt(MODE_UPPER),toInt(0)));
l_ibands_52 = toDouble(iBands(toInstrument(Instrument()),toPeriod(0),toInt(BB_Period),toInt(BB_Deviation),toInt(0),toInt(PRICE_OPEN),toInt(MODE_LOWER),toInt(0)));
if (greaterThan(Close(toInt(0)), l_ibands_44+Delta*Point)){
li_36=toBool(true);
} else {
li_36=toBool(false);
}
if (lessThan(Close(toInt(0)), l_ibands_52-Delta*Point)){
li_32=toBool(true);
} else {
li_32=toBool(false);
}
if (Bool(li_32)){
if (equal(MaxLoss, 0)){
l_price_8=toDouble(0);
} else {
l_price_8=toDouble(Ask-(MaxLoss+g_stoplevel_140)*Point);
}
if (equal(MinPrfofit, 0)){
l_price_16=toDouble(0);
} else {
l_price_16=toDouble(Ask+(MinPrfofit+g_stoplevel_140+g_spread_148)*Point);
}
OrderSend(toInstrument(Instrument()),toInt(OP_BUY),toDouble(g_lots_180),toDouble(Ask),toInt(Slippage),toDouble(l_price_8),toDouble(l_price_16),toString(Comm),toInt(g_magic_132),toInt(16711680));
}
if (Bool(li_36)){
if (equal(MaxLoss, 0)){
l_price_8=toDouble(0);
} else {
l_price_8=toDouble(Bid+(MaxLoss+g_stoplevel_140)*Point);
}
if (equal(MinPrfofit, 0)){
l_price_16=toDouble(0);
} else {
l_price_16=toDouble(Bid-(MinPrfofit+g_stoplevel_140+g_spread_148)*Point);
}
OrderSend(toInstrument(Instrument()),toInt(OP_SELL),toDouble(g_lots_180),toDouble(Bid),toInt(Slippage),toDouble(l_price_8),toDouble(l_price_16),toString(Comm),toInt(g_magic_132),toInt(255));
}
if(true)return toInt((0));return 0;
}

public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException{}
/**/};