Da sich keiner so richtig an das Thema heranzutrauen scheint (vielleicht wird aber auch nur mehr Eigeninitiative erwartet), habe ich nunmehr versucht, die ersten Schritte alleine zu gehen:
1.Um eine sehr langwierige Kontrolle an aktuellen Trades zu umgehen, wurde vorerst alles etwas vereinfacht: als Time_1 und Time _2 wurden extern einstellbare, fixe Zeiten deklariert und Price_1 mit „Open" / Price_2 mit „Close" vorgegeben.
2. So dann: Create Rectangle - mit Time_1 und Price_1 bzw. Time_2 und Price_2 für die notwendigen Koordinaten.
3. Fast analog dann: Create Text - mit Open_Price und Close_Price.
Bis alles wunschgemäß funktionierte, war ich mehrmals der Verzweiflung nahe: - dennoch kann sich das erreichte (Zwischen-) Ergebnis erst einmal sehen lassen (siehe Picture im Angang).
Und hier der entsprechende, komplette Code:
Code:
#property indicator_chart_window
//--- parameter timezones------------------------------------------------+
extern int NumberOfDays = 1;
extern string TimeOpen = "02:52";
extern string TimeClose = "03:21";
extern color LossesCLR = Maroon;
//extern color ProfitCLR = DarkGreen;
extern bool ShowPrice = True;
extern color clFont = Silver;
extern int SizeFont = 9;
extern int OffSet = 10;
//+--- initialization TimeFunction -------------------------------------+
void init() {
DeleteObjects();
for (int i=0; i<NumberOfDays; i++) {
CreateObjects("ST_1"+i, LossesCLR); // "ST_1" = ShortTrade_1
}
Comment("");
}
//+--- deinitialization TimeFunction -----------------------------------+
void deinit() {
DeleteObjects();
Comment("");
}
//+--- create object ----------------------------------------------------+
void CreateObjects(string no, color cl) {
ObjectCreate(no, OBJ_RECTANGLE,0, 0,0, 0,0);
ObjectSet(no, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet(no, OBJPROP_COLOR, LossesCLR);
ObjectSet(no, OBJPROP_BACK, True);
}
//+--- object delate ----------------------------------------------------+
void DeleteObjects() {
for (int i=0; i<NumberOfDays; i++) {
ObjectDelete("ST_1"+i);
}
ObjectDelete("ST_1up"); // NEU
ObjectDelete("ST_1dn"); // NEU
}
//+--- interation function ----------------------------------------------+
void start() {
datetime dt=CurTime();
for (int i=0; i<NumberOfDays; i++){
if (ShowPrice && i==0) {
DrawPrices(dt,"ST_1",TimeOpen,TimeClose);
}
DrawObjects(dt, "ST_1"+i,TimeOpen,TimeClose);
}
}
//+--- draw objects -----------------------------------------------------+
void DrawObjects(datetime dt, string no, string tb, string te)
{
datetime t1, t2;
double p1, p2;
int b1, b2;
t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb);
t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te);
b1=iBarShift(NULL, 0, t1);
b2=iBarShift(NULL, 0, t2);
p1=Open[b1];
p2=Close[b2];
ObjectSet(no, OBJPROP_TIME1 , t1);
ObjectSet(no, OBJPROP_PRICE1, p1);
ObjectSet(no, OBJPROP_TIME2 , t2);
ObjectSet(no, OBJPROP_PRICE2, p2);
}
//+--- draw prices -------------------------------------------------------+
void DrawPrices(datetime dt, string no, string tb, string te) {
datetime t1, t2;
double p1, p2;
int b1, b2;
t1=StrToTime(TimeToStr(dt, TIME_DATE)+" "+tb);
t2=StrToTime(TimeToStr(dt, TIME_DATE)+" "+te);
b1=iBarShift(NULL, 0, t1);
b2=iBarShift(NULL, 0, t2);
//p1=High[Highest(NULL, 0, MODE_HIGH, b1-b2, b2)];
p1=Open[b1];
//p2=Low [Lowest (NULL, 0, MODE_LOW , b1-b2, b2)];
p2=Close[b2];
//+--- obere Price-Angabe
if (ObjectFind(no+"up")<0) ObjectCreate(no+"up", OBJ_TEXT, 0, 0,0);
ObjectSet(no+"up", OBJPROP_TIME1 , t2);
ObjectSet(no+"up", OBJPROP_PRICE1 , p1+OffSet*Point);
ObjectSet(no+"up", OBJPROP_COLOR , clFont);
ObjectSet(no+"up", OBJPROP_FONTSIZE, SizeFont);
ObjectSetText(no+"up", DoubleToStr(p1, Digits));// p1"+Ask-Bid" entnommen / jetzt Price-Angaben = ok.
//+--- untere Price-Angabe
if (ObjectFind(no+"dn")<0) ObjectCreate(no+"dn", OBJ_TEXT, 0, 0,0);
ObjectSet(no+"dn", OBJPROP_TIME1 , t2);
ObjectSet(no+"dn", OBJPROP_PRICE1 , p2);
ObjectSet(no+"dn", OBJPROP_COLOR , clFont);
ObjectSet(no+"dn", OBJPROP_FONTSIZE, SizeFont);
ObjectSetText(no+"dn", DoubleToStr(p2, Digits));
}
//+----------------------------------------------------------------------+
Kann der o.a. Code einfacher, ggf. ev. auch eleganter, programmiert werden? Ist diese Programmierung überhaupt sinnvoll, wenn der vollendete Indikator nach Long- oder ShortOrder unterscheiden und dementsprechend nur noch eine Ziffer (Loss oder Profit) darstellen soll?
And but last not least: Wo muß ich jetzt für die Unterscheidung Long-/ShortOrder ansetzten und wie realisiere ich die Loss-/Profit Darstellung am besten?
Ohne Eure Unterstützung komme ich hier wahrscheinlich nicht weiter, so dass ich mich riesig über eine helfende Hand freuen würde. Hierfür schon `mal ein kleines Dankeschön.
LG: piptrade