Здравствуйте, не могли бы вы исправить код, пожалуйста? Большое спасибо
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int init()
{
return(0);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| Expert start function |
//+------------------------------------------------------------------+
int start()
{
double ema50, ema100, price, stoch;
int tickets, slippage, total_orders, martingale_multiplier;
double lot, stop_loss, take_profit, order_open_price;
bool buy_signal, sell_signal, buy_order_open, sell_order_open, martingale_enabled;
total_orders = OrderTotal();
slippage = 3;
lot = 0.01;
stop_loss = 30;
take_profit = 80;
martingale_enabled = false;
martingale_multiplier = 2;
for (int i = total_orders - 1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
{
if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber()) continue;
if (OrderType() == OP_BUY && OrderCloseTime() == 0)
{
buy_order_open = true;
order_open_price = OrderOpenPrice();
}
if (OrderType() == OP_SELL && OrderCloseTime() == 0)
{
sell_order_open = true;
order_open_price = OrderOpenPrice();
}
}
}
// Calculate EMA and Stochastic
ema50 = iMA(NULL, PERIOD_M1, 50, 0, MODE_EMA, PRICE_CLOSE, 0);
ema100 = iMA(NULL, PERIOD_M1, 100, 0, MODE_EMA, PRICE_CLOSE, 0);
price = Ask;
stoch = iStochastic(NULL, PERIOD_M1, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
// Check for buy signal
buy_signal = (ema50 > ema100) && (price < ema50) && (stoch > 20);
// Check for sell signal
sell_signal = (ema50 < ema100) && (price > ema50) && (stoch < 80);
if (buy_signal && !buy_order_open && !sell_order_open)
{
tickets = (int)MathCeil(AccountFreeMarginCheck(Symbol(), MODE_BUY, lot) / MarketInfo(Symbol(), MODE_MARGINREQUIRED) / lot);
if (martingale_enabled) {
double new_lot = NormalizeDouble(lot * MathPow(martingale_multiplier, tickets - 1), 2);
if (new_lot <= 0) {
new_lot = 0.01;
}
if (new_lot <= MarketInfo(Symbol(), MODE_MAXLOT))
{
lot = new_lot;
}
else
{
lot = MarketInfo(Symbol(), MODE_MAXLOT);
}
}