Can anyone please help me with converting the following Tradestation code to MT4:
Did you notice how this function was made up of other functions (building blocks)? We calculated the denom (denominator) by using the Highest and Lowest functions. We calculated the num (numerator) by using AbsValue (returns the absolute value of a number) functions. The only confusing snippet of code in this function is probably:
You may be asking why we subtracted 1 from the periodLength. This is a great question. If you incorporate today’s closing price into a calculation, then the closing price 30 days ago would be referenced by Close[29]. Remember that Close[1] is yesterday’s closing price not today’s. Since we want our index to flow between 0 and positive 100, we remove the negative sign of a down move in the market. We are only interested in absolute distances.
Here is what I came up with, but not sure it is coded correctly:
Thanks in advance,
TimeFreedom
Inserted Code
{Choppy Market Index Function This function returns a value from 0 to 100. A lower value denotes higher market indecisiveness (choppiness), whereas a higher value denotes a trending market. The only input is the number of bars that we look back.} Inputs: periodLength(Numeric); Vars: num(0),denom(1); if(periodLength<>0) then begin denom = Highest(High,periodLength) – Lowest(Low,periodLength); num = Close[periodLength-1] – Close; num = AbsValue(num); ChoppyMarketIndex = 0.0; if(denom<>0) then ChoppyMarketIndex = num/demon*100; end;
Inserted Code
Close[periodLength-1] – Close
Here is what I came up with, but not sure it is coded correctly:
Inserted Code
double ChoppyMarketIndex(int periodLength) { double num = 0; double denom = 0; if(periodLength != 0) { denom = High[iHighest(Symbol(),PERIOD_D1,MODE_HIGH,periodLength,0)] - Low[iLowest(Symbol(),PERIOD_D1,MODE_LOW,periodLength,0)]; num = Close[periodLength-1] - Close[1]; num = MathAbs(num); } if(denom != 0) { return(NormalizeDouble(num/denom*100,0)); } }
TimeFreedom