I've searched through the internet for an indicator that works in MT4 for this but they all don't seem to work, so I'm making my own.
I'm basically trying to get the Commitment Of Traders (COT) (from the CFTC) data in an index along the bottom on the chart using the following formula (as defined by Larry Williams)
net commercial position (net coms) = commercial longs - commercial shorts
max net coms = maximum of net commercial position over 156 weeks
min net coms = minimum of net commercial position over 156 weeks
The same calculation is applied to noncommercial traders and nonreporting traders.
Should end up looking a bit like this chart (make sure COT Index is selected!)
http://timingcharts.com/charts
Now I'm not a good coder by any standard, so I search for a bit and found this article.
( http://moneyunleashed.com/articles/i...-metatrader-4/).
I decided I'd try to take out the interest rate data and replace it with COT data, and then have the script make the COT index for me. The result of my efforts is the code below. Hopefully it makes some degree of sense but if not, please tell me.
Everything looks fine so I'm not sure why it won't compile.
If someone could tell me why its not compiling/how to fix it I'd very much appreciate it. I think many others would too because I've seen quite a few threads when I was searching.
If my explanation is unclear please let me know and I'll try to re-explain.
To this post I've also attached the COT data which are in the correct format. (They will need to go in expert->files)
I'm basically trying to get the Commitment Of Traders (COT) (from the CFTC) data in an index along the bottom on the chart using the following formula (as defined by Larry Williams)
net commercial position (net coms) = commercial longs - commercial shorts
max net coms = maximum of net commercial position over 156 weeks
min net coms = minimum of net commercial position over 156 weeks
QuoteDislikedCOT formula (commercials)
(net coms - min net coms) / (max net coms - min net coms)
The same calculation is applied to noncommercial traders and nonreporting traders.
Should end up looking a bit like this chart (make sure COT Index is selected!)
http://timingcharts.com/charts
Now I'm not a good coder by any standard, so I search for a bit and found this article.
( http://moneyunleashed.com/articles/i...-metatrader-4/).
I decided I'd try to take out the interest rate data and replace it with COT data, and then have the script make the COT index for me. The result of my efforts is the code below. Hopefully it makes some degree of sense but if not, please tell me.
Everything looks fine so I'm not sure why it won't compile.
Inserted Code
//+------------------------------------------------------------------+ //| COMDEX.mq4 | //| Copyright © 2009, Fibollinger | //| [url="http://moneyunleashed.com/"]http://moneyunleashed.com[/url] | //+------------------------------------------------------------------+ #property copyright "Copyright © 2009, Fibollinger" #property link "[url="http://moneyunleashed.com/"]http://moneyunleashed.com[/url]" #property indicator_separate_window #property indicator_buffers 3 #property indicator_color1 Green #property indicator_color2 Red #property indicator_color3 Blue #property indicator_width3 1 //---- input parameters extern string FileExtention = "txt"; extern int Delimiter = 9; //---- buffers double ExtMapBuffer1[]; double ExtMapBuffer2[]; double ExtMapBuffer3[]; datetime ComDate[]; double ComRate[]; double MaxComRate[]; double MinComRate[]; datetime NoncomDate[]; double NoncomRate[]; double MaxNoncomRate[]; double MinNoncomRate[]; datetime NonrepDate[]; double NonrepRate[]; double MaxNonrepRate[]; double MinNonrepRate[]; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- indicators SetIndexStyle(0, DRAW_LINE, 0, 1, Green); SetIndexBuffer(0, ExtMapBuffer1); SetIndexStyle(1, DRAW_LINE, 0, 1, Red); SetIndexBuffer(1, ExtMapBuffer2); SetIndexStyle(2, DRAW_LINE, 0, 1, Blue); SetIndexBuffer(2, ExtMapBuffer3); string commercial = "commercial"; string noncommercial = "noncommercial"; string nonreporting = "nonreporting"; //---- read file if (ReadSeriesFromFile(StringConcatenate(commercial, ".", FileExtention), Delimiter, ComDate, ComRate, MaxComRate, MinComRate) < 0) { return(Terminate()); } if (ReadSeriesFromFile(StringConcatenate(noncommercial, ".", FileExtention), Delimiter, NoncomDate, NoncomRate, MaxNoncomRate, MinNoncomRate) < 0) { return(Terminate()); } if (ReadSeriesFromFile(StringConcatenate(nonreporting, ".", FileExtention), Delimiter, NonrepDate, NonrepRate, MaxNonrepRate, MinNonrepRate) < 0) { return(Terminate()); } //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { int Counted_bars = IndicatorCounted(); int i; i = Bars - Counted_bars - 1; while(i >= 0) { int iCom = ArrayBsearchCorrect(ComDate, Time[i]); int iNoncom = ArrayBsearchCorrect(NoncomDate, Time[i]); int iNonrep = ArrayBsearchCorrect(NonrepDate, Time[i]); // COMDEX calculation below ExtMapBuffer1[i] = (ComRate[iCom]-MinComRate[iCom])/(MaxComRate[iCom]-MinComRate[iCom]); ExtMapBuffer2[i] = (NoncomRate[iNoncom]-MinNoncomRate[iNoncom])/(MaxNoncomRate[iNoncom]-MinNoncomRate[iNoncom]); ExtMapBuffer3[i] = (NonrepRate[iNonrep]-MinNonrepRate[iNoncom])/(MaxNonrepRate[iNonrep]-MinNonrepRate[iNonrep]); i--; } //---- return(0); } //+------------------------------------------------------------------+ int ReadSeriesFromFile(string filename, int delimiter, datetime &keys[], double &values[], double &values1[], double &values2[]) { int h = FileOpen(filename, FILE_CSV || FILE_READ, delimiter); if (h < 1) { Print("File ", filename, " not found, the last error is ", GetLastError()); return(-1); } Print("File ", filename, " open."); int i = 0; while (!FileIsEnding(h)) // UP TO HERE!!!!! { string s = StringTrimRight(FileReadString(h)); if (s == "") { continue; // ignore blank lines } datetime date = StrToTime(s); // value = FileReadNumber(h); // not sure if this is going ot be correct since they're all assigned to strtodouble(s) s = FileReadString(h); double value = StrToDouble(s); double value1 = StrToDouble(s); double value2 = StrToDouble(s); // Print(TimeToStr(date, TIME_DATE), ": ", value, "%"); ArrayResize(keys, i + 1); keys[i] = date; ArrayResize(values, i + 1); values[i] = value; ArrayResize(values1, i + 1); values1[i] = value1; ArrayResize(values2, i + 1); values2[i] = value2; i++; } FileClose(h); SortDictionary(keys, values, values1, values2); return(i); } void SortDictionary(datetime &keys[], double &values[], double &values1[], double &values2[], int sortDirection = MODE_ASCEND) { datetime keyCopy[]; double valueCopy[]; double value1Copy[]; double value2Copy[]; ArrayCopy(keyCopy, keys); ArrayCopy(valueCopy, values); ArrayCopy(value1Copy, values1); ArrayCopy(value2Copy, values2); ArraySort(keys, WHOLE_ARRAY, 0, sortDirection); for (int i = 0; i < MathMin(ArraySize(keys), ArraySize(values), ArraySize(values1), ArraySize(values2)); i++) { //Print(i, ": ", TimeToStr(keys[i], TIME_DATE), " ci=", ArrayBsearch(keyCopy, keys[i]), " cv=", valueCopy[ArrayBsearch(keyCopy, keys[i])]); //values[i] = valueCopy[ArrayBsearch(keyCopy, keys[i])]; values[ArrayBsearch(keys, keyCopy[i])] = valueCopy[i]; values1[ArrayBsearch(keys, keyCopy[i])] = value1Copy[i]; values2[ArrayBsearch(keys, keyCopy[i])] = value2Copy[i]; } } int ArrayBsearchCorrect(datetime array[], datetime value, datetime value1, datetime value2, int count = WHOLE_ARRAY, int start = 0, int direction = MODE_ASCEND) { int i = ArrayBsearch(array, value, value1, value2, count, start, direction); if (value < array[i]) { i = -1; } return (i); if (value1 < array[i]) { i = -1; } return (i); if (value2 < array[i]) { i = -1; } return (i); } int Terminate() { int err = 1; Print("Self-terminating with divide by zero"); err /= 0; return (err); }
If someone could tell me why its not compiling/how to fix it I'd very much appreciate it. I think many others would too because I've seen quite a few threads when I was searching.
If my explanation is unclear please let me know and I'll try to re-explain.
To this post I've also attached the COT data which are in the correct format. (They will need to go in expert->files)
Attached File(s)
commercial.txt
4 KB
|
419 downloads
noncommercial.txt
4 KB
|
371 downloads
nonreporting.txt
3 KB
|
380 downloads