Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1099

 
A13ksandr:
So you start sequentially. First test on one pair all possible trades, then only run on a few. (4) - is this the number of deals?
When the EA is started, the variable is assigned 1, if there is no such variable (in your case there certainly is, as it is stored for 4 weeks). At every tick this variable allows or disallows new trades - that is its only meaning. If a trade is losing or non-profitable, AllowNewOrders=0, if not - 1. Before checking for Buy/Sell signals, this variable is checked and the loop is removed from the loop without opening an order. If 4 orders on one symbol are opened, moreover with bigger lot, CountTrades obviously does not work. I cannot check it myself, as the Internet is very very bad where I am. And by the way for me on Grand Capital options on any timeframe a new tick comes only with a new candle - is it the same for you?

Alexander, I think it's not correct to assign 1 to the global variable when launching it, because we have to wait for at least one order to open. I think we should bind the value of AllowNewOrders toOrdersTotal or CountTrades, so it would change when the first series opens. I will try to do it today, but I'm very inexperienced, so if you tell me how to state it correctly in the code, I will be very grateful to you. In my terminal the ticks come at any moment of current bar, even on M1. (4) - is the number of deals opened by the bot at once. And I have tested it the way you advise.
 
trader_fx:
https://docs.mql4.com/ru/objects/objectgetdouble
https://docs.mql4.com/ru/objects/objectgetinteger

Thank you ! I got it. Now here's a question. These functions work for getting values from objects. But how to get the values of, say, arrows,

which are visible in the graph, but are not visible in the list of objects. For example, if the arrows are drawn, for example :

SetIndexStyle(0, DRAW_ARROW);

SetIndexArrow(0, 234);

\\\\

ObjectsTotal() (and other object functions) do not see these arrows....

 
ilmel:

Thank you ! I got it. Now here's a question. These functions work for getting values from objects. But how to get the values of, let's say, arrows,

which are visible in the graph, but are not visible in the list of objects. For example, if the arrows are drawn, for example :

SetIndexStyle(0, DRAW_ARROW);

SetIndexArrow(0, 234);

\\\\

ObjectsTotal() ( and other object functions) do not see these arrows....

iCustom to the rescue

 
Hello! Does anyone know what it was on the 2nd of September?
 

Good evening, could you tell me where the error is, I took the indicator from mql4 tutorialhttps://book.mql4.com/ru/samples/icustom. But I want the envelope to be in a separate window. In the screenshot in the main window the indicator from the tutorial, in the bottom window I have

.Screenshot

#property strict
#property indicator_separate_window
#property indicator_minimum 1
#property indicator_buffers 1
#property  indicator_color1 Blue

double Buf_0[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  SetIndexBuffer(0,Buf_0);
  SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,clrAqua);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int i,                           // Индекс бара
       Counted_bars;                // Количество просчитанных баров 
    Counted_bars=IndicatorCounted(); // Количество просчитанных баров 
   i=Bars-Counted_bars-1;           // Индекс первого непосчитанного
   while(i>=0)                      // Цикл по непосчитанным барам
     {
      Buf_0[i]=Close[i];             // Значение 0 буфера на i-ом баре     
      i--;                          // Расчёт индекса следующего бара
     }
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
bobrush:

Good evening, could you tell me where the error is, I took the indicator from mql4 tutorialhttps://book.mql4.com/ru/samples/icustom. But I want the envelope to be in a separate window. You can see the indicator from the book in the main window and in the bottom window - my indicator


Why should I set the minimum?

#property indicator_minimum 1???

Why do I need to use two different colours?

But the main error is in the buffer's style, the number of parameters was a bit off.

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,0,indicator_color1);

Well, it looks like this:

#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property  indicator_color1 Blue

double Buf_0[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
  SetIndexBuffer(0,Buf_0);
  SetIndexStyle(0,DRAW_LINE,0,0,indicator_color1);
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
   int i=rates_total-prev_calculated-1;
   if(prev_calculated>0)     i++;

   while(i>=0)                      // Цикл по непосчитанным барам
     {
      Buf_0[i]=сlose[i];             // Значение 0 буфера на i-ом баре     
      i--;                          // Расчёт индекса следующего бара
     }
   return(rates_total);
  }
 
evillive:

Why set the minimum?

#property indicator_minimum 1???

Yes, and colour twice, why, and different?

But the main error is in the buffer's style, the number of parameters was a bit off.

SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,0,indicator_color1);

Well, it looks like this:

Thank you so much! About#propertyindicator_minimum1 I don't know what it's for :) , if not difficult to explain??? My programming experience is 3 EAs that have failed

 
bobrush:About#propertyindicator_minimum1 I don't know what it's for :) If it's not difficult to explain?

The lower limit of the scale of a separate indicator window, everything out of the limits is not shown in the window. Usually, the minimum-maximum is set when you need a fixed indicator scale and know that its values do not go beyond this limit.
 
evillive:

The lower limit of the individual indicator window scale, anything outside of this limit is not shown in the window. Usually the minimum-maximum is set when a fixed indicator scale is required and its values are known not to go beyond this limit.
oh, just what I was looking for, thanks)
 

Dear programmers, can you please help me set a ban on opening more than one series of deals at once (series is if the order is closed in the loss or zero and then opens the next deal on the same instrument, but with a larger lot), that is, if you open one series of deals the second and subsequent are put on other instruments under a ban (the bot simultaneously works on different instruments). I think it should be done through a global variable in terminal, but I don't have enough knowledge and experience, I just started to learnMQL. This is a binary options advisor. Here is the code

extern double Lots = 1; // Lots

extern int Exp = 1; // Expiry

extern int Wait = 1; // Number of candlesticks of one direction

extern int Timeout = 1; // Time interval

extern double Multiplier = 3; // Multiplier

extern int Slippage = 5; // Slippage

extern int Magic = 2090; // Magic


int ticket, Type;

double Price, Lot;

//+------------------------------------------------------------------+

//| Expert initialization function |

//+------------------------------------------------------------------+

int OnInit()

{

return(INIT_SUCCEEDED);

}

//+------------------------------------------------------------------+

//| Expert deinitialization function |

//+------------------------------------------------------------------+

void OnDeinit(const int reason)

{

}

//+------------------------------------------------------------------+

//| expert tick function |

//+------------------------------------------------------------------+

void OnTick()

{

// --------------- Open trades ---------------

if (OrdersTotal() == 0) // Number of orders must equal zero

{

if ((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) < PriceOpenLastHistOrder(OP_BUY))

|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) > PriceOpenLastHistOrder(OP_SELL))

// If the last trade is losing, the same one is opened, but with bigger lot

{

Type = TypeLastHistOrder();

if (Type == OP_BUY) Price = Ask;

if (Type == OP_SELL) Price = Bid;

Lot = NormalizeDouble(LotsLastHistOrder()*Multiplier, 2);

ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

if (PriceCloseLastHistOrder() == PriceOpenLastHistOrder() && CountHistTrades() > 0)

// if last trade's profit is equal to zero, the same trade will be opened

{

Type = TypeLastHistOrder();

if (Type == OP_BUY) Price = Ask;

if (Type == OP_SELL) Price = Bid;

Lot = NormalizeDouble(LotsLastHistOrder(), 2);

ticket = OrderSend(Symbol(), Type, Lot, Price, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

if (((TypeLastHistOrder() == OP_BUY && PriceCloseLastHistOrder(OP_BUY) > PriceOpenLastHistOrder(OP_BUY))

|| (TypeLastHistOrder() == OP_SELL && PriceCloseLastHistOrder(OP_SELL) < PriceOpenLastHistOrder(OP_SELL))

|| CountHistTrades() == 0)// If the last trade is profitable, the order is opened

{

if (SignalBuy() && OrdersTotal() == 0)

{

ticket = OrderSend(Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, IntegerToString(Exp), Magic);

}

if (SignalSell() && OrdersTotal() == 0)

{

ticket = OrderSend(Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, IntegerToString(Exp), Magic);

Comment ("PriceCloseLastHistOrder(OP_BUY)= ", PriceCloseLastHistOrder(OP_BUY), "PriceCloseLastHistOrder(OP_SELL)=",

PriceCloseLastHistOrder(OP_SELL) );

}

}

}

}

//+------------------------------------------------------------------+

int CountTrades(int type = -1) // Determine number of trades

{

int cnt = 0;

for (int i=OrdersTotal()-1; i>=0; i--) // The loop goes through absolutely all open orders, i is the order number

{

if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) // The function checks if the order with the order number i is in the market,

// if there is, the following conditions are checked...

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1)) // If the symbol

// the symbol at which the order is open is equal to the current symbol, the order type is equal to magic in the settings of the current EA, and

// the order type is equal to type (or type == -1 (in case it does not matter which type is required for the order count))

cnt++; // 1 is added to the cnt variable and at the end of the loop cnt will be equal to the number of deals

// opened by the current EA for the current currency pair with a certain type

}

}

return(cnt); // the value of cnt variable is returned

}

//+------------------------------------------------------------------+

int CountHistTrades(int type = -1)

{

int cnt = 0;

for (int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

cnt++;

}

}

return(cnt);

}

//+------------------------------------------------------------------+

bool SignalBuy()

{

for (int i=1; i<=Wait; i++)

{

if (Close[i] > Open[i]) return(false)

}

if ((iBarShift(Symbol(), 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))

&& CountHistTrades() > 0) return(true);

if (CountHistTrades() == 0) return(true);

return(false);

}

//+------------------------------------------------------------------+

bool SignalSell()

{

for (int i=1; i<=Wait; i++)

{

if (Close[i] < Open[i]) return(false)

}

if ((iBarShift(Symbol(), 0, TimeLastHistOrder()+Timeout) >= Wait || (Wait == 0 && TimeCurrent() >= TimeLastHistOrder()+Timeout))

&& CountHistTrades() > 0) return(true);

if (CountHistTrades() == 0) return(true);

return(false);

}

//+------------------------------------------------------------------+

datetime TimeLastHistOrder(int type = -1)

{

datetime lasttime = 0;

datetime opentime = 0;


for (int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

if (OrderCloseTime() > lasttime)

{

lasttime = OrderCloseTime();

opentime = OrderOpenTime();

}

}

}

}

return(opentime);

}

//+------------------------------------------------------------------+

int TypeLastHistOrder()

{

datetime time = 0;

int type = -1;

for (int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)

{

if (OrderCloseTime() > time)

{

time = OrderCloseTime();

type = OrderType();

}

}

}

}

return(type);

}

//+------------------------------------------------------------------+

double LotsLastHistOrder(int type = -1)

{

datetime time = 0;

double lots = 0;

for (int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

if (OrderOpenTime() > time)

{

time = OrderOpenTime();

time = OrderLots();

}

}

}

}

return(lots);

}

//+------------------------------------------------------------------+

double PriceCloseLastHistOrder(int type = -1)

{

datetime time = 0;

double price = 0;

for (int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

if (OrderCloseTime() > time)

{

time = OrderCloseTime();

price = OrderClosePrice();

}

}

}

}

}

}

//+------------------------------------------------------------------+

double PriceOpenLastHistOrder(int type = -1)

{

datetime time = 0;

double price = 0;

for (int i=OrdersHistoryTotal()-1; i>=0; i--)

{

if (OrderSelect(i, SELECT_BY_POS, MODE_HISTORY))

{

if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && (OrderType() == type || type == -1))

{

if (OrderCloseTime() > time)

{

time = OrderCloseTime();

price = OrderOpenPrice();

}

}

}

}

}

}

//+------------------------------------------------------------------+

Reason: