KawaseOsyo_Price

Download script
Author: Copyright by. KawaseOsyo,TransEdge co.,Ltd.
KawaseOsyo_Price

This script is designed as a visual dashboard for the Metatrader 4 platform. Its primary purpose is to display essential real-time trading information—such as currency symbols, current prices, spreads, and countdown timers—directly on the chart in an organized, easy-to-read layout.

Instead of forcing you to look at different corners of your screen or various windows, this script centralizes key data points into a single visual cluster. Here is a breakdown of how the logic works:

Dynamic Information Display

The script automatically identifies and displays the following four key pieces of information:

  • Symbol Identification: It shows the current trading pair (e.g., EURUSD) prominently at the top of the display.
  • Spread Tracking: It calculates the difference between the "Bid" and "Ask" prices in real-time, showing you exactly how much the market is currently costing to execute a trade.
  • Live Pricing: It retrieves the current market price. Interestingly, for certain types of currencies (like those involving Yen), it has specialized logic to ensure the price is formatted correctly so that it remains readable and accurate according to standard trading conventions.
  • Time Remaining: The script calculates how much time is left in the current candle (the current timeframe on your chart). It intelligently converts this into a human-readable format, automatically switching between "Hours/Minutes/Seconds" or just "Minutes/Seconds" depending on how much time is remaining.

Visual Organization and Customization

The logic is built to be visually clean and customizable for the user:

  • Layered Layout: The script uses specific mathematical offsets to stack the information vertically. This ensures that the text for the price, spread, and timer do not overlap with one another.
  • Formatting Options: It includes a toggle for different languages (specifically handling Japanese and English characters) and allows the user to choose different colors and font sizes for each piece of data.
  • Dynamic Positioning: The script is designed to anchor the information to a specific corner of your chart, keeping it out of the way of your price action candles while remaining easily accessible at a glance.

Automatic Management

To ensure the chart stays clean:

  • Clean Up: Every time the script is loaded or removed from the chart, it includes an automated "cleanup" function. This deletes any old labels or text objects it created previously, preventing your chart from becoming cluttered with leftover data.
  • Real-Time Updates: The script constantly refreshes its calculations to ensure that as the market moves or as time ticks by, the numbers on your screen stay perfectly synchronized with the live market.
4 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