Trabalho concluído
Termos de Referência
Hi coders,
I coded a matrix-indicator which checks if the last closed bar is a pinbar which is simply defined as a bar with a 75% shadow. This checks are made in all timeframes and all currency pairs. It works fine and has just one small bug: the indicator checks all currencies and all timeframes with every tick. And that is wasting much computer calculation time. I want that the M5 timeframe will only be checked at the open of a new M5 bar, the same with all other timeframes. So if I want to check the M1 chart, the indicator's fastest refresh-rate should be once a minute.
According to that I want an Alert to be displayed when conditions are met. At the moment the Alerts are based on Time[0] and I know that is wrong because the bar in the corresponding timeframe has to be checked and not the bar which is displayed in the current chart.
I think every coder will solve this problem within some minutes but I am a beginner and I am still very poor in MQL4-specific data types, syntax and structure.
Here is my code:
//+------------------------------------------------------------------+ //| Pinbar-Scanner.mq4 | //| Copyright 2013, MR | //| | //+------------------------------------------------------------------+ #property copyright "Copyright 2013, MR" #property link "" #property indicator_chart_window extern bool M1 = true; extern bool M5 = true; extern bool M15 = true; extern bool M30 = true; extern bool H1 = true; extern bool H4 = true; extern bool D1 = true; extern bool W1 = true; string Timeframe[]; int TimeframeNo[]; string CurrPair[] = {"AUDCAD", "AUDCHF", "AUDJPY", "AUDNZD", "AUDUSD", "CADCHF", "CHFJPY", "EURAUD", "EURCAD", "EURCHF", "EURGBP", "EURJPY", "EURNZD", "EURUSD", "GBPAUD", "GBPCAD", "GBPCHF", "GBPJPY", "GBPNZD", "GBPUSD", "NZDJPY", "NZDUSD", "USDCAD", "USDCHF", "USDJPY"}; color col; bool PinbarLong, PinbarShort; int dist_X, dist_Y, i, j; //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { //---- Arrays population ---- if (M1) { ArrayResize(Timeframe, ArraySize(Timeframe)+1); Timeframe[ArraySize(Timeframe)-1]="M1"; ArrayResize(TimeframeNo, ArraySize(TimeframeNo)+1); TimeframeNo[ArraySize(TimeframeNo)-1]=PERIOD_M1; } if (M5) { ArrayResize(Timeframe, ArraySize(Timeframe)+1); Timeframe[ArraySize(Timeframe)-1]="M5"; ArrayResize(TimeframeNo, ArraySize(TimeframeNo)+1); TimeframeNo[ArraySize(TimeframeNo)-1]=PERIOD_M5; } if (M15) { ArrayResize(Timeframe, ArraySize(Timeframe)+1); Timeframe[ArraySize(Timeframe)-1]="M15"; ArrayResize(TimeframeNo, ArraySize(TimeframeNo)+1); TimeframeNo[ArraySize(TimeframeNo)-1]=PERIOD_M15; } if (M30) { ArrayResize(Timeframe, ArraySize(Timeframe)+1); Timeframe[ArraySize(Timeframe)-1]="M30"; ArrayResize(TimeframeNo, ArraySize(TimeframeNo)+1); TimeframeNo[ArraySize(TimeframeNo)-1]=PERIOD_M30; } if (H1) { ArrayResize(Timeframe, ArraySize(Timeframe)+1); Timeframe[ArraySize(Timeframe)-1]="H1"; ArrayResize(TimeframeNo, ArraySize(TimeframeNo)+1); TimeframeNo[ArraySize(TimeframeNo)-1]=PERIOD_H1; } if (H4) { ArrayResize(Timeframe, ArraySize(Timeframe)+1); Timeframe[ArraySize(Timeframe)-1]="H4"; ArrayResize(TimeframeNo, ArraySize(TimeframeNo)+1); TimeframeNo[ArraySize(TimeframeNo)-1]=PERIOD_H4; } if (D1) { ArrayResize(Timeframe, ArraySize(Timeframe)+1); Timeframe[ArraySize(Timeframe)-1]="D1"; ArrayResize(TimeframeNo, ArraySize(TimeframeNo)+1); TimeframeNo[ArraySize(TimeframeNo)-1]=PERIOD_D1; } if (W1) { ArrayResize(Timeframe, ArraySize(Timeframe)+1); Timeframe[ArraySize(Timeframe)-1]="W1"; ArrayResize(TimeframeNo, ArraySize(TimeframeNo)+1); TimeframeNo[ArraySize(TimeframeNo)-1]=PERIOD_W1; } //---- Timeframe Objects ---- dist_X = 80; for(i=0; i<=ArrayRange(Timeframe,0)-1; i++) { if (ObjectFind(Timeframe[i]+"txt") == -1) { ObjectCreate(Timeframe[i]+"txt", OBJ_LABEL, 0, 0, 0); ObjectSet(Timeframe[i]+"txt", OBJPROP_CORNER, 0); ObjectSet(Timeframe[i]+"txt", OBJPROP_XDISTANCE, dist_X); ObjectSet(Timeframe[i]+"txt", OBJPROP_YDISTANCE, 0); ObjectSetText(Timeframe[i]+"txt", Timeframe[i], 9, "Calibri", White); dist_X = dist_X+40; } } //---- Currency pairs objects ---- dist_Y = 30; for(i=0; i<=ArrayRange(CurrPair,0)-1; i++) { if (ObjectFind(CurrPair[i]+"txt") == -1) { ObjectCreate(CurrPair[i]+"txt", OBJ_LABEL, 0, 0, 0); ObjectSet(CurrPair[i]+"txt", OBJPROP_CORNER, 0); ObjectSet(CurrPair[i]+"txt", OBJPROP_XDISTANCE, 0); ObjectSet(CurrPair[i]+"txt", OBJPROP_YDISTANCE, dist_Y); ObjectSetText(CurrPair[i]+"txt", CurrPair[i], 9, "Calibri", White); dist_Y = dist_Y+17; } } //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectsDeleteAll(); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { static datetime Time0; //---- Dot matrix ---- dist_X=80; dist_Y=4; for(j=0; j<=ArrayRange(Timeframe,0)-1; j++) { for(i=0; i<=ArrayRange(CurrPair,0)-1; i++) { ObjectCreate(CurrPair[i]+Timeframe[j], OBJ_LABEL, 0, 0, 0); ObjectSet(CurrPair[i]+Timeframe[j], OBJPROP_CORNER, 0); ObjectSet(CurrPair[i]+Timeframe[j], OBJPROP_XDISTANCE, dist_X); ObjectSet(CurrPair[i]+Timeframe[j], OBJPROP_YDISTANCE, dist_Y); //-- Conditions -- PinbarLong = MathMin(iOpen(CurrPair[i], TimeframeNo[j], 1),iClose(CurrPair[i], TimeframeNo[j], 1))- iLow(CurrPair[i], TimeframeNo[j], 1) >= (iHigh(CurrPair[i], TimeframeNo[j], 1)-iLow(CurrPair[i], TimeframeNo[j], 1))*0.75; PinbarShort = iHigh(CurrPair[i], TimeframeNo[j], 1)- MathMax(iOpen(CurrPair[i], TimeframeNo[j], 1),iClose(CurrPair[i], TimeframeNo[j], 1)) >= (iHigh(CurrPair[i], TimeframeNo[j], 1)-iLow(CurrPair[i], TimeframeNo[j], 1))*0.75; //-- Alert -- if (PinbarLong) { col=Lime; if (Time0 != Time[0]) { Alert(CurrPair[i]+" "+Timeframe[j]+" Pinbar Long"); Time0 = Time[0]; } } else if (PinbarShort) { col=Red; if (Time0 != Time[0]) { Alert(CurrPair[i]+" "+Timeframe[j]+" Pinbar Short"); Time0 = Time[0]; } } else { col=Gray; } //-- Dot Matrix -- ObjectSetText(CurrPair[i]+Timeframe[j], "-", 35, "Calibri", col); dist_Y = dist_Y+17; } dist_Y=4; dist_X=dist_X+40; } WindowRedraw(); //---- return(0); } //+------------------------------------------------------------------+
If you would like to complete my code, please tell me what price it will be.
Thank you!
PS: If you attach this indicator to your chart, please set all chart colors to "None".