fxsquirrel:
Hi, I created this price ticker as I wanted to use the Market Watch prices and to reduce the quote to one less decimal place but still see the fractional element. It works great but the only snag is the colour doesn't change. What have a i missed? Thanks in advance.
int start(){ double Old_Price,Old_Spread;Shouldn't Old_Price be remembered between calls? Currently (since you're not using strict) it is always zero.
fxsquirrel:
Hi, I created this price ticker as I wanted to use the Market Watch prices and to reduce the quote to one less decimal place but still see the fractional element. It works great but the only snag is the colour doesn't change. What have a i missed? Thanks in advance.
- You should stop to use obsolete functions init(), deinit(), start().
- You should start to use #property strict.
- You should create objects in OnInit().
- Then you just change color and text in the loop OnCalculate()
- This indicator has no sense on metals, indexes...
See the updated code as an example:
#property strict #property indicator_chart_window int OnInit() { string FontType="Arial"; color FontColour=clrBlue; ObjectCreate(0,"Symbol_Label",OBJ_LABEL,0,0,0); ObjectSetString(0,"Symbol_Label",OBJPROP_TEXT,_Symbol); ObjectSetString(0,"Symbol_Label",OBJPROP_FONT,FontType); ObjectSetInteger(0,"Symbol_Label",OBJPROP_FONTSIZE,27); ObjectSetInteger(0,"Symbol_Label",OBJPROP_COLOR,FontColour); ObjectSetInteger(0,"Symbol_Label",OBJPROP_CORNER,CORNER_RIGHT_UPPER); ObjectSetInteger(0,"Symbol_Label",OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER); ObjectSetInteger(0,"Symbol_Label",OBJPROP_XDISTANCE,1); ObjectSetInteger(0,"Symbol_Label",OBJPROP_YDISTANCE,1); ObjectSetInteger(0,"Symbol_Label",OBJPROP_SELECTABLE,false); ObjectCreate(0,"Bid_Price_Label",OBJ_LABEL,0,0,0); ObjectSetString(0,"Bid_Price_Label",OBJPROP_FONT,FontType); ObjectSetInteger(0,"Bid_Price_Label",OBJPROP_FONTSIZE,27); ObjectSetInteger(0,"Bid_Price_Label",OBJPROP_COLOR,FontColour); ObjectSetInteger(0,"Bid_Price_Label",OBJPROP_CORNER,CORNER_RIGHT_UPPER); ObjectSetInteger(0,"Bid_Price_Label",OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER); ObjectSetInteger(0,"Bid_Price_Label",OBJPROP_XDISTANCE,14); ObjectSetInteger(0,"Bid_Price_Label",OBJPROP_YDISTANCE,35); ObjectSetInteger(0,"Bid_Price_Label",OBJPROP_SELECTABLE,false); ObjectCreate(0,"Fraction_Price_Label",OBJ_LABEL,0,0,0); ObjectSetString(0,"Fraction_Price_Label",OBJPROP_FONT,FontType); ObjectSetInteger(0,"Fraction_Price_Label",OBJPROP_FONTSIZE,16); ObjectSetInteger(0,"Fraction_Price_Label",OBJPROP_COLOR,FontColour); ObjectSetInteger(0,"Fraction_Price_Label",OBJPROP_CORNER,CORNER_RIGHT_UPPER); ObjectSetInteger(0,"Fraction_Price_Label",OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER); ObjectSetInteger(0,"Fraction_Price_Label",OBJPROP_XDISTANCE,1); ObjectSetInteger(0,"Fraction_Price_Label",OBJPROP_YDISTANCE,38); ObjectSetInteger(0,"Fraction_Price_Label",OBJPROP_SELECTABLE,false); ObjectCreate(0,"Spread_Label",OBJ_LABEL,0,0,0); ObjectSetString(0,"Spread_Label",OBJPROP_FONT,FontType); ObjectSetInteger(0,"Spread_Label",OBJPROP_FONTSIZE,27); ObjectSetInteger(0,"Spread_Label",OBJPROP_COLOR,FontColour); ObjectSetInteger(0,"Spread_Label",OBJPROP_CORNER,CORNER_RIGHT_UPPER); ObjectSetInteger(0,"Spread_Label",OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER); ObjectSetInteger(0,"Spread_Label",OBJPROP_XDISTANCE,14); ObjectSetInteger(0,"Spread_Label",OBJPROP_YDISTANCE,66); ObjectSetInteger(0,"Spread_Label",OBJPROP_SELECTABLE,false); ObjectCreate(0,"Spread_Fraction_Label",OBJ_LABEL,0,0,0); ObjectSetString(0,"Spread_Fraction_Label",OBJPROP_FONT,FontType); ObjectSetInteger(0,"Spread_Fraction_Label",OBJPROP_FONTSIZE,16); ObjectSetInteger(0,"Spread_Fraction_Label",OBJPROP_COLOR,FontColour); ObjectSetInteger(0,"Spread_Fraction_Label",OBJPROP_CORNER,CORNER_RIGHT_UPPER); ObjectSetInteger(0,"Spread_Fraction_Label",OBJPROP_ANCHOR,ANCHOR_RIGHT_UPPER); ObjectSetInteger(0,"Spread_Fraction_Label",OBJPROP_XDISTANCE,1); ObjectSetInteger(0,"Spread_Fraction_Label",OBJPROP_YDISTANCE,66); ObjectSetInteger(0,"Spread_Fraction_Label",OBJPROP_SELECTABLE,false); return(INIT_SUCCEEDED); } void OnDeinit(const int reason) { ObjectDelete("Symbol_Label"); ObjectDelete("Bid_Price_Label"); ObjectDelete("Fraction_Price_Label"); ObjectDelete("Spread_Label"); ObjectDelete("Spread_Fraction_Label"); } int OnCalculate (const int rates_total, // size of input time series const int prev_calculated, // bars handled in previous call const datetime& time[], // Time const double& open[], // Open const double& high[], // High const double& low[], // Low const double& close[], // Close const long& tick_volume[], // Tick Volume const long& volume[], // Real Volume const int& spread[] // Spread ) { static double Old_Price=0.0; static long Old_Spread=0; string Bid_Price,Fraction_Price,Spread_Price,Spread_Fraction; color FontColour,FontColour2; double M=pow(10,Digits-1); FontColour=Bid>Old_Price?clrBlue:clrRed; Old_Price=Bid; FontColour2=SymbolInfoInteger(_Symbol,SYMBOL_SPREAD)>Old_Spread?clrBlue:clrRed; Old_Spread=SymbolInfoInteger(_Symbol,SYMBOL_SPREAD); Bid_Price=DoubleToString(int(Bid*M)/M,Digits-1); Fraction_Price=DoubleToString((Bid-int(Bid*M)/M)*pow(10,Digits),0); Spread_Price=DoubleToString(Old_Spread/10.0,0); Spread_Fraction=StringSubstr(DoubleToStr(MarketInfo(NULL,MODE_SPREAD)/10,1),2); ObjectSetString(0,"Symbol_Label",OBJPROP_TEXT,_Symbol); ObjectSetInteger(0,"Symbol_Label",OBJPROP_COLOR,FontColour); ObjectSetString(0,"Bid_Price_Label",OBJPROP_TEXT,Bid_Price); ObjectSetInteger(0,"Bid_Price_Label",OBJPROP_COLOR,FontColour); ObjectSetString(0,"Fraction_Price_Label",OBJPROP_TEXT,Fraction_Price); ObjectSetInteger(0,"Fraction_Price_Label",OBJPROP_COLOR,FontColour); ObjectSetString(0,"Spread_Label",OBJPROP_TEXT,Spread_Price); ObjectSetInteger(0,"Spread_Label",OBJPROP_COLOR,FontColour); ObjectSetString(0,"Spread_Fraction_Label",OBJPROP_TEXT,Spread_Fraction); ObjectSetInteger(0,"Spread_Fraction_Label",OBJPROP_COLOR,FontColour); return(rates_total); }
Petr Nosek:
Thanks very much for your explanation. I didn't expect you to code it for me but appreciate the help. I don't think I've seen "?" used before so I'll use this as a lesson, thanks.
- You should stop to use obsolete functions init(), deinit(), start().
- You should start to use #property strict.
- You should create objects in OnInit().
- Then you just change color and text in the loop OnCalculate()
- This indicator has no sense on metals, indexes...
See the updated code as an example:
i need only color change in fraction lable plz
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Hi, I created this price ticker as I wanted to use the Market Watch prices and to reduce the quote to one less decimal place but still see the fractional element. It works great but the only snag is the colour doesn't change. What have a i missed? Thanks in advance.