Market Price

 
楼主  收藏   举报   帖子创建时间:  2019-05-05 05:12 回复:0 关注量:72
marketprice-v1.4-mt4.png

  1. //+------------------------------------------------------------------+
  2. //|                                           #MarketPrice _v1_4.mq4 |
  3. //|                                                       ServerUang |
  4. //|                                    http://www.indofx-trader.net/ |
  5. //+------------------------------------------------------------------+
  6. #property copyright "ServerUang"
  7. #property link      "http://www.indofx-trader.net/"

  8. #property indicator_chart_window
  9. extern string Settings_n_1 = "--------------------------";
  10. extern int Side = 1;
  11. extern int MP_Y = 0;
  12. extern int MP_X = 0;

  13. //--------------------------------------------------------------------
  14. extern string Settings_n_2 = "--------------------------";
  15. extern string Colors_Setting ="Setting for Colors";
  16. extern color Highest_Color          = Blue;
  17. extern color Distance_from_Highest_Color = DodgerBlue;
  18. extern color Lowest_Color           = Red;
  19. extern color Distance_from_Lowest_Color  = OrangeRed;
  20. extern color Hi_to_Lo_Color         = Peru;
  21. extern color Daily_Av_Up_Color      = Blue;
  22. extern color Daily_Av_Dn_Color      = Red;
  23. extern color Time_n_Spread_Color    = LimeGreen;
  24. extern color PipsToOpen_Up_Color    = Blue;
  25. extern color PipsToOpen_Dn_Color    = Red;

  26. //--------------------------------------------------------------------
  27. extern string Settings_n_3 = "--------------------------";
  28. extern string Signals_Settings = "Settings for Signals";
  29. extern bool  Show_Signals      = true;

  30. // BuySeLL Variable
  31. extern string BuySeLL_Settings = "--------------------------";
  32. extern int MAFast_Period = 1;
  33. extern int MAFast_Method = 0;
  34. extern int MAFast_Apply_To = 0;
  35. extern int MAFast_Shift = 0;

  36. extern int MASlow_Period = 4;
  37. extern int MASlow_Method = 0;
  38. extern int MASlow_Apply_To = 1;
  39. extern int MASlow_Shift = 0;

  40. // Trend Variable
  41. extern string TRend_Settings = "--------------------------";
  42. extern int TMAFast_Period = 1;
  43. extern int TMAFast_Method = 0;
  44. extern int TMAFast_Apply_To = 0;
  45. extern int TMAFast_Shift = 0;

  46. extern int TMASlow_Period = 20;
  47. extern int TMASlow_Method = 0;
  48. extern int TMASlow_Apply_To = 0;
  49. extern int TMASlow_Shift = 0;

  50. // Strength Variable
  51. extern string Strength_Settings = "--------------------------";
  52. extern int RSI_Period = 5;
  53. extern int RSI_PRICE_TYPE = 0;

  54. extern int CCI_Period = 20;
  55. extern int CCI_PRICE_TYPE = 0;

  56. extern int STOCH_K_Period = 5;
  57. extern int STOCH_D_Period = 3;
  58. extern int STOCH_Slowing = 3;
  59. extern int STOCH_MA_MODE = 0;
  60. extern int STOCH_Price_Field = 0;

  61. //--------------------------------------------------------------------
  62. extern string Settings_n_4 = "--------------------------";
  63. extern color LegendColor = Gainsboro;
  64. extern color PriceColor_Up = Blue;
  65. extern color PriceColor_Dn = Red;
  66. extern color NeutralColor = LightGray;

  67. extern color Arrow_Up = Lime;
  68. extern color Arrow_Dn = Gold;
  69. extern color Arrow_Nt = White;

  70. //===================================================================+
  71. double vA, vB, vC, TFs, High_Lama, Low_Lama;
  72. int Timeframe, x, y, space, baris, fontsize, cTF, cCC, cX, cSTR, cTR;
  73. string text, fontname, Teks_Menit, Teks_Detik;
  74. string UpSymbol="?,  DnSymbol="?, NtSymbol="?, SignalSymbol;
  75. color SignalColor;

  76. // --- variabel Daili_Av --------------------------------------------+
  77. int    R1, R5, R10, R20, RAvg, n, i;
  78. string Teks_ReRata = "", Teks_Rerata_Kemarin ="";
  79. color  warna_ReRata, WarnaTeks;
  80. //-------------------------------------------------------------------+

  81. // --- Strength Variable ---
  82. double v_RSI, v_Stoch, v_CCI;
  83. //+------------------------------------------------------------------+
  84. //| Custom indicator initialization function                         |
  85. //+------------------------------------------------------------------+
  86. int init()
  87.   {
  88. //---- indicators
  89. //----
  90.    return(0);
  91.   }
  92. //+------------------------------------------------------------------+
  93. //| Custom indicator deinitialization function                       |
  94. //+------------------------------------------------------------------+
  95. int deinit()
  96.   {
  97. //----
  98.      for(int i = ObjectsTotal() - 1; i >= 0; i--)
  99.      {
  100.        string label = ObjectName(i);
  101.        if(StringSubstr(label, 0, 4) != "MP14")
  102.            continue;
  103.        ObjectDelete(label);   
  104.      }   //----
  105.    return(0);
  106.    
  107.    //ObjectsDeleteAll(0,OBJ_HLINE);
  108.    //ObjectsDeleteAll(0,OBJ_TEXT);
  109.    //ObjectsDeleteAll(0,OBJ_LABEL);
  110. //----
  111.    return(0);
  112.   }
  113. //+------------------------------------------------------------------+
  114. //| Custom indicator iteration function                              |
  115. //+------------------------------------------------------------------+
  116. int start()
  117.   {
  118.    int    counted_bars=IndicatorCounted();
  119. //----
  120.    // Price
  121.    Timeframe = 15;
  122.    vA = iMA(Symbol(),0,1,0,MODE_EMA,PRICE_CLOSE,0);
  123.    vB = iMA(Symbol(), Timeframe, MAFast_Period, MAFast_Shift, MAFast_Method, MAFast_Apply_To, 0);
  124.    vC = iMA(Symbol(), Timeframe, MASlow_Period, MASlow_Shift, MASlow_Method, MASlow_Apply_To, 0);
  125.    Write("MP14001", Side, MP_X+9, MP_Y+22, DoubleToStr(vA,Digits), 34, "Arial", CheckColor(vB, vC, PriceColor_Up, PriceColor_Dn) );

  126.    // Highest
  127.    vB=iHigh(NULL,1440,0); text=DoubleToStr(vB, Digits);
  128.    Write("MP14002", Side, MP_X+100, MP_Y+14, text, 10, "Tahoma Bold", Highest_Color);
  129.    
  130.    // Lowest
  131.    vC=iLow(NULL,1440,0); text=DoubleToStr(vC, Digits);
  132.    Write("MP14003", Side, MP_X+100, MP_Y+62, text, 10, "Tahoma Bold", Lowest_Color);
  133.    
  134.    //--- Distance from Highest ---
  135.    text=DoubleToStr((vA-vB)/Point,0);
  136.    Write("MP14004", Side, MP_X+56, MP_Y+14, text, 10, "Tahoma Bold", Distance_from_Highest_Color);
  137.    
  138.    //--- Distance from Lowest ---
  139.    text=DoubleToStr((vA-vC)/Point,0);
  140.    Write("MP14005", Side, MP_X+56, MP_Y+62, text, 10, "Tahoma Bold", Distance_from_Lowest_Color);
  141.    
  142.    //--- Hi to Lo ---
  143.    text=DoubleToStr((vB-vC)/Point,0);
  144.    Write("MP14006", Side, MP_X+10, MP_Y+14, text, 10, "Tahoma Bold", Hi_to_Lo_Color);
  145.    
  146.    //--- Daily Av ---
  147.    R1=0; R5=0; R10=0; R20=0; RAvg=0; i=0;
  148.    R1 =  (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/Point;
  149.    for(i=1;i<=5;i++)   
  150.      R5  = R5  + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
  151.    for(i=1;i<=10;i++)
  152.      R10 = R10 + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;
  153.    for(i=1;i<=20;i++)
  154.      R20 = R20 + (iHigh(NULL,PERIOD_D1,i)-iLow(NULL,PERIOD_D1,i))/Point;

  155.    R5 = R5/5;
  156.    R10 = R10/10;
  157.    R20 = R20/20;
  158.    RAvg  =  (R1+R5+R10+R20)/4;   
  159.    
  160.    Teks_ReRata = (DoubleToStr(RAvg,Digits-4));
  161.    Teks_Rerata_Kemarin = (iHigh(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1))/Point;
  162.    
  163.    if (Teks_ReRata > Teks_Rerata_Kemarin) {warna_ReRata = Daily_Av_Up_Color;}
  164.       else {warna_ReRata = Daily_Av_Dn_Color;}
  165.       
  166.    Write("MP14007", Side, MP_X+10, MP_Y+62, Teks_ReRata, 10, "Tahoma Bold", warna_ReRata);
  167.    
  168.    //--- Time for Next Candle ---
  169.    vB = (Time[4]-Time[5])-MathMod(CurTime(),Time[4]-Time[5]);
  170.    vA = vB/60;
  171.    vB = (vA-MathFloor(vA))*60;
  172.    vA = MathFloor(vA);
  173.    Teks_Menit = DoubleToStr(vA,0);
  174.    Teks_Detik = DoubleToStr(vB,0);
  175.    text=Teks_Menit+":"+Teks_Detik;
  176.    Write("MP14008", Side, MP_X+100, MP_Y+74, text, 10, "Tahoma Bold", Time_n_Spread_Color);
  177.    
  178.    // --- Spread ---
  179.    vA = (Ask - Bid)/Point;
  180.    text = (DoubleToStr(vA, Digits-4));
  181.    Write("MP14009", Side, MP_X+56, MP_Y+74, text, 10, "Tahoma Bold", Time_n_Spread_Color);
  182.    
  183.    //--- Pips to Open ---
  184.    vA = iOpen(NULL,1440,0);
  185.    vB = iClose(NULL,1440,0);
  186.    SignalColor=CheckColor(vB, vA, PipsToOpen_Up_Color, PipsToOpen_Dn_Color);
  187.    text=DoubleToStr((vB-vA)/Point,0);
  188.    Write("MP14010", Side, MP_X+10, MP_Y+74, text, 10, "Tahoma Bold", SignalColor);
  189.    
  190.    //--- Show_Signals ---
  191.    if (Show_Signals)
  192.       {
  193.    
  194.        // Legend
  195.        //cTF=MP_X+127; cCC=MP_X+99; cX=MP_X+81; cSTR=MP_X+53; cTR=MP_X+25;
  196.        cTF=MP_X+127; cCC=MP_X+99; cX=MP_X+76; cSTR=MP_X+40; cTR=MP_X+10;
  197.        Write("MP14011", Side, MP_X+cTF,  MP_Y+90, "TF", 10, "Arial", LegendColor); //152
  198.        Write("MP14012", Side, MP_X+cCC,  MP_Y+90, "CC", 10, "Arial", LegendColor); //116
  199.        Write("MP14013", Side, MP_X+cX-5, MP_Y+90, "BS", 10, "Arial", LegendColor);  //086
  200.        Write("MP14014", Side, MP_X+cSTR, MP_Y+90, "Str", 10, "Arial", LegendColor); //048
  201.        Write("MP14015", Side, MP_X+cTR,  MP_Y+90, "TR", 10, "Arial", LegendColor); //012
  202.    
  203.        x=cTF; //154
  204.        y=MP_Y+106; space=12; fontname="Arial"; fontsize=8;
  205.        Write("MP14016", Side, x, y+(00*space), "MN", fontsize, fontname, LegendColor);
  206.        Write("MP14017", Side, x, y+(01*space), "W1", fontsize, fontname, LegendColor);
  207.        Write("MP14018", Side, x, y+(02*space), "D1", fontsize, fontname, LegendColor);
  208.    
  209.        Write("MP14019", Side, x, y+(04*space), "H4", fontsize, fontname, LegendColor);
  210.        Write("MP14020", Side, x, y+(05*space), "H1", fontsize, fontname, LegendColor);
  211.        Write("MP14021", Side, x, y+(06*space), "M30", fontsize, fontname, LegendColor);
  212.    
  213.        Write("MP14022", Side, x, y+(08*space), "M15", fontsize, fontname, LegendColor);
  214.        Write("MP14023", Side, x, y+(09*space), "M5", fontsize, fontname, LegendColor);
  215.        Write("MP14024", Side, x, y+(10*space), "M1", fontsize, fontname, LegendColor);
  216.    
  217.        // LOOP
  218.        n=1; y=MP_Y+106; space=12;
  219.        while (n<=9)
  220.              {
  221.               switch (n)
  222.                 {
  223.                  case 1: TFs = 43200;  baris=0;  break;
  224.                  case 2: TFs = 10080;  baris=1;  break;
  225.                  case 3: TFs =  1440;  baris=2;  break;
  226.               
  227.                  case 4: TFs =   240;  baris=4;  break;
  228.                  case 5: TFs =    60;  baris=5;  break;
  229.                  case 6: TFs =    30;  baris=6;  break;
  230.               
  231.                  case 7: TFs =    15;  baris=8;  break;
  232.                  case 8: TFs =     5;  baris=9;  break;
  233.                  case 9: TFs =     1;  baris=10; break;
  234.                 }//switch
  235.             
  236.                 // Trend;
  237.                 vA = iMA(Symbol(),TFs, TMAFast_Period, TMAFast_Shift, TMAFast_Method, TMAFast_Apply_To, 0);
  238.                 vB = iMA(Symbol(),TFs, TMASlow_Period, TMASlow_Shift, TMASlow_Method, TMASlow_Apply_To, 0);
  239.                 if (vA>vB)
  240.                    { SignalSymbol=UpSymbol; SignalColor=Arrow_Up; }
  241.                 else if  (vA<vB)
  242.                    { SignalSymbol=DnSymbol; SignalColor=Arrow_Dn; }
  243.                 else {SignalSymbol=NtSymbol; SignalColor=Arrow_Nt; }
  244.                 Write("MP14025"+DoubleToStr(n,0), Side, cTR, y+(baris*space), SignalSymbol, 10, "Wingdings", SignalColor );
  245.             
  246.                 // STR Signals
  247.                 v_RSI   = iRSI(Symbol(), TFs, RSI_Period , RSI_PRICE_TYPE, 0);
  248.                 v_Stoch = iStochastic(Symbol(), TFs, STOCH_K_Period,STOCH_D_Period,STOCH_Slowing, STOCH_MA_MODE, STOCH_Price_Field, MODE_MAIN, 0);
  249.                 v_CCI   = iCCI(Symbol(), TFs,CCI_Period , CCI_PRICE_TYPE, 0);
  250.                
  251.                 if ((v_RSI > 50) && (v_Stoch > 40) && (v_CCI > 0)) { SignalSymbol = UpSymbol; SignalColor = Arrow_Up ;}
  252.                 else if ((v_RSI < 50) && (v_Stoch < 60) && (v_CCI < 0)) { SignalSymbol = DnSymbol; SignalColor = Arrow_Dn ;}
  253.             
  254.                 //netral condition
  255.                 else if ((v_RSI < 50) && (v_Stoch > 40) && (v_CCI > 0)) { SignalSymbol = NtSymbol;  SignalColor = Arrow_Nt; }
  256.                 else if ((v_RSI > 50) && (v_Stoch < 60) && (v_CCI < 0)) { SignalSymbol = NtSymbol;  SignalColor = Arrow_Nt; }
  257.                 else if ((v_RSI < 50) && (v_Stoch > 40) && (v_CCI < 0)) { SignalSymbol = NtSymbol;  SignalColor = Arrow_Nt; }
  258.                 else if ((v_RSI > 50) && (v_Stoch < 60) && (v_CCI > 0)) { SignalSymbol = NtSymbol;  SignalColor = Arrow_Nt; }
  259.                 else if ((v_RSI > 50) && (v_Stoch > 40) && (v_CCI < 0)) { SignalSymbol = NtSymbol;  SignalColor = Arrow_Nt; }
  260.                 else if ((v_RSI > 50) && (v_Stoch < 60) && (v_CCI < 0)) { SignalSymbol = NtSymbol;  SignalColor = Arrow_Nt; }
  261.             
  262.                 Write("MP14026"+DoubleToStr(n,0), Side, cSTR, y+(baris*space), SignalSymbol, 10, "Wingdings", SignalColor );
  263.             
  264.             
  265.                 // BuySell Crossing
  266.                 vB = iMA(Symbol(), TFs, MAFast_Period, MAFast_Shift, MAFast_Method, MAFast_Apply_To, 0);
  267.                 vC = iMA(Symbol(), TFs, MASlow_Period, MASlow_Shift, MASlow_Method, MASlow_Apply_To, 0);
  268.                 if (vB>vC)
  269.                    { SignalSymbol=UpSymbol; SignalColor=Arrow_Up; }
  270.                 else { SignalSymbol=DnSymbol; SignalColor=Arrow_Dn; }
  271.                 Write("MP14027"+DoubleToStr(n,0), Side, cX-3, y+(baris*space), SignalSymbol, 10, "Wingdings", SignalColor);
  272.             
  273.             
  274.                 // CandleColor
  275.                 vC = iClose( NULL , TFs, 0) - iOpen( NULL , TFs, 0);
  276.                 if ( vC > 0 )
  277.                    { SignalColor = PriceColor_Up;  SignalSymbol="n"; }
  278.                 else if ( vC < 0 )  { SignalColor = PriceColor_Dn; SignalSymbol="n"; }
  279.                 else { SignalColor = NeutralColor; SignalSymbol="?; }
  280.                 Write("MP14028"+DoubleToStr(n,0), Side, cCC+2, y+(baris*space), SignalSymbol, 10, "Wingdings", SignalColor ); //x=120
  281.                
  282.                
  283.                 Write("MP14029", Side, cTR, y+((baris+1)*space), "Created by ServerUang", 7, "Tahoma Narrow", Gray);
  284.             
  285.                 n++;
  286.              } //end while
  287.          
  288.          }//Show
  289.          else Write("MP14030", Side, MP_X+10, MP_Y+90, "Created by ServerUang", 7, "Tahoma Narrow", Gray);

  290. //----
  291.    return(0);
  292.   }
  293. //+------------------------------------------------------------------+
  294. //+------------------------------------------------------------------+
  295. //+------------------------------------------------------------------+

  296. // Write Procedure
  297. void Write(string LBL, double side, int pos_x, int pos_y, string text, int fontsize, string fontname, color Tcolor=CLR_NONE)
  298.      {
  299.        ObjectCreate(LBL, OBJ_LABEL, 0, 0, 0);
  300.        ObjectSetText(LBL,text, fontsize, fontname, Tcolor);
  301.        ObjectSet(LBL, OBJPROP_CORNER, side);
  302.        ObjectSet(LBL, OBJPROP_XDISTANCE, pos_x);
  303.        ObjectSet(LBL, OBJPROP_YDISTANCE, pos_y);
  304.      }
  305.      
  306.      
  307. // CheckColor Function

  308. color CheckColor(double a, double b, color u, color d)
  309.       {
  310.         if (a>b) { return (u); } else { return (d); }
  311.       }

  312. //+------------------------------------------------------------------+
打赏