//+------------------------------------------------------------------+ //| KawaseOsyo_Price.mq4 | //| Copyright ゥ 2010, Syotaro Yoshida,SimplePlanning | //| http://www.kawaseosyo.com/ | //+------------------------------------------------------------------+ #property copyright "Copyright by. KawaseOsyo,TransEdge co.,Ltd." #property link "http://www.kawaseosyo.com/" #property indicator_chart_window // --- Const #define SymbolSize 18 #define PriceSize 28 #define RemainSize 12 #define SpreadSize 12 // ■■■ パラメータ extern string URL = "www.kawaseosyo.com"; extern color SymbolColor = RoyalBlue; extern color PriceColor = Chartreuse; extern color RemainColor = White; extern color SpreadColor = Lime; extern string Label1 ="--- Position ---"; extern int LeftBias = 0; extern int TopBias = 15; extern bool English = false; extern string Label2 ="--- Option ---"; extern bool DrawNear = true; extern int FontSize = 10; extern int DelaySec = 350; // ■■■■■■■■■ 初期設定 ■■■■■■■■■ int init() { if(DelaySec<=0 ) DelaySec=1; Comment(""); DeleteObject(); return(0); } // ■■■■■■■■■ 終了処理 ■■■■■■■■■ int deinit() { Comment(""); DeleteObject(); return(0); } // ■■■■■■■■■ メイン処理 ■■■■■■■■■ int start() { double y1 = 0 + TopBias; double y2 = y1 + NormalizeDouble( 30*(SymbolSize/18.0),1); double y3 = y2 + NormalizeDouble( 90*(SpreadSize/28.0),1); double y4 = y3 + NormalizeDouble( 10*(PriceSize /12.0),1); string left = "残り "; if( English ) left = "Remain: "; DrawLabel( "KawaseOsyo_Price_symbol", Symbol(), 10+LeftBias, y1, "Comic Sans MS", SymbolSize, SymbolColor ); DrawLabel( "KawaseOsyo_Price_spread", "( "+ DoubleToStr( ToPips(Ask-Bid),2 ) +" )", 2+LeftBias, y3, "Arial", SpreadSize, SpreadColor ); if( MarketInfo( "USDJPY", MODE_DIGITS )==2 ) DrawLabel( "KawaseOsyo_Price_Value" , DoubleToStr(Bid,Digits), 2+LeftBias, y2, "Arial", PriceSize, PriceColor ); else DrawPrice( 2+LeftBias, y2, "Arial", PriceSize, PriceColor ); // ■■■ Remaining_Time if( RemainSize>0 ){ DrawLabel( "KawaseOsyo_Price_remain", left+GetLeftTime(), 5+LeftBias, y4, "Arisaka", RemainSize, RemainColor ); if( DrawNear==true ){ DrawText( "KawaseOsyo_Price_time", GetLeftTime(), "Arisaka", FontSize, RemainColor ); } } return(0); } // ■■■■■■■■■ 残り時間 ■■■■■■■■■ string GetLeftTime() { string text; int m = Time[0] + Period()*60 - TimeCurrent(); int s = m % 60; m = (m - m%60) / 60; if( s<0 ) s=0; // ■■■ 60分以下 if( m>=60 ){ int h = m/60; int k = m - (h*60); text = h + "時間 " + k + "分 " + s +"秒"; if( English ) text = h + "h " + k + "m " + s; } // ■■■ 1分以上 else if( m>0 ){ text = m + "分 " + s +"秒"; if( English ) text = m +"m " + s + "s"; } // ■■■ 60秒未満 else{ text = s + " 秒"; if( English ) text = s + " sec"; } return( text ); } // ■■■■■■■■■ ラベル描画 ■■■■■■■■■ void DrawLabel( string label, string text, int x, int y, string FontType, int size, color fontColor ) { if( ObjectFind(label)==-1 ){ ObjectCreate ( label, OBJ_LABEL, 0, 0, 0 ); ObjectSet ( label, OBJPROP_CORNER, 1 ); ObjectSet ( label, OBJPROP_XDISTANCE, x ); ObjectSet ( label, OBJPROP_YDISTANCE, y ); } ObjectSetText( label, text, size, FontType, fontColor ); } // ■■■■■■■■■ プライス描画 ■■■■■■■■■ void DrawPrice( int x, int y, string FontType, int size, color fontColor ) { double price = NormalizeDouble( Bid, Digits ); double p1 = MathFloor( price * MathPow(10,Digits-3) ) / MathPow(10,Digits-3); double p2 = (price-p1) * MathPow(10,Digits); string large = DoubleToStr(p1,2); string txt = Right("000"+DoubleToStr(p2,0),3); string middle = StringSubstr( txt,0,2 ); string small = StringSubstr( txt,2,1 ); if( StringFind(Symbol(),"JPY")>0 ) large = DoubleToStr(p1,0)+"."; // --- Large ObjectCreate ( "KawaseOsyo_Price_L", OBJ_LABEL, 0, 0, 0 ); ObjectSet ( "KawaseOsyo_Price_L", OBJPROP_CORNER, 1 ); ObjectSet ( "KawaseOsyo_Price_L", OBJPROP_XDISTANCE, x + 60 ); ObjectSet ( "KawaseOsyo_Price_L", OBJPROP_YDISTANCE, y + 15 ); ObjectSetText( "KawaseOsyo_Price_L", large, size-10, FontType, fontColor ); // --- Middle ObjectCreate ( "KawaseOsyo_Price_M", OBJ_LABEL, 0, 0, 0 ); ObjectSet ( "KawaseOsyo_Price_M", OBJPROP_CORNER, 1 ); ObjectSet ( "KawaseOsyo_Price_M", OBJPROP_XDISTANCE, x + 15 ); ObjectSet ( "KawaseOsyo_Price_M", OBJPROP_YDISTANCE, y + 0 ); ObjectSetText( "KawaseOsyo_Price_M", middle, size+ 0, FontType, fontColor ); // --- Small ObjectCreate ( "KawaseOsyo_Price_S", OBJ_LABEL, 0, 0, 0 ); ObjectSet ( "KawaseOsyo_Price_S", OBJPROP_CORNER, 1 ); ObjectSet ( "KawaseOsyo_Price_S", OBJPROP_XDISTANCE, x + 0 ); ObjectSet ( "KawaseOsyo_Price_S", OBJPROP_YDISTANCE, y + 15 ); ObjectSetText( "KawaseOsyo_Price_S", small, size-10, FontType, fontColor ); } // ■■■■■■■■■ テキスト描画 ■■■■■■■■■ void DrawText( string label, string text, string FontType, int size, color fontColor ) { if( ObjectFind(label)==-1 ){ ObjectCreate ( label, OBJ_TEXT, 0, 0, 0 ); } ObjectSet ( label, OBJPROP_PRICE1, Bid ); ObjectSet ( label, OBJPROP_TIME1, Time[0]+(Period()*DelaySec) ); ObjectSetText( label, text, size, FontType, fontColor ); } // ■■■■■■■■■ オブジェクト削除 ■■■■■■■■■ void DeleteObject() { string name = ""; for( int i=ObjectsTotal()-1 ; i>=0 ; i--){ name = ObjectName(i); if( StringFind(name, "KawaseOsyo_Price", 0)==0 ) ObjectDelete( name ); } } // ■■■■■■■■■ 価格をPipsに変換 ■■■■■■■■■ double ToPips(double price) { if( MarketInfo( "USDJPY", MODE_DIGITS )==2 ) return ( NormalizeDouble( price/Point,Digits+1) ); else return ( NormalizeDouble( price/(Point*10),Digits+1) ); } // ■■■■■■■■■ 文字列を右側からとりだす ■■■■■■■■■ string Right(string src, int length ) { int cnt = StringLen(src); if( cnt>=length ) return( StringSubstr( src, cnt-length, length ) ); else return( src ); }