English

## Median in timeseries array

 705 1005phillip 2010.06.11 18:08 #   double mean = (Integer+Integer)/2 = (Integer+Integer)/Integer = double Incorrect, the variable "mean" will be a double but the value it will be holding as computed by the integer/integer will be an integer value. https://docs.mql4.com/basis/types/casting Examples: ```int i = 1 / 2; // no types casting, the result is 0 int i = 1 / 2.0; // the expression is cast to the double type, then is to the target type of int, the result is 0 double d = 1.0 / 2.0; // no types casting, the result is 0.5 double d = 1 / 2.0; // the expression is cast to the double type that is the same as the target type, the result is 0.5 <- I want you to ensure this happens double d = 1 / 2; // the expression of the int type is cast to the target type of double, the result is 0.0 <- this one applies to you in your current calculation method string s = 1.0 / 8; // the expression is cast to the double type, then is to the target type of string, the result is "0.12500000" (the string containing 10 characters) string s = NULL; // the constant of type int is cast to the target type of string, the result is "0" (the string containing 1 character) string s = "Ticket #"+12345; // the expression is cast to the string type that is the same as the target type, the result is "Ticket #12345" ``` similar
 539 Viffer 2010.06.11 18:21 #   `double d = 1 / 2; // the expression of the int type is cast to the target type of double, the result is 0.0 ` Well I honestly didn't know that. thanks for pointing it out. I can see it now though int/int=int then cast to a double so 1/2=0 then cast to 0.0... all makes sense. I think I ought to have another look through all my other code! Thanks again V [I've updated the function code in case anyone is using it] similar
 1 sapogov 2014.05.06 10:40 #   Hello I use Time Series to create new order with SL and TP based on median bar size from, may be it could help: ```input double SL_Mult, // StopLoss Multiplier              TP_Mult; // TakeProfit Multiplier double ArrHigh[], ArrLow[], M_Point1, M_Point2, M_High, M_Low, MedianBarSize, MinStopLevel, SL, TP; string symb=Symbol(); int TimeFrame=Period();   {    BarsCount = iBars(symb, Timeframe);    CopyHigh(symb,TimeFrame,0,BarsCount,ArrHigh); // copy Time Series    CopyLow(symb,TimeFrame,0,BarsCount,ArrLow);       ArraySort(ArrHigh,WHOLE_ARRAY,0,MODE_ASCEND); //Sort Ascending    ArraySort(ArrLow,WHOLE_ARRAY,0,MODE_ASCEND);       M_Point1 = MathFloor(BarsCount /2);    // First half end point    M_Point2 = MathCeil((BarsCount /2)+1); // Second half start point    M_High = (ArrHigh[M_Point1]+ArrHigh[M_Point2])/2; // Median High    M_Low = (ArrLow[M_Point1]+ArrLow[M_Point2])/2; // Median Low    MedianBarSize = NormalizeDouble((M_High-M_Low),Digits); // Median Bar Size                     MinStopLevel = MarketInfo(symb,MODE_STOPLEVEL);                           SL=NormalizeDouble(OpeningPrice_Bid+MinStopLevel+(MedianBarSize*SL_Mult),Digits);  // SL based on Median Bar Size    TP=NormalizeDouble(OpeningPrice_Ask-MinStopLevel-(MedianBarSize*TP_Mult),Digits);  // TP based on Median Bar Size      if (SL<=MinStopLevel) SL=MinStopLevel;    if (TP<=MinStopLevel) TP=MinStopLevel; }```