Questions from Beginners MQL5 MT5 MetaTrader 5 - page 271

 
soroko:
so only the first value is filled in with the index [0].
//+------------------------------------------------------------------+
//|                                                         test.mq5 |
//|                              Copyright © 2014, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2014, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"

double Pr[5];                 // обявление 5-мерного статического массива
double PriceOld;              // переменная для сравнения цены
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
int OnInit()
  {
//---

//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---

  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   double temp_prace=SymbolInfoDouble(_Symbol,SYMBOL_BID);
   if(NormalizeDouble(PriceOld-temp_prace,5)!=0)
     {
      Pr[4]=Pr[3];
      Pr[3]=Pr[2];
      Pr[2]=Pr[1];
      Pr[1]=Pr[0];
      Pr[0]=temp_prace;
      PriceOld=Pr[0];
     }
  }
//+------------------------------------------------------------------+
 
soroko:

thank you. saved me a sleepless weekend).

vicmos thank you.
 
barabashkakvn:
vicmos thank you.
it fills everything with one value, like the ArrayFill(...)/ function
 
soroko:
it fills everything with one value, like the ArrayFill(...)/ function
sorry there is just a smaller number of digits! thank you very much!
 

Good day to all! Such a problem - the compiler gives a warning. I don't want to ignore it, can you help me find a way out?

   double aHigh[ 12 ], aLow[ 12 ];
   double dVolatility = 0.0;
   
   CopyHigh(sSymbol, PERIOD_MN1, 0, 12, aHigh);
   CopyLow(sSymbol, PERIOD_MN1, 0, 12, aLow);
   
   dVolatility = ArrayMaximum(aHigh) - ArrayMinimum(aLow);
   dVolatility = NormalizeDouble(dVolatility, SymbolInfoInteger(sSymbol, SYMBOL_DIGITS));

It is cursing specifically at the last line, says:"possible loss of data due to type conversion". How to correctly normalize the real type in this case?

 
jommerbot:

Good day to all! Such a problem - the compiler gives a warning. I don't want to ignore it, can you help me find a way out?

It is cursing specifically at the last line, says:"possible loss of data due to type conversion". How to correctly normalize the real type in this case?

   dVolatility = NormalizeDouble(dVolatility, (int)SymbolInfoInteger(sSymbol, SYMBOL_DIGITS));
 
barabashkakvn:
Thank you
 
jommerbot:

Good day all! Such a problem - the compiler gives a warning. I don't want to ignore it, can you help me find a way out?

It is cursing specifically at the last line, says:"possible loss of data due to type conversion". How to correctly normalize the real type in this case?

And one more thing: ArrayMaximum and ArrayMinimum returns the index of the element found. So the correct way is this:

   dVolatility = aHigh[ArrayMaximum(aHigh)] - aLow[ArrayMinimum(aLow)];
 
MigVRN:

Also: ArrayMaximum and ArrayMinimum return the index of the element found. So the correct way is like this:

Thank you very much. Discovered the same thing when debugging the code.
 

It does not correctly calculate the take profit level based on the amount of losses of the closed orders. It turns out the 1st order = 1; 2nd order = 2; 3rd order = 3; 4th order = 4. We need to calculate the number of pips to cover the loss on all previous orders and gain 10% of the total loss.

Actually, the Expert Advisor just considers the amount of each closed order to be equal to the supposedly pending order, i.e. its calculations show that if the pending 5th order equals 5 lots, all previous losing orders were equal to 5 lots and, therefore, the loss is calculated with the corresponding wrong profit level. In other words, if the total volume of 4 orders equals 10 lots, then the Expert Advisor will simply multiply 4 orders by the volume of the 5th pending order and obtain a total volume of 20 lots......What should we correct in the code?

// Function which calculates Take Level based on Loss Level of closed trades

//=================================================================================================

double TakeProfitCalculate(double lot,int type)

{

int n,i;

double prf,ttp;


prf=MathAbs(BuyLevel-SellLevel)/Point*LOT*MarketInfo(Symbol(),MODE_TICKVALUE);//

if(No!=0) for(i=OrdersHistoryTotal()-1;i>=0;i--)

{

if(!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;

if(OrderSymbol()!=Symbol() || OrderMagicNumber()<MAGIC || OrderMagicNumber()>MAGIC+200 || OrderType()>OP_SELL) continue;

n=OrderMagicNumber()-MAGIC;

prf+=(OrderProfit()+OrderSwap()+OrderCommission());

if(n==0) break;

}

prf=MathAbs(prf*(100+ProfitPercent)/100);

ttp=prf*Point/(LOT*MarketInfo(Symbol(),MODE_TICKVALUE))

if(type==OP_BUY) return(NRu(BuyLevel+ttp)); else return(NRd(SellLevel-ttp))

}

Reason: