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

 

Dear forum users!

Please help, problems are as follows: 1) How to prescribe in the code, so that the deal, say, on SELL, opened when the upper boundary of the channel, and closed when it reaches the bottom; 2) When one signal should open only one deal; 3) when installing the EA, the deal opens immediately, but you want the deal is opened only when the channel line is reached.

I would be very grateful for your help.

extern double Lots = 0.1;
extern int TakeProfit = 30; // TakeProfit (a negative number or zero to avoid using);
extern int StopLoss = 20; // Stop Loss level for buying;
extern inttern Slippage = 2; // slippage
extern string Comment = "Keller";
extern inttern Magic = 333;

extern string Indi = "Indicator data";
extern string TimeFrame = "current time frame;
extern int int MA_Period = 10; // 0 - SMA, 1 - EMA, 2 - SMMA, 3 - LWMA
extern int Mode_MA = 0; // 0 - Close, 1 - Open, 2 - High, 3 - Low, 4 - Median, 5 - Typical, 6 - Weighted
extern int Price_Type = 5;

double PriceHigh, PriceLow, SL, TP;
int ticket;
//+------------------------------------------------------------------+
//| expert initialization function |
//+------------------------------------------------------------------+
int init()
{
if (Digits ==3 || Digits ==3) // for a five-digit broker
{
TakeProfit *= 10;
StopLoss *= 10;
Slippage *= 10;
}
return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function |
//+------------------------------------------------------------------+
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
PriceHigh = iCustom (Symbol(), 0, "Keller", TimeFrame, MA_Period, Mode_MA, Price_Type, 0, 0); // red top buffer 0
PriceLow = iCustom (Symbol(), 0, "Tma", TimeFrame, MA_Period, Mode_MA, Price_Type, 2, 0); // red bottom buffer 2

if (Bid >= PriceHigh && CountSell() == 0) // where Countsell check that orders are opened one by one and not on every tick
{
SL = NormalizeDouble (Bid + StopLoss * Point, Digits);
TP = NormalizeDouble (Bid - TakeProfit * Point, Digits);

ticket = OrderSend (Symbol(), OP_SELL, Lots, Bid, Slippage, 0, 0, Comment, Magic, 0, Red); // where 0 is SL and TP (this is 0 for ßn accounts) and the last 0 is an action
if (ticket > 0) // check for an open order
{
if (OrderSelect (ticket, SELECT_BY_TICKET, MODE_TRADES) == true)
OrderModify (ticket, OrderOpenPrice(), SL, TP, 0); // where 0 is an expression
}
}


if (Ask <= PriceLow && CountBuy() == 0)// where Countsell checks that orders are opened one by one, not on every tick
{
SL = NormalizeDouble (Ask - StopLoss * Point, Digits);
TP = NormalizeDouble (Ask + TakeProfit * Point, Digits);

ticket = OrderSend (Symbol(), OP_BUY, Lots, Ask, Slippage, 0, 0, Comment, Magic, 0, Blue); // where 0 is SL and TP (this is 0 for ßn accounts), and the last 0 is an action
if (ticket > 0) // check for an open order
{
if (OrderSelect (ticket, SELECT_BY_TICKET, MODE_TRADES) == true)
OrderModify (ticket, OrderOpenPrice(), SL, TP, 0); // where 0 is an expression
}
}


if (Bid >= PriceHigh && CountBuy() > 0) // if price has reached the upper limit of the channel and the number of orders is greater than 0
{
for (int i=OrdersTotal()-1; i >= 0; i--)
{
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)== true)
{
if (OrderMagicNumber() == Magic && OrderType() == OP_BUY) // check if this is our buy order
OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Black); // close the order at the upper border of the channel
}
}
}
if (Ask <= PriceLow && CountSell() > 0) // if the price has reached the lower limit of the channel and the number of orders is greater than 0
{
for ( i=OrdersTotal()-1; i >= 0; i--) // no variable definition for buy
{
if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)== true)
{
if(OrderMagicNumber() == Magic && OrderType() == OP_SELL) // check if this is our sell order
OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Black); // close the order at the lower border of the channel
}
}
}

return(0);
}

//+------------------------------------------------------------------+
int CountSell()// check - number of Sell orders in progress
{
int Count = 0;
for (int trade = OrdersTotal() - 1; trade >=0; trade --)
{
OrderSelect (trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
if (OrderType() == OP_SELL)
Count++;
}
}
return(Count);
}
//+------------------------------------------------------------------+
int CountBuy()// check - number of buy orders that are in work
{
int Count = 0;
for (int trade = OrdersTotal() - 1; trade >=0; trade --)
{
OrderSelect (trade, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic)
{
if (OrderType() == OP_BUY)
Count++;
}
}
return(Count);
}

 
Adding a screenshot
 
artmedia70:

No, they didn't. I glanced at your code and answered "without looking". Your line:

- assigns to the cycle index i a value equal to the total number of horizontal lines. If you have 3 of them, the cycle will be from 2 to 0. It is unclear what is in your cycle, but there will be only three iterations from 2 to 0.


Yeah, well... And that's exactly what I was worried about. The thing is, without specially set experiments, but just by observation, it did work in the presence of other objects.

for(int i=ObjectsTotal(OBJ_HLINE)-1; i>=0; i--) 

And at a glance it worked correctly. But there were doubts about the very thing you described. That is why I wanted to clarify this aspect.

And I am glad that your opinions confirmed my assumption. We may consider that certainty on the matter is achieved.

Thank you very much once again!

 
bistreevseh:


I have a custom indicator, it is a histogram, all values are maximal, it only matters the colour of bars in the histogram, it has no input parameters, buffers 2 : 0 - with red bar, and 1 - blue bar, I found out by imperial method, that in 0 buffer, does not change value, and in 1 changes. How to write the criteria for the transaction I can't understand, please explain how, thanks in advance.


If you have the source code of the indicator, it is not difficult: you look at the source code and find the conditions for colour change in the indicator. Using them, we form a signal. There are 2 ways to do it, the first one is writing a "wrapper" for analyzing conditions of buffer values changing, at that the indicator code is not changed, iCustom() is used, the second one converts the indicator code into a function that can be called from the Expert Advisor. Both methods are described in the articles on the website.

If you are interested, for example, in the smoothed Heikin-Ashi indicator, look through the website - for this indicator there was a discussion, as far as I remember, both the correctness of the algorithm and the signal analysis were discussed. The code of its open and is available in the code base (there are plenty of them there).

If the indicator is a unique one and has no source code, the matter is much more complicated: reverse engineering, which, by the way, does not always justify the effort.

 
VladislavVG:

If you have the source code of the indicator, it's not difficult: Look at the source code and find the conditions for colour change in the indicator. Using them we form a signal. There are 2 ways to do it: the first one - by writing a "wrapper" for the analysis of conditions of buffer values changing, the indicator code is not changed, iCustom() is used, the second one - by converting the indicator code into the function that can be called from the Expert Advisor. Both methods are described in the articles on the website.

If you are interested, for example, in the smoothed Heikin-Ashi indicator, look through the website - for this indicator there was a discussion, as far as I remember, both the correctness of the algorithm and the signal analysis were discussed. The code of its open and is available in the code base (there are plenty of them there).

If the indicator is a unique one and has no source code, the matter is much more complicated: reverse engineering, which, by the way, does not always justify the effort.


thank you very much, I'll give it a try. Could you help me with finding articles on "wrapping" and converting indicator code, as I'm afraid I can't interpret this into a search query.
 
Help, please. The indicator draws the previous day's high and low lines. I need it to draw lines on history every day. Thank you.
Files:
line.mq4  3 kb
 
prom18:
Help, please. The indicator draws the previous day's high and low lines. I need it to draw lines on history every day. Thank you.
Files:
line_1.mq4  3 kb
 
bistreevseh:

Thank you very much, I'll give it a try. Could you help me with finding articles on "wrapper" and transforming indicator code, as I'm afraid I can't interpret this into a search query.


https://www.mql5.com/ru/forum/114117 here is an example of creating a wrapper function to interpret indicator signals

here are articles on the use of indicator codes:

https://www.mql5.com/ru/articles/1456

https://www.mql5.com/ru/articles/1457

 
Vinin:



Thank you!
 
VladislavVG:


https://www.mql5.com/ru/forum/114117 here is an example of creating a wrapper function to interpret indicator signals

here are articles on the use of indicator codes:

https://www.mql5.com/ru/articles/1456

https://www.mql5.com/ru/articles/1457


Once again, thank you very much.
Reason: