Any rookie question, so as not to clutter up the forum. Professionals, don't pass by. Nowhere without you - 6. - page 1099
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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?
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....
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
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
.
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:
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
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.
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.
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();
}
}
}
}
}
}
//+------------------------------------------------------------------+