//+------------------------------------------------------------------+ //| MTF_MARSI_v0.10.mq4 | //| RL | //| http:// | //+------------------------------------------------------------------+ #property copyright "RL (okfar)" #property link "http://" #property indicator_separate_window #property indicator_minimum 0 #property indicator_maximum 100 #property indicator_buffers 2 #property indicator_color1 Blue #property indicator_color2 Gold #property indicator_level1 30 #property indicator_level2 70 #property indicator_levelcolor DarkSlateGray extern int RSIPeriod = 14; extern int MARSIPeriod =8; int ModeMA = MODE_SMA; extern int fontsize = 10; extern int Side = 1; extern int Y = 5; extern int X = 5; extern color maRsiCoolor = Gold; extern color rsiCoolor = Blue; extern color BarLabel_color = DarkGreen; int minBars = 3; int tf[] = {1, 5, 15, 30, 60, 240}; double rsi1[], rsi5[], rsi15[], rsi30[], rsi1H[], rsi4H[]; double maRsi1[], maRsi5[], maRsi15[], maRsi30[], maRsi1H[], maRsi4H[]; double dRsi[]; double dMaRsi[]; string ind; int i, j; int pperiod; int limit[6]; int cBars[6], pBars[6]; int pTime ; //---- buffers //+------------------------------------------------------------------+ //| Custom indicator initialization function | //+------------------------------------------------------------------+ int init() { // if ( barsPerTimeFrame < 100 ) barsPerTimeFrame = 100; //---- indicators IndicatorBuffers(8); SetIndexStyle(0,DRAW_LINE, Blue); SetIndexLabel( 0, "RSI"+Period()); SetIndexBuffer(0, dRsi); SetIndexStyle(1,DRAW_LINE, Green); SetIndexLabel( 1, "MARSI"+Period()); SetIndexBuffer(1, dMaRsi); SetIndexBuffer(2, rsi1); SetIndexBuffer(3, rsi5); SetIndexBuffer(4, rsi15); SetIndexBuffer(5, rsi30); SetIndexBuffer(6, rsi1H); SetIndexBuffer(7, rsi4H); ind = StringConcatenate(WindowExpertName()," RSI (",RSIPeriod,") MARSI(",MARSIPeriod,")"); IndicatorShortName(ind); /* ArraySetAsSeries(maRsi1, true); ArraySetAsSeries(maRsi5, true); ArraySetAsSeries(maRsi15, true); ArraySetAsSeries(maRsi30,true); ArraySetAsSeries(maRsi1H, true); ArraySetAsSeries(maRsi4H, true); */ if (Side == 1 || Side == 3) Write("NumberRsi"+WindowFind(ind), Side, X+(12*fontsize/8), Y, "H4 H1 M30 M15 M5 M1", (fontsize+2), "Tahoma", BarLabel_color); else Write("NumberRsi"+WindowFind(ind), Side, X+(12*fontsize/8), Y, "M1 M5 M15 M30 H1 H4", fontsize+2, "Tahoma", BarLabel_color); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- ObjectDelete("NumberRsi"+WindowFind(ind)); ObjectDelete("maRSI1"+WindowFind(ind)); ObjectDelete("maRSI5"+WindowFind(ind)); ObjectDelete("maRSI15"+WindowFind(ind)); ObjectDelete("maRSI30"+WindowFind(ind)); ObjectDelete("maRSI1H"+WindowFind(ind)); ObjectDelete("maRSI4H"+WindowFind(ind)); ObjectDelete("RSI1"+WindowFind(ind)); ObjectDelete("RSI5"+WindowFind(ind)); ObjectDelete("RSI15"+WindowFind(ind)); ObjectDelete("RSI30"+WindowFind(ind)); ObjectDelete("RSI1H"+WindowFind(ind)); ObjectDelete("RSI4H"+WindowFind(ind)); //---- return(0); } //+------------------------------------------------------------------+ //| Custom indicator iteration function | //+------------------------------------------------------------------+ int start() { //---- for (i=0; i<6; i++) { // if (iClose(Symbol(), tf[i], 0)==0) // return(0); cBars[i] = iBars(Symbol(), tf[i]); if (pBars[i] <= 0) limit[i] = cBars[i] - RSIPeriod - 1; // else if (pBars[i] > 0) { // if (cBars[i] > pBars[i]) // limit[i] = cBars[i] - RSIPeriod - 1; else limit[i] = cBars[i] - pBars[i]; //limit[i] ++; // } } limit[0] = CheckArray(maRsi1, tf[0], limit[0], 0); limit[1] = CheckArray(maRsi5, tf[1], limit[1], 1); limit[2] = CheckArray(maRsi15, tf[2], limit[2], 2); limit[3] = CheckArray(maRsi30, tf[3], limit[3], 3); limit[4] = CheckArray(maRsi1H, tf[4], limit[4], 4); limit[5] = CheckArray(maRsi4H, tf[5], limit[5], 5); // ArrayInitialize(rsi1, 1.0); for (i=limit[0]+MARSIPeriod; i>=0; i--) rsi1[i] = iRSI(Symbol(),tf[0],RSIPeriod,PRICE_CLOSE,i); for (i=limit[1]+MARSIPeriod; i>=0; i--) rsi5[i] = iRSI(Symbol(),tf[1],RSIPeriod,PRICE_CLOSE,i); for (i=limit[2]+MARSIPeriod; i>=0; i--) rsi15[i] = iRSI(Symbol(),tf[2],RSIPeriod,PRICE_CLOSE,i); for (i=limit[3]+MARSIPeriod; i>=0; i--) rsi30[i] = iRSI(Symbol(),tf[3],RSIPeriod,PRICE_CLOSE,i); for (i=limit[4]+MARSIPeriod; i>=0; i--) rsi1H[i] = iRSI(Symbol(),tf[4],RSIPeriod,PRICE_CLOSE,i); for (i=limit[5]+MARSIPeriod; i>=0; i--) rsi4H[i] = iRSI(Symbol(),tf[5],RSIPeriod,PRICE_CLOSE,i); /* // ArrayInitialize(maRsi1, 1.0); for (i=limit[0]; i>=0; i--) maRsi1[i] = iMAOA(rsi1,MARSIPeriod,ModeMA,i); for (i=limit[1]; i>=0; i--) maRsi5[i] = iMAOnArray(rsi5,0,MARSIPeriod,0,ModeMA,i); for (i=limit[2]; i>=0; i--) maRsi15[i] = iMAOnArray(rsi15,0,MARSIPeriod,0,ModeMA,i); for (i=limit[3]; i>=0; i--) maRsi30[i] = iMAOnArray(rsi30,0,MARSIPeriod,0,ModeMA,i); for (i=limit[4]; i>=0; i--) maRsi1H[i] = iMAOnArray(rsi1H,0,MARSIPeriod,0,ModeMA,i); for (i=limit[5]; i>=0; i--) maRsi4H[i] = iMAOnArray(rsi4H,0,MARSIPeriod,0,ModeMA,i); */ for (i=limit[0]; i>=0; i--) maRsi1[i] = iMAOA(rsi1,MARSIPeriod,ModeMA,i); for (i=limit[1]; i>=0; i--) maRsi5[i] = iMAOA(rsi5,MARSIPeriod,ModeMA,i); for (i=limit[2]; i>=0; i--) maRsi15[i] = iMAOA(rsi15,MARSIPeriod,ModeMA,i); for (i=limit[3]; i>=0; i--) maRsi30[i] = iMAOA(rsi30,MARSIPeriod,ModeMA,i); for (i=limit[4]; i>=0; i--) maRsi1H[i] = iMAOA(rsi1H,MARSIPeriod,ModeMA,i); for (i=limit[5]; i>=0; i--) maRsi4H[i] = iMAOA(rsi4H,MARSIPeriod,ModeMA,i); switch (Period()) { case 1: { if (pperiod != Period()) { ArrayResize(maRsi1, cBars[0]); // int cc = cBars[0] - RSIPeriod; } // else // cc = limit[0]+1; for (i=cBars[0] - RSIPeriod; i>=0; i--) maRsi1[i] = iMAOnArray(rsi1,0,MARSIPeriod,0,ModeMA,i); ArrayCopy(dRsi, rsi1, 0, 0, WHOLE_ARRAY); ArrayCopy(dMaRsi, maRsi1, 0, 0, WHOLE_ARRAY); } break; case 5: { if (pperiod != Period()) { ArrayResize(maRsi5, cBars[1]); // cc = cBars[1] - RSIPeriod; } // else // cc = limit[1]+1; for (i=cBars[1] - RSIPeriod; i>=0; i--) maRsi5[i] = iMAOnArray(rsi5,0,MARSIPeriod,0,ModeMA,i); ArrayCopy(dRsi, rsi5, 0, 0, WHOLE_ARRAY); ArrayCopy(dMaRsi, maRsi5, 0, 0, WHOLE_ARRAY); } break; case 15: { if (pperiod != Period()) { ArrayResize(maRsi15, cBars[2]); // cc = cBars[2] - RSIPeriod; } // else // cc = limit[2]+1; for (i=cBars[2] - RSIPeriod; i>=0; i--) maRsi15[i] = iMAOnArray(rsi15,0,MARSIPeriod,0,ModeMA,i); ArrayCopy(dRsi, rsi15, 0, 0, WHOLE_ARRAY); ArrayCopy(dMaRsi, maRsi15, 0, 0, WHOLE_ARRAY); } break; case 30: { if (pperiod != Period()) { ArrayResize(maRsi30, cBars[3]); // cc = cBars[3] - RSIPeriod; } // else // cc = limit[3]+1; for (i=cBars[3] - RSIPeriod; i>=0; i--) maRsi30[i] = iMAOnArray(rsi30,0,MARSIPeriod,0,ModeMA,i); ArrayCopy(dRsi, rsi30, 0, 0); ArrayCopy(dMaRsi, maRsi30, 0, 0); } break; case 60: { if (pperiod != Period()) { ArrayResize(maRsi1H, cBars[4]); // cc = cBars[4] - RSIPeriod; } // else // cc = limit[4]+1; for (i=cBars[4] - RSIPeriod; i>=0; i--) maRsi1H[i] = iMAOnArray(rsi1H,0,MARSIPeriod,0,ModeMA,i); ArrayCopy(dRsi, rsi1H, 0, 0); ArrayCopy(dMaRsi, maRsi1H, 0, 0); } break; case 240: { if (pperiod != Period()) { ArrayResize(maRsi4H, cBars[5]); // cc = cBars[5] - RSIPeriod; } // else // cc = limit[5]+1; for (i=cBars[5] - RSIPeriod; i>=0; i--) maRsi4H[i] = iMAOnArray(rsi4H,0,MARSIPeriod,0,ModeMA,i); ArrayCopy(dRsi, rsi4H, 0, 0); ArrayCopy(dMaRsi, maRsi4H, 0, 0); } break; default: { ArrayInitialize(dRsi, EMPTY_VALUE); ArrayInitialize(dMaRsi, EMPTY_VALUE); } break; } /* for (i=0; i<6; i++) if (cBars[i] != pBars[i]) { Print(i," - ",iBars(Symbol(), tf[i])," - ",iClose(Symbol(), tf[i], 0), " - ",TimeToStr(TimeCurrent(), TIME_SECONDS), " - ", maRsi1[0], " - ", maRsi1[1], " - ", maRsi1[2], " - ", maRsi1[3], " -/ ", limit[0], " -- ", rsi1[0], " - ", rsi1[1], " - ", rsi1[2], " - ", rsi1[3]); Print(2," - ",iBars(Symbol(), tf[2])," - ",iClose(Symbol(), tf[2], 0), " - ",TimeToStr(TimeCurrent(), TIME_SECONDS), " - ", maRsi15[0], " - ", maRsi15[1], " - ", maRsi15[2], " - ", maRsi15[3], " -/ ", limit[2], " -- ", rsi15[0], " - ", rsi15[1], " - ", rsi15[2], " - ", rsi15[3]); } */ for (i=0; i<6; i++) pBars[i] = cBars[i]; pperiod = Period(); //Write("NumberRsi", Side, X+12, Y, "M1 M5 M15 M30 H1 H4", 6, "Tahoma Narrow", BarLabel_color); Write("maRSI1"+WindowFind(ind), Side, X+(5*fontsize/6) , Y+(10*fontsize/6), DoubleToStr(maRsi1[0], 2), fontsize, "Tahoma", maRsiCoolor); Write("maRSI5"+WindowFind(ind), Side, X+(29*fontsize/6), Y+(10*fontsize/6), DoubleToStr(maRsi5[0], 2), fontsize, "Tahoma", maRsiCoolor); Write("maRSI15"+WindowFind(ind), Side, X+(51*fontsize/6), Y+(10*fontsize/6), DoubleToStr(maRsi15[0], 2), fontsize, "Tahoma", maRsiCoolor); Write("maRSI30"+WindowFind(ind), Side, X+(74*fontsize/6), Y+(10*fontsize/6), DoubleToStr(maRsi30[0], 2), fontsize, "Tahoma", maRsiCoolor); Write("maRSI1H"+WindowFind(ind), Side, X+(97*fontsize/6), Y+(10*fontsize/6), DoubleToStr(maRsi1H[0], 2), fontsize, "Tahoma", maRsiCoolor); Write("maRSI4H"+WindowFind(ind), Side, X+(120*fontsize/6), Y+(10*fontsize/6), DoubleToStr(maRsi4H[0], 2), fontsize, "Tahoma", maRsiCoolor); Write("RSI1"+WindowFind(ind), Side, X+(5*fontsize/6) , Y+(18*fontsize/6), DoubleToStr(rsi1[0], 2), fontsize, "Tahoma", rsiCoolor); Write("RSI5"+WindowFind(ind), Side, X+(29*fontsize/6), Y+(18*fontsize/6), DoubleToStr(rsi5[0], 2), fontsize, "Tahoma", rsiCoolor); Write("RSI15"+WindowFind(ind), Side, X+(51*fontsize/6), Y+(18*fontsize/6), DoubleToStr(rsi15[0], 2), fontsize, "Tahoma", rsiCoolor); Write("RSI30"+WindowFind(ind), Side, X+(74*fontsize/6), Y+(18*fontsize/6), DoubleToStr(rsi30[0], 2), fontsize, "Tahoma", rsiCoolor); Write("RSI1H"+WindowFind(ind), Side, X+(97*fontsize/6), Y+(18*fontsize/6), DoubleToStr(rsi1H[0], 2), fontsize, "Tahoma", rsiCoolor); Write("RSI4H"+WindowFind(ind), Side, X+(120*fontsize/6), Y+(18*fontsize/6), DoubleToStr(rsi4H[0], 2), fontsize, "Tahoma", rsiCoolor); //---- //---- return(0); } //+------------------------------------------------------------------+ void Write(string LBL, double Side, int X, int Y, string text, int fontsize, string fontname, color Tcolor) { if (ObjectFind(LBL) < 0) { ObjectCreate(LBL, OBJ_LABEL, WindowFind(ind), 0 , 0); ObjectSet(LBL, OBJPROP_CORNER, Side); ObjectSet(LBL, OBJPROP_XDISTANCE, X); ObjectSet(LBL, OBJPROP_YDISTANCE, Y); } ObjectSetText(LBL,text, fontsize, fontname, Tcolor); } int CheckArray(double arr[], int tf, int n, int c) { if (Period() != tf && ArraySize(arr) != minBars+1) { ArrayResize(arr, minBars+1); // Print("ArrayResize:",tf," - ", ArraySize(arr)); // ArraySetAsSeries(arr, true); return (minBars); } // else if (Period() != tf && pBars[c] != cBars[c]) { // Print("Bars:",tf," - ", pBars[c], " - ", cBars[c]); // return (minBars); // } else return (n); } double iMAOA(double a[],int per,int ModeMa,int sh) { int i; double res = 0.0; switch (ModeMa) { case MODE_SMA: { for (i=0+sh; i<per+sh;i++) res += a[i]; return (res/per); } break; default: return (EMPTY_VALUE); } }
Sample
Analysis
Market Information Used:
Series array that contains close prices for each bar
Indicator Curves created:
Implements a curve of type DRAW_LINE
Indicators Used:
Relative strength index
Moving average indicator
Custom Indicators Used:
Order Management characteristics:
Other Features: