У вас функции GetMaxPrice() и GetMinPrice() типа void, а надо double, чтобы они возвращали значение цены. И когда хотите открыть ордер, вызовите эту функцию.
например:
Сергей огромное спасибо. Очень помогло.
Есть еще вопрос.
В том же коде учитель пишет ограничение по выставлению ордеров командой int count - как я понял. Но как написать так чтобы советник выставлял только один отложенный ордер на каждую вершину которую он определил?
После внесения коррективов по вашему совету код выглядит вот так:
extern int BarCount = 10;
extern int HourStart = 11;
extern double Lots = 0.01;
extern int StopLoss = 300;
extern int TakeProfit = 200;
extern int Magic = 12345;
double SL, TP, MaxPrice, MinPrice;
int ticket;
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
if(TimeHour(TimeCurrent()) == HourStart)
{
if (BuyLimitCount() == 0 && BuyCount() == 0)
{
double price_open = GetMinPrice();
SL = NormalizeDouble(price_open- StopLoss*Point, 5);
TP = NormalizeDouble(price_open + TakeProfit*Point, 5);
ticket = OrderSend(Symbol(), OP_BUYLIMIT, Lots, price_open, 3, SL, TP, "", Magic, 0, Blue);
if(ticket Print("Не удалось открыть ордер");
}
if (SellLimitCount() == 0 && SellCount() == 0)
{
double price_open = GetMaxPrice();
SL = NormalizeDouble(price_open + StopLoss*Point, 5);
TP = NormalizeDouble(price_open - TakeProfit*Point, 5);
ticket = OrderSend(Symbol(), OP_SELLLIMIT, Lots, price_open, 3, SL, TP, "", Magic, 0, Red);
if(ticket Print("Не удалось открыть ордер");
}
}
Comment("Maxprice:" +DoubleToStr(GetMaxPrice(), 5) + "\n"+
"Minprice:" +DoubleToStr(GetMinPrice(), 5));
}
//+------------------------------------------------------------------+
int BuyLimitCount()
{
int count = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true &&
OrderMagicNumber() == Magic &&
OrderType() == OP_BUYLIMIT)
{
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
int SellLimitCount()
{
int count = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true &&
OrderMagicNumber() == Magic &&
OrderType() == OP_SELLLIMIT)
{
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
int BuyCount()
{
int count = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true &&
OrderMagicNumber() == Magic &&
OrderType() == OP_BUY)
{
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
int SellCount()
{
int count = 0;
for(int i=OrdersTotal()-1; i>=0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == true &&
OrderMagicNumber() == Magic &&
OrderType() == OP_SELL)
{
count++;
}
}
return(count);
}
//+------------------------------------------------------------------+
double GetMinPrice() // Функция для определения максимальной цены за n баров
{
double minprice = -99999;
for (int i=BarCount-1; i>=0; i--)
{
double mp = iLow(Symbol(), PERIOD_CURRENT, i);
if(mp > minprice)
minprice = mp;
MinPrice = minprice;
}
return(MinPrice); //что вернет функция
}
//+------------------------------------------------------------------+
double GetMaxPrice() // Функция для определения максимальной цены за n баров
{
double maxprice = -99999;
for (int i=BarCount-1; i>=0; i--)
{
double mp = iHigh(Symbol(), PERIOD_CURRENT, i);
if(mp > maxprice)
maxprice = mp;
MaxPrice = maxprice;
}
return(MaxPrice); //что вернет функция
