jma

Download JMA

If you can't read please download the document

Upload: gaurigan

Post on 16-Aug-2015

221 views

Category:

Documents


4 download

DESCRIPTION

jma

TRANSCRIPT

#define STRICT#include #include #include #include #pragma hdrstopdouble DateBegin;bool DateBeginSaved;int IntPortion (double);/*====================================================================================================================================*/#pragma argsusedextern "C" double _stdcall __declspec(dllexport)JMA (double Empty, double CurClose, int Period, int Phase, double* Date){static double PrevJMAValueBuffer;static double Cur_fC0Buffer; static double Prev_fC0Buffer;static double Cur_fA8Buffer;static double Prev_fA8Buffer;static double Cur_fC8Buffer;static double Prev_fC8Buffer;static double list[128];static double ring1[128];static double ring2[11];static double buffer[62];static int limitValue;static int startValue;static int loopParam; static int loopCriteria;static int cycleLimit;static int highLimit;static int counterA;static int counterB;static int s58; static int s60;static int s40; static int s38;static int s68;static double cycleDelta; static double lowDValue;static double highDValue; static double absValue;static double paramA; static double paramB;static double phaseParam; static double logParam;static double JMAValue; static double series;static double sValue; static double sqrtParam;static double lengthDivider;static double NoEvalValue;static bool MoreThanThirtyFlag;int i;int j;int intPart;int leftInt;int rightPart;int upShift;int dnShift;double sqrtDivider;double dValue;double powerValue;double squareValue;double JMATempValue;double lengthParam;static int Counter;if (DateBeginSaved == false){ DateBegin = *Date;DateBeginSaved = true; }if (*Date == DateBegin) {PrevJMAValueBuffer = 0;Cur_fC0Buffer = 0;Prev_fC0Buffer = 0;Cur_fA8Buffer = 0;Prev_fA8Buffer = 0;Cur_fC8Buffer = 0;Prev_fC8Buffer = 0;limitValue = 0; startValue = 0;loopParam = 0;loopCriteria = 0;cycleLimit = 0; highLimit = 0;counterA = 0; counterB = 0;s58 = 0; s60 = 0; s40 = 0; s38 = 0; s68 = 0;cycleDelta = 0; lowDValue = 0;highDValue = 0; absValue = 0;paramA = 0; paramB = 0;phaseParam = 0; logParam = 0;JMAValue = 0; series = 0;sValue = 0; sqrtParam = 0;lengthDivider = 0;NoEvalValue = 0;MoreThanThirtyFlag = true;limitValue = 63;startValue = 64;phaseParam = Phase/100.0 + 1.5;if (Phase < -100)phaseParam = 0.5;if (Phase > 100)phaseParam = 2.5;for (i=0; i= highDValue){ if (list[s60-1] list[127]))s60 = 128;}if (cycleLimit > 127) {if (s58 >= s60) {if (((s38 + 1) > s60) && ((s40 - 1) < s60))lowDValue += highDValue; else { if ((s40 > s60) && ((s40 - 1) < s58))lowDValue += list[s40-1]; } } else{ if (s40 >= s60){ if (((s38 + 1) < s60) && ((s38 + 1) > s58))lowDValue += list[s38+1]; } else{ if ((s38 + 2) > s60)lowDValue += highDValue; else { if (((s38 + 1) < s60) && ((s38 + 1) > s58))lowDValue += list[s38+1]; } } }if (s58 > s60) {if (((s40 - 1) < s58) && ((s38 + 1) > s58))lowDValue -= list[s58]; else{ if ((s38 < s58) && ((s38 + 1) > s60))lowDValue -= list[s38]; } }else{if (((s38 + 1) > s58) && ((s40 - 1) < s58))lowDValue -= list[s58];else{ if ((s40 > s58) && (s40 < s60))lowDValue -= list[s40]; } } }if (s58 = s60) list[s60] = highDValue; else{for (j=s58+1; j=s60; j--) { list[j+1] = list[j]; } list[s60] = highDValue; }if (cycleLimit = 1)intPart = ceil(sqrtParam);elseintPart = 1;leftInt = IntPortion (intPart);if (floor(sqrtParam) >= 1)intPart = floor(sqrtParam);elseintPart = 1;rightPart = IntPortion (intPart);if (leftInt == rightPart)dValue = 1.0;else{ dValue = (sqrtParam - rightPart) / (leftInt - rightPart); }if (rightPart = pow(absValue/dValue, powerValue))dValue = pow((absValue/dValue),powerValue);elsedValue = logParam;if (dValue < 1)dValue = 1;powerValue = pow(sqrtDivider,sqrt(dValue));if ((sValue - paramA) > 0)paramA = sValue;else{ paramA = sValue - ((sValue - paramA) * powerValue); }if ((sValue - paramB) < 0)paramB = sValue;elseparamB = sValue - ((sValue - paramB) * powerValue);}}////////////////////////////////////////////////////////////////////////////////////if (loopCriteria > 30) {JMATempValue = PrevJMAValueBuffer; powerValue = pow(lengthDivider,dValue); squareValue = pow(powerValue,2); Cur_fC0Buffer = ((1 - powerValue) * series) + (powerValue * Prev_fC0Buffer); Cur_fC8Buffer = ((series - Cur_fC0Buffer) * (1 - lengthDivider)) + (lengthDivider * Prev_fC8Buffer); Cur_fA8Buffer = (phaseParam * Cur_fC8Buffer + Cur_fC0Buffer - JMATempValue) *(powerValue * (-2.0) + squareValue + 1) + (squareValue * Prev_fA8Buffer); JMATempValue += Cur_fA8Buffer;}JMAValue = JMATempValue;PrevJMAValueBuffer = JMAValue;Prev_fC0Buffer = Cur_fC0Buffer;Prev_fC8Buffer = Cur_fC8Buffer;Prev_fA8Buffer = Cur_fA8Buffer;return JMAValue;}if (Counter 0)Result = floor (param);if (param < 0)Result = ceil (param);return ((int)Result);}/*====================================================================================================================================*/#pragma argsusedint _matherr (exception* E){if (lstrcmp((E->name),"log") == 0) {if ((E->type) == UNDERFLOW)(E->retval) = DBL_MIN;if ((E->type) == SING) (E->retval) = DBL_MIN;return 1;}if (lstrcmp((E->name),"exp") == 0) {if ((E->type) == OVERFLOW) (E->retval) = DBL_MAX;if ((E->type) == UNDERFLOW)(E->retval) = DBL_MIN;return 1;}if (lstrcmp((E->name),"pow") == 0) {if ((E->type) == OVERFLOW) (E->retval) = DBL_MAX;if ((E->type) == UNDERFLOW)(E->retval) = DBL_MIN;return 1;}if (lstrcmp((E->name),"sqrt") == 0) {if ((E->type) == OVERFLOW) (E->retval) = DBL_MAX;if ((E->type) == UNDERFLOW)(E->retval) = DBL_MIN;if ((E->type) == DOMAIN) (E->retval) = sqrt (-(E->arg1));return 1;}return 0;}/*=====================================================================================================================================*/