KawaseOsyo_Price

Author: Copyright by. KawaseOsyo,TransEdge co.,Ltd.
KawaseOsyo_Price
0 Views
0 Downloads
0 Favorites
KawaseOsyo_Price
//+------------------------------------------------------------------+
//|                                             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

// ¡¡¡ ƒpƒ‰ƒ[ƒ^
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);
}

// ¡¡¡¡¡¡¡¡¡ I—¹ˆ— ¡¡¡¡¡¡¡¡¡

int deinit()
{
    Comment("");
    DeleteObject();
    return(0);
}

// ¡¡¡¡¡¡¡¡¡ ƒƒCƒ“ˆ— ¡¡¡¡¡¡¡¡¡

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 = "Žc‚è  ";

    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);
}

// ¡¡¡¡¡¡¡¡¡ Žc‚莞ŠÔ ¡¡¡¡¡¡¡¡¡

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 +"•b";
	    if( English ) text = h + "h " + k + "m " + s;
    }
    
    // ¡¡¡ 1•ªˆÈã
    else if( m>0 ){
        text = m + "•ª " + s +"•b";
        if( English ) text = m +"m " + s + "s";
    }

    // ¡¡¡ 60•b–¢–ž
    else{
        text = s + " •b";
        if( English ) text = s + " sec";
    }
    return( text );
}

// ¡¡¡¡¡¡¡¡¡ ƒ‰ƒxƒ‹•`‰æ ¡¡¡¡¡¡¡¡¡

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 );
}

// ¡¡¡¡¡¡¡¡¡ ƒvƒ‰ƒCƒX•`‰æ ¡¡¡¡¡¡¡¡¡

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 );
}

// ¡¡¡¡¡¡¡¡¡ ƒeƒLƒXƒg•`‰æ ¡¡¡¡¡¡¡¡¡

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 );

}

// ¡¡¡¡¡¡¡¡¡ ƒIƒuƒWƒFƒNƒgíœ ¡¡¡¡¡¡¡¡¡

void DeleteObject()
{
string  name = "";
   
    for( int i=ObjectsTotal()-1 ; i>=0 ; i--){
        name = ObjectName(i);
        if( StringFind(name, "KawaseOsyo_Price", 0)==0 ) ObjectDelete( name );
    }   
}

// ¡¡¡¡¡¡¡¡¡ ‰¿Ši‚ð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) );
}

// ¡¡¡¡¡¡¡¡¡ •¶Žš—ñ‚ð‰E‘¤‚©‚ç‚Æ‚肾‚· ¡¡¡¡¡¡¡¡¡

string Right(string src, int length )
{
int cnt = StringLen(src);

    if( cnt>=length )
        return( StringSubstr( src, cnt-length, length ) );  
    else
        return( src );
}

Comments