Any questions from newcomers on MQL4 and MQL5, help and discussion on algorithms and codes - page 53

 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 blue
//--------------------------------------------------------------------
double Buffer[];
//--------------------------------------------------------------------
int init()
{
SetIndexStyle(0,DRAW_HISTOGRAM, EMPTY,2);
SetIndexBuffer(0,Buffer;)
return(0);
}
// -------------------------------------------------------------------
int deinit()
{
return(0);
}
//--------------------------------------------------------------------
int start()
{
int StartBar = Bars - IndicatorCounted() - 1;
for(int i = StartBar; i >= 0; i--)
Buffer[i] =(iClose("EURGBP",0,i)-iOpen("EURGBP",0,i))/MarketInfo("EURGBP",MODE_POINT)+
(iClose("EURAUD",0,i)-iOpen("EURAUD",0,i))/MarketInfo("EURAUD",MODE_POINT);
return(0);
}

//---------------------------------------------------------------------

Sorry I don't know how to format the text with code .

This is a simple counter indicator ( sum of instrument bodies in pips on current timeframe ) instruments any . Each bar of the histogram begins with "O" and ends at the close of the timeframe . For example the current timeframe is H1, at 12.00 it shows "0" and at 13.00 "+20" and the bar graph reads clearly = +20. But during this hour the readings were -50 and +60, but the indicator does not show them, it is necessary to add one buffer for minimum Buffer[i] and one for maximum Buffer[i]. We cannot use High and Low because these values come at different times for each symbol written in the indicator. I want the second buffer to fix the maximal value of Buffer[i] of the smaller chart (M5) on the current chart (H1), and the third buffer fixes the minimal value of Buffer[i] of the smaller chart (M5) on the current chart (H1). Dear, who can advise what?

 
vitek2010:

I'm sorry, I don't know how to code the text.

We cannot use High and Low because these values come at different times for every instrument specified in the indicator.

And Close for each instrument occurs at the same time, during the candle's life? So it's a wrong opinion, the ticks all come at different times)))

 
trader781:
The point is that there will ALWAYS be losing orders with some lot which will also have to be covered by the rest of the orders. The trigger is the closing time. If we close even one, the whole chain will be lost. Therefore, the question is how to trawl the average price of all selected ones.

So we have to go through all the "necessary" orders in the loop and calculate this average price. Then, when the current price deviates from the calculated average price in the required direction, we should charge the loop again with modification of all orders.

If we don't want to read the average price on every tick, we may read it only when adding another order.

 
Alexey Viktorov:

So we have to go through all the "necessary" orders in the loop and calculate this average price. Then, when the current price deviates from the calculated average price in the required direction, we should charge the loop again with modification of all orders.

If we don't want to read the average price on every tick, it can be read only when another order is added.

If you don't mind, just explain how to calculate the average price when the order grid is distributed unevenly (where OrderType()<2). That's all.
 
Vitalie Postolache:

And Close for each instrument comes at the same time, during the life of the candle? I'm not talking about ticks, I'm talking about fixing the minimum and maximum readings of the indicator buffer.)

I'm not talking about ticks I was saying that we should fix the minimum and maximum readings of the indicator buffer calculated on a smaller timeframe, in the gap of a larger timeframe I will try to show it on the screenshot In this case the smallest timeframe is H1 (but this is the window of different timeframes):

[img]https://charts.mql5.com/13/642/eurgbp-w1-instaforex-group.png[/img]

I will consider the week 05.12 (red crosshair) this bar graph by the indicator shown above clearly shows that the total pair movement at the end of the week was descending by 95 points, but it does not show how many points were descending or ascending during the week.

And here on this screen you can see the dynamics of this indicator on the H1 chart during this week:

[img]https://charts.mql5.com/13/642/eurgbp-h1-instaforex-group.png[/img]

Indicator had minimal value 400 and then went up to 700 and closed on 160 (the difference of numbers on two screens is not important)

i need all these values in one indicator in one bar of the histogram and the minimum, maximum and close (in this case on the wickle). ideally on the current timeframe from the one you specify in the settings of the timeframe

i did it with mt4 insta copying from mcl5 website

 
trader781:
If it's not difficult, just explain how I can calculate the average price when the order grid is unevenly distributed(where OrderType()<2). That's all.

I hope you can figure it out.

for(int i=0; i<OrdersTotal(); i++) {
  if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
   if(OrderSymbol()==_Symbol && OrderMagicNumber()==Magic) {
    if(OrderType()==OP_BUY) {
      _BuyProfit+=OrderProfit()+OrderSwap()+OrderCommission(); // совокупный профит  по всем Sell
      _BuyLot+=OrderLots(); //совокупный лот по всем Sell
    }
    if(OrderType()==OP_SELL) {
      _SellProfit+=OrderProfit()+OrderSwap()+OrderCommission(); // совокупный профит  по всем Sell
      _SellLot+=OrderLots(); //совокупный лот по всем Sell
    }
}}}

double TickValue= MarketInfo(_Symbol,MODE_TICKVALUE);

if(_BuyLot  > 0) { BuyAwerage = NormalizeDouble(Bid-(_BuyProfit/(TickValue*_BuyLot))*_Point,_Digits); } else { BuyAwerage=0; }// безубыток buy
if(_SellLot > 0) { SellAwerage= NormalizeDouble(Ask+(_SellProfit/(TickValue*_SellLot))*_Point,_Digits); } else { SellAwerage=0; } // безубыток sell
if(_BuyLot-_SellLot! = 0) { AllAwerage= NormalizeDouble(((_BuyLot>_SellLot)?Bid:Ask)-((_BuyProfit+_SellProfit)/(TickValue*(_BuyLot-_SellLot))*_Point),_Digits); } else { AllAwerage=0; } // общий безубыток
 
Vitaly Muzichenko:

Hope you get the hang of it.



double TickValue= MarketInfo(_Symbol,MODE_TICKVALUE);


Can we talk a little bit about this one? I don't understand the point of this code.
 
trader781:
Can we talk a little about this?

The amount of the minimum change in the price of an instrument in the currency of the deposit

The pip value is different for each instrument and does not equal "1" like e.g. EUR/USD.

 
Vitaly Muzichenko:

The amount of the minimum change in the price of an instrument in the currency of the deposit

The pip value is different for each instrument and does not equal "1" like e.g. EUR/USD.

Yep, now I see

it turns out that you can also set a floating stop for example (eqi=balance*1.1) or (eqi=balance*0.9)

are there such tools?

 
trader781:

Yep, got it now.

but it turns out that you can also set floating stop for example (eqi=balance*1.1) or (eqi=balance*0.9)

are there such tools?

You already have a specific price from which you only need to trawl using the analog of a simple trawl, but a simple trawl is based on the opening price of the position = OrderOpenPrice() , while here it is based on the average calculated price and modifies all positions by one level
Reason: