Why is my text doubled?

Questions about MultiCharts and user contributed studies.
olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Why is my text doubled?

Postby olobay » 22 Sep 2012

I don't understand why I am getting doubled text like in the attachment. Code is posted below.

Code: Select all

Inputs: StartTime(0830),
    EndTime(915),
    yHigh(93.09),
    yLow(90.96),
    yClose(92.96),
    yHighLow_Color(darkgray),
    yHighLow_Style(3),
    yHighLow_LineSize(2),
    yClose_Color(darkred),
    yCLose_Style(3),
    yClose_LineSize(2),
    IB_Color(Red),
    IB_Style(2), 
    IB_LineSize(0),
    A_Color(Red),
    A_Style(2), 
    A_LineSize(0),
    C_Color(Cyan),
    C_Style(3), 
    C_LineSize(1),
    PP_Color(yellow),
    PP_Style(2), 
    PP_LineSize(1),
    TodayOnly(True);

vars:  DPP(0), PV(0), PVR(0),
   HighDay(0),
   LowDay(0),
   RangeToday(0),
   LineId1(-1),
   LineId2(-1),
   LineId3(-1),
   LineId4(-1),
   LineId5(-1),
   LineId6(-1),
   LineId7(-1),
   LineId8(-1),
   LineId9(-1),
   LineId10(-1),
   LineId11(-1),
   LineId12(-1),
   LineId13(-1), 
   ID1(-1),
   ID2(-1),
   ID3(-1),
   ID4(-1),
   ID5(-1),
   ID6(-1),
   ID7(-1),
   ID8(-1),
   ID9(-1),
   ID10(-1),
   ID11(-1),
   ID12(-1),
   ID13(-1);

If Date <> Date[1] Then Begin      // Initialize vars at max of ranges
   HighDay = 0;
   LowDay = 99999;
End;
 
If Time >= StartTime and Time <= EndTime Then Begin
   // Get the high and low from the start time to end time
   If H > HighDay Then HighDay = H;
   If L < LowDay Then LowDay = L;
End;
 
If Time >= EndTime Then Begin
   RangeToday = HighDay - LowDay;
   // Draw the High line
   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then TL_Delete(LineId1);
   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then Text_Delete(LineId1);
   If TodayOnly then LineId1 = ID1;
   ID1 = TL_New(Date, StartTime, HighDay, Date, Time, HighDay);
   If TodayOnly then Value1 = TL_SetExtRight(ID1, True);    
   Value1= TL_SetColor(ID1, IB_Color);
   Value1= TL_SetStyle(ID1, IB_Style);
   Value1= TL_SetSize(ID1, IB_LineSize);   
   value1= Text_New(Date, Time + 50, HighDay, "OR  High");
   value1= Text_SetStyle(ID1, 0, 1);   
   value1= Text_SetColor(ID1, IB_Color);
 
   // Draw the Low Line
   If TodayOnly and LineId2 <> -1 and LineId2 <> ID2 Then TL_Delete(LineId2);
   If TodayOnly and LineId2 <> -1 and LineId2 <> ID2 Then Text_Delete(LineId2); 
   If TodayOnly Then LineId2 = Id2;
   ID2 = TL_New(Date, StartTime, LowDay, Date, Time, LowDay);
   If TodayOnly then Value1 = TL_SetExtRight(ID2, True);
   Value2= TL_SetColor(ID2, IB_Color);
   Value2= TL_SetStyle(ID2, IB_Style);
   Value2= TL_SetSize(ID2, IB_LineSize);
   value2= Text_New(Date, Time + 50, LowDay, "OR  Low");
   value2= Text_SetStyle(ID2, 0, 1);   
   value2= Text_SetColor(ID2, IB_Color);
 
   
   //Draw A Up Line
   If TodayOnly and LineId3 <> -1 and LineId3 <> ID3 Then TL_Delete(LineId3);
   If TodayOnly and LineId3 <> -1 and LineId3 <> ID3 Then Text_Delete(LineId3);
   If TodayOnly then LineId3 = ID3;
   ID3 = TL_New(Date, StartTime, HighDay + .08, Date, Time, HighDay + .08);
   If TodayOnly then Value1 = TL_SetExtRight(ID3, True);    
   value3= TL_SetColor(ID3, A_Color);
   value3= TL_SetStyle(ID3, A_Style);
   value3= TL_SetSize(ID3, A_LineSize);
   value3= Text_New(Date, Time + 50, HighDay + .08, "A  Up");
   value3= Text_SetStyle(ID3, 0, 1);   
   value3= Text_SetColor(ID3, IB_Color);
    
   
   // Draw A Down Line
   If TodayOnly and LineId4 <> -1 and LineId4 <> ID4 Then TL_Delete(LineId4);
   If TodayOnly and LineId4 <> -1 and LineId4 <> ID4 Then Text_Delete(LineId4);
   If TodayOnly Then LineId4 = Id4;
   ID4 = TL_New(Date, StartTime, LowDay - .08, Date, Time, LowDay - .08);
   If TodayOnly then Value1 = TL_SetExtRight(ID4, True);
   value4= TL_SetColor(ID4, A_Color);
   value4= TL_SetStyle(ID4, A_Style);
   value4= TL_SetSize(ID4, A_LineSize);
   value4= Text_New(Date, Time + 50, LowDay - .08, "A  Down");
   value4= Text_SetStyle(ID4, 0, 1);   
   value4= Text_SetColor(ID4, IB_Color);
   
   //Draw C Up Line
   If TodayOnly and LineId5 <> -1 and LineId5 <> ID5 Then TL_Delete(LineId5);
   If TodayOnly and LineId5 <> -1 and LineId5 <> ID5 Then Text_Delete(LineId5);
   If TodayOnly then LineId5 = ID5;
   ID5 = TL_New(Date, StartTime, HighDay + .13, Date, Time, HighDay + .13);
   If TodayOnly then Value1 = TL_SetExtRight(ID5, True);    
   value5= TL_SetColor(ID5, C_Color);
   value5= TL_SetStyle(ID5, C_Style);
   value5= TL_SetSize(ID5, C_LineSize);
   value5= Text_New(Date, Time + 50, HighDay + .13, "C  Up");
   value5= Text_SetStyle(ID5, 0, 1);   
   value5= Text_SetColor(ID5, C_Color);    
   
   // Draw C Down Line
   If TodayOnly and LineId6 <> -1 and LineId6 <> ID6 Then TL_Delete(LineId6);
   If TodayOnly and LineId6 <> -1 and LineId6 <> ID6 Then Text_Delete(LineId6); 
   If TodayOnly Then LineId6 = Id6;
   ID6 = TL_New(Date, StartTime, LowDay - .13, Date, Time, LowDay - .13);
   If TodayOnly then Value1 = TL_SetExtRight(ID6, True);
   value6= TL_SetColor(ID6, C_Color);
   value6= TL_SetStyle(ID6, C_Style);
   value6= TL_SetSize(ID6, C_LineSize);
   value6= Text_New(Date, Time + 50, LowDay - .13, "C  Down");
   value6= Text_SetStyle(ID6, 0, 1);   
   value6= Text_SetColor(ID6, C_Color);

DPP = (yHigh + yLow + yClose ) /3; //Daily Pivot Point

   //Draw Daily Pivot Point Line
   If TodayOnly and LineId7 <> -1 and LineId7 <> ID7 Then TL_Delete(LineId7);
   If TodayOnly and LineId7 <> -1 and LineId7 <> ID7 Then Text_Delete(LineId7);
   If TodayOnly then LineId7 = ID7;
   ID7 = TL_New(Date, StartTime, DPP, Date, Time, DPP);
   If TodayOnly then Value1 = TL_SetExtRight(ID7, True);    
   value7= TL_SetColor(ID7, PP_Color);
   value7= TL_SetStyle(ID7, PP_Style);
   value7= TL_SetSize(ID7, PP_LineSize);
   value7= Text_New(Date, Time + 50, DPP, "DPP");
   value7= Text_SetStyle(ID7, 0, 1);   
   value7= Text_SetColor(ID7, PP_Color);
   
PV = (yHigh + yLow) /2;
PVR = (DPP - PV); //Pivot Range Value

   //Draw Pivot Range High Line
   If TodayOnly and LineId8 <> -1 and LineId8 <> ID8 Then TL_Delete(LineId8);
   If TodayOnly and LineId8 <> -1 and LineId8 <> ID8 Then Text_Delete(LineId8); 
   If TodayOnly then LineId8 = ID8;
   ID8 = TL_New(Date, StartTime, DPP + PVR, Date, Time, DPP + PVR);
   If TodayOnly then Value1 = TL_SetExtRight(ID8, True);    
   value8= TL_SetColor(ID8, PP_Color);
   value8= TL_SetStyle(ID8, PP_Style);
   value8= TL_SetSize(ID8, PP_LineSize);
   value8= Text_New(Date, Time + 50, DPP + PVR, "PVR  High");
   value8= Text_SetStyle(ID8, 0, 1);   
   value8= Text_SetColor(ID8, PP_Color);
   
   //Draw Pivot Range Low Line
   If TodayOnly and LineId9 <> -1 and LineId9 <> ID9 Then TL_Delete(LineId9);
   If TodayOnly and LineId9 <> -1 and LineId9 <> ID9 Then Text_Delete(LineId9); 
   If TodayOnly then LineId9 = ID9;
   ID9 = TL_New(Date, StartTime, DPP - PVR, Date, Time, DPP - PVR);
   If TodayOnly then Value1 = TL_SetExtRight(ID9, True);    
   value9= TL_SetColor(ID9, PP_Color);
   value9= TL_SetStyle(ID9, PP_Style);
   value9= TL_SetSize(ID9, PP_LineSize);
   value9= Text_New(Date, Time + 50, DPP - PVR, "PVR  Low");
   value9= Text_SetStyle(ID9, 0, 1);   
   value9= Text_SetColor(ID9, PP_Color);
   
   
   //Draw yHigh Line
   If TodayOnly and LineId10 <> -1 and LineId10 <> ID10 Then TL_Delete(LineId10);
   If TodayOnly and LineId10 <> -1 and LineId10 <> ID10 Then Text_Delete(LineId10);
   If TodayOnly then LineId10 = ID10;
   ID10 = TL_New(Date, StartTime, yHigh, Date, Time, yHigh);
   If TodayOnly then Value1 = TL_SetExtRight(ID10, True);    
   value10= TL_SetColor(ID10, yHighLow_Color);
   value10= TL_SetStyle(ID10, yHighLow_Style);
   value10= TL_SetSize(ID10, yHighLow_LineSize);
   value10= Text_New(Date, Time + 50, yHigh, "Y  High");
   value10= Text_SetStyle(ID10, 0, 1);   
   value10= Text_SetColor(ID10, yHighLow_Color);
   
   //Draw yLow Line
   If TodayOnly and LineId11 <> -1 and LineId11 <> ID11 Then TL_Delete(LineId11);
   If TodayOnly and LineId11 <> -1 and LineId11 <> ID11 Then Text_Delete(LineId11);
   If TodayOnly then LineId11 = ID11;
   ID11 = TL_New(Date, StartTime, yLow, Date, Time, yLow);
   If TodayOnly then Value1 = TL_SetExtRight(ID11, True);    
   value11= TL_SetColor(ID11, yHighLow_Color);
   value11= TL_SetStyle(ID11, yHighLow_Style);
   value11= TL_SetSize(ID11, yHighLow_LineSize);
   value11= Text_New(Date, Time + 50, yLow, "Y  Low");
   value11= Text_SetStyle(ID11, 0, 1);   
   value11= Text_SetColor(ID11, yHighLow_Color);
   
   //Draw yClose Line
   If TodayOnly and LineId12 <> -1 and LineId12 <> ID12 Then TL_Delete(LineId12);
   If TodayOnly and LineId12 <> -1 and LineId12 <> ID12 Then Text_Delete(LineId12);
   If TodayOnly then LineId12 = ID12;
   ID12 = TL_New(Date, StartTime, yClose, Date, Time, yClose);
   If TodayOnly then Value1 = TL_SetExtRight(ID12, True);    
   value12= TL_SetColor(ID12, yClose_Color);
   value12= TL_SetStyle(ID12, yClose_Style);
   value12= TL_SetSize(ID12, yClose_LineSize);
   value12= Text_New(Date, Time + 50, yClose, "Y  Close");
   value12= Text_SetStyle(ID12, 0, 1);   
   value12= Text_SetColor(ID12, yClose_Color);


End;
Attachments
double text.png
double text.png (9.79 KiB) Viewed 353 times

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 22 Sep 2012

olobay wrote:I don't understand why I am getting doubled text like in the attachment. Code is posted below.
...


You are learning fast and trying hard. Good going!

Take a look at this example.
This code is by a professional programmer, there are lots to learn here.

http://www.tradersxchange.com/viewtopic ... =576&p=347

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 22 Sep 2012

Thanks for the encouragement but all I did was find some code and then modify it to suit my needs. I understand what the code in the link is doing but it seems to be doing the same thing as my code. He sets a trend line and then sets text and plots the style and location. I can't really see where his code is doing something mine is not and yet his plots text only once. I might need some more hints on this one TJ. Except maybe that I don't need to declare a value every time I set a TL or TEXT?

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 22 Sep 2012

olobay wrote:Thanks for the encouragement but all I did was find some code and then modify it to suit my needs. I understand what the code in the link is doing but it seems to be doing the same thing as my code. He sets a trend line and then sets text and plots the style and location. I can't really see where his code is doing something mine is not and yet his plots text only once. I might need some more hints on this one TJ. Except maybe that I don't need to declare a value every time I set a TL or TEXT?


pay attention to the keywords with "SetLocation".
These users thanked the author TJ for the post:
olobay

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 22 Sep 2012

Start reading; there is no short cut.

The essential EasyLanguage programming guide
Creating a Text Object ....pg. 112
Moving a Text Object .... pg. 113


https://www.multicharts.com/multicharts/ ... mentation/
These users thanked the author TJ for the post (total 2):
olobayJoshM

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

Thanks for the links. I didn't that documentation existed. I've applied the Text_SetLocation to my code but it still prints twice. I checked the format drawings and I also see that each trendline is being printed twice. Will it keep printing a trendline and text every time a bar is completed? If so, that would use a lot of ressources wouldn't it? I saw in the TradersExchange link, that his code only prints 1 line and 1 text object per formula. Is it something in his IF Time or IF Date formula that I need to do the same for my code?

Code: Select all

Inputs: StartTime(0830),
    EndTime(0915),
    yHigh(93.09),
    yLow(90.96),
    yClose(92.96),
    yHighLow_Color(darkgray),
    yHighLow_Style(3),
    yHighLow_LineSize(2),
    yClose_Color(darkred),
    yCLose_Style(3),
    yClose_LineSize(2),
    IB_Color(Red),
    IB_Style(2), 
    IB_LineSize(0),
    A_Color(Red),
    A_Style(2), 
    A_LineSize(0),
    C_Color(Cyan),
    C_Style(3), 
    C_LineSize(1),
    PP_Color(yellow),
    PP_Style(2), 
    PP_LineSize(1),
    Font_Name("Arial"),
    Font_Size(9),
    Text_Offset(40),
    TodayOnly(True);

vars:  DPP(0), PV(0), PVR(0),
   HighDay(0),
   LowDay(0),
   RangeToday(0),
   LineId1(-1),
   LineId2(-1),
   LineId3(-1),
   LineId4(-1),
   LineId5(-1),
   LineId6(-1),
   LineId7(-1),
   LineId8(-1),
   LineId9(-1),
   LineId10(-1),
   LineId11(-1),
   LineId12(-1),
   ID1(-1),
   ID2(-1),
   ID3(-1),
   ID4(-1),
   ID5(-1),
   ID6(-1),
   ID7(-1),
   ID8(-1),
   ID9(-1),
   ID10(-1),
   ID11(-1),
   ID12(-1);

If Date <> Date[1] Then Begin      // Initialize vars at max of ranges
   HighDay = 0;
   LowDay = 99999;
End;
 
If Time >= StartTime and Time <= EndTime Then Begin
   // Get the high and low from the start time to end time
   If H > HighDay Then HighDay = H;
   If L < LowDay Then LowDay = L;
End;
 
If Time >= EndTime Then Begin
   RangeToday = HighDay - LowDay;
   // Draw the OR High line
   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then TL_Delete(LineId1);
   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then Text_Delete(LineId1);
   If TodayOnly then LineId1 = ID1;
   ID1 = TL_New(Date, StartTime, HighDay, Date, Time, HighDay);
   //If TodayOnly then Value1 = TL_SetExtRight(ID1, True);    
   TL_SetEnd(ID1, Date, Time + Text_Offset, HighDay);
   TL_SetColor(ID1, IB_Color);
   TL_SetStyle(ID1, IB_Style);
   TL_SetSize(ID1, IB_LineSize);   
   Text_New(Date, Time + Text_Offset, HighDay, "OR  High");
   Text_SetStyle(ID1, 0, 1);   
   Text_SetColor(ID1, IB_Color);
   Text_SetFontName(ID1, Font_Name);
   Text_SetSize(ID1, Font_Size);
   Text_SetLocation(ID1, Date, Time + Text_Offset, HighDay);
 
   // Draw the OR Low Line
   If TodayOnly and LineId2 <> -1 and LineId2 <> ID2 Then TL_Delete(LineId2);
   If TodayOnly and LineId2 <> -1 and LineId2 <> ID2 Then Text_Delete(LineId2); 
   If TodayOnly Then LineId2 = Id2;
   ID2 = TL_New(Date, StartTime, LowDay, Date, Time, LowDay);
   //If TodayOnly then Value1 = TL_SetExtRight(ID2, True);
   TL_SetEnd(ID2, Date, Time + Text_Offset, LowDay);
   TL_SetColor(ID2, IB_Color);
   TL_SetStyle(ID2, IB_Style);
   TL_SetSize(ID2, IB_LineSize);
   Text_New(Date, Time + Text_Offset, LowDay, "OR  Low");
   Text_SetStyle(ID2, 0, 1);   
   Text_SetColor(ID2, IB_Color);
   Text_SetFontName(ID2, Font_Name);
   Text_SetSize(ID2, Font_Size);
   Text_SetLocation(ID2, Date, Time + Text_Offset, LowDay);   
   
   //Draw A Up Line
   If TodayOnly and LineId3 <> -1 and LineId3 <> ID3 Then TL_Delete(LineId3);
   If TodayOnly and LineId3 <> -1 and LineId3 <> ID3 Then Text_Delete(LineId3);
   If TodayOnly then LineId3 = ID3;
   ID3 = TL_New(Date, StartTime, HighDay + .08, Date, Time, HighDay + .08);
   //If TodayOnly then Value1 = TL_SetExtRight(ID3, True);    
   TL_SetEnd(ID3, Date, Time + Text_Offset, HighDay + .08);
   TL_SetColor(ID3, A_Color);
   TL_SetStyle(ID3, A_Style);
   TL_SetSize(ID3, A_LineSize);
   Text_New(Date, Time + Text_Offset, HighDay + .08, "A  Up");
   Text_SetStyle(ID3, 0, 1);   
   Text_SetColor(ID3, IB_Color);
   Text_SetFontName(ID3, Font_Name);
   Text_SetSize(ID3, Font_Size);
   Text_SetLocation(ID3, Date, Time + Text_Offset, HighDay + .08);
   Text_SetLocation(ID3, Date, Time + Text_Offset, HighDay + .08);
   
   // Draw A Down Line
   If TodayOnly and LineId4 <> -1 and LineId4 <> ID4 Then TL_Delete(LineId4);
   If TodayOnly and LineId4 <> -1 and LineId4 <> ID4 Then Text_Delete(LineId4);
   If TodayOnly Then LineId4 = Id4;
   ID4 = TL_New(Date, StartTime, LowDay - .08, Date, Time, LowDay - .08);
   //If TodayOnly then Value1 = TL_SetExtRight(ID4, True);
   TL_SetEnd(ID4, Date, Time + Text_Offset, LowDay - .08);
   TL_SetColor(ID4, A_Color);
   TL_SetStyle(ID4, A_Style);
   TL_SetSize(ID4, A_LineSize);
   Text_New(Date, Time + Text_Offset, LowDay - .08, "A  Down");
   Text_SetStyle(ID4, 0, 1);   
   Text_SetColor(ID4, IB_Color);
   Text_SetFontName(ID4, Font_Name);
   Text_SetSize(ID4, Font_Size);
   Text_SetLocation(ID4, Date, Time + Text_Offset, LowDay - .08);
   
   //Draw C Up Line
   If TodayOnly and LineId5 <> -1 and LineId5 <> ID5 Then TL_Delete(LineId5);
   If TodayOnly and LineId5 <> -1 and LineId5 <> ID5 Then Text_Delete(LineId5);
   If TodayOnly then LineId5 = ID5;
   ID5 = TL_New(Date, StartTime, HighDay + .13, Date, Time, HighDay + .13);
   //If TodayOnly then Value1 = TL_SetExtRight(ID5, True);    
   TL_SetEnd(ID5, Date, Time + Text_Offset, HighDay + .13);
   TL_SetColor(ID5, C_Color);
   TL_SetStyle(ID5, C_Style);
   TL_SetSize(ID5, C_LineSize);
   Text_New(Date, Time + Text_Offset, HighDay + .13, "C  Up");
   Text_SetStyle(ID5, 0, 1);   
   Text_SetColor(ID5, C_Color);
   Text_SetFontName(ID5, Font_Name);   
   Text_SetSize(ID5, Font_Size);
   Text_SetLocation(ID5, Date, Time + Text_Offset, HighDay + .13);

   // Draw C Down Line
   If TodayOnly and LineId6 <> -1 and LineId6 <> ID6 Then TL_Delete(LineId6);
   If TodayOnly and LineId6 <> -1 and LineId6 <> ID6 Then Text_Delete(LineId6); 
   If TodayOnly Then LineId6 = Id6;
   ID6 = TL_New(Date, StartTime, LowDay - .13, Date, Time, LowDay - .13);
   //If TodayOnly then Value1 = TL_SetExtRight(ID6, True);
   TL_SetEnd(ID6, Date, Time + Text_Offset, LowDay - .13);
   TL_SetColor(ID6, C_Color);
   TL_SetStyle(ID6, C_Style);
   TL_SetSize(ID6, C_LineSize);
   Text_New(Date, Time + Text_Offset, LowDay - .13, "C  Down");
   Text_SetStyle(ID6, 0, 1);   
   Text_SetColor(ID6, C_Color);
   Text_SetFontName(ID6, Font_Name);
   Text_SetSize(ID6, Font_Size);
   Text_SetLocation(ID6, Date, Time + Text_Offset, LowDay - .13);   

DPP = (yHigh + yLow + yClose ) /3; //Daily Pivot Point

   //Draw Daily Pivot Point Line
   If TodayOnly and LineId7 <> -1 and LineId7 <> ID7 Then TL_Delete(LineId7);
   If TodayOnly and LineId7 <> -1 and LineId7 <> ID7 Then Text_Delete(LineId7);
   If TodayOnly then LineId7 = ID7;
   ID7 = TL_New(Date, StartTime, DPP, Date, Time, DPP);
   //If TodayOnly then Value1 = TL_SetExtRight(ID7, True);    
   TL_SetEnd(ID7, Date, Time + Text_Offset, DPP);
   TL_SetColor(ID7, PP_Color);
   TL_SetStyle(ID7, PP_Style);
   TL_SetSize(ID7, PP_LineSize);
   Text_New(Date, Time + Text_Offset, DPP, "DPP");
   Text_SetStyle(ID7, 0, 1);   
   Text_SetColor(ID7, PP_Color);
   Text_SetFontName(ID7, Font_Name);
   Text_SetSize(ID7, Font_Size);
   Text_SetLocation(ID7, Date, Time + Text_Offset, DPP);

PV = (yHigh + yLow) /2;
PVR = (DPP - PV); //Pivot Range Value

   //Draw Pivot Range High Line
   If TodayOnly and LineId8 <> -1 and LineId8 <> ID8 Then TL_Delete(LineId8);
   If TodayOnly and LineId8 <> -1 and LineId8 <> ID8 Then Text_Delete(LineId8); 
   If TodayOnly then LineId8 = ID8;
   ID8 = TL_New(Date, StartTime, DPP + PVR, Date, Time, DPP + PVR);
   //If TodayOnly then Value1 = TL_SetExtRight(ID8, True);    
   TL_SetEnd(ID8, Date, Time + Text_Offset, DPP + PVR);
   TL_SetColor(ID8, PP_Color);
   TL_SetStyle(ID8, PP_Style);
   TL_SetSize(ID8, PP_LineSize);
   Text_New(Date, Time + Text_Offset, DPP + PVR, "PVR  High");
   Text_SetStyle(ID8, 0, 1);   
   Text_SetColor(ID8, PP_Color);
   Text_SetFontName(ID8, Font_Name);
   Text_SetSize(ID8, Font_Size);
   Text_SetLocation(ID8, Date, Time + Text_Offset, DPP + PVR);
   
   //Draw Pivot Range Low Line
   If TodayOnly and LineId9 <> -1 and LineId9 <> ID9 Then TL_Delete(LineId9);
   If TodayOnly and LineId9 <> -1 and LineId9 <> ID9 Then Text_Delete(LineId9); 
   If TodayOnly then LineId9 = ID9;
   ID9 = TL_New(Date, StartTime, DPP - PVR, Date, Time, DPP - PVR);
   //If TodayOnly then Value1 = TL_SetExtRight(ID9, True);    
   TL_SetEnd(ID9, Date, Time + Text_Offset, DPP - PVR);
   TL_SetColor(ID9, PP_Color);
   TL_SetStyle(ID9, PP_Style);
   TL_SetSize(ID9, PP_LineSize);
   Text_New(Date, Time + Text_Offset, DPP - PVR, "PVR  Low");
   Text_SetStyle(ID9, 0, 1);   
   Text_SetColor(ID9, PP_Color);
   Text_SetFontName(ID9, Font_Name);
   Text_SetSize(ID9, Font_Size);
   Text_SetLocation(ID9, Date, Time + Text_Offset, DPP - PVR);
   
   //Draw yHigh Line
   If TodayOnly and LineId10 <> -1 and LineId10 <> ID10 Then TL_Delete(LineId10);
   If TodayOnly and LineId10 <> -1 and LineId10 <> ID10 Then Text_Delete(LineId10);
   If TodayOnly then LineId10 = ID10;
   ID10 = TL_New(Date, StartTime, yHigh, Date, Time, yHigh);
   //If TodayOnly then Value1 = TL_SetExtRight(ID10, True);    
   TL_SetEnd(ID10, Date, Time + Text_Offset, yHigh);
   TL_SetColor(ID10, yHighLow_Color);
   TL_SetStyle(ID10, yHighLow_Style);
   TL_SetSize(ID10, yHighLow_LineSize);
   Text_New(Date, Time + Text_Offset, yHigh, "Y  High");
   Text_SetStyle(ID10, 0, 1);   
   Text_SetColor(ID10, yHighLow_Color);
   Text_SetFontName(ID10, Font_Name);
   Text_SetSize(ID10, Font_Size);
   Text_SetLocation(ID10, Date, Time + Text_Offset, yHigh);
   
   //Draw yLow Line
   If TodayOnly and LineId11 <> -1 and LineId11 <> ID11 Then TL_Delete(LineId11);
   If TodayOnly and LineId11 <> -1 and LineId11 <> ID11 Then Text_Delete(LineId11);
   If TodayOnly then LineId11 = ID11;
   ID11 = TL_New(Date, StartTime, yLow, Date, Time, yLow);
   //If TodayOnly then Value1 = TL_SetExtRight(ID11, True);    
   TL_SetEnd(ID11, Date, Time + Text_Offset, yLow);
   TL_SetColor(ID11, yHighLow_Color);
   TL_SetStyle(ID11, yHighLow_Style);
   TL_SetSize(ID11, yHighLow_LineSize);
   Text_New(Date, Time + Text_Offset, yLow, "Y  Low");
   Text_SetStyle(ID11, 0, 1);   
   Text_SetColor(ID11, yHighLow_Color);
   Text_SetFontName(ID11, Font_Name);
   Text_SetSize(ID11, Font_Size);
   Text_SetLocation(ID11, Date, Time + Text_Offset, yLow);
   
   //Draw yClose Line
   If TodayOnly and LineId12 <> -1 and LineId12 <> ID12 Then TL_Delete(LineId12);
   If TodayOnly and LineId12 <> -1 and LineId12 <> ID12 Then Text_Delete(LineId12);
   If TodayOnly then LineId12 = ID12;
   ID12 = TL_New(Date, StartTime, yClose, Date, Time, yClose);
   //If TodayOnly then Value1 = TL_SetExtRight(ID12, True);    
   TL_SetEnd(ID12, Date, Time + Text_Offset, yClose);
   TL_SetColor(ID12, yClose_Color);
   TL_SetStyle(ID12, yClose_Style);
   TL_SetSize(ID12, yClose_LineSize);
   Text_New(Date, Time + Text_Offset, yClose, "Y  Close");
   Text_SetStyle(ID12, 0, 1);   
   Text_SetColor(ID12, yClose_Color);
   Text_SetFontName(ID12, Font_Name);
   Text_SetSize(ID12, Font_Size);
   Text_SetLocation(ID12, Date, Time + Text_Offset, yClose);

End;
Attachments
v2.png
v2.png (13.16 KiB) Viewed 343 times

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 23 Sep 2012

olobay wrote:Thanks for the links. I didn't that documentation existed. I've applied the Text_SetLocation to my code but it still prints twice. I checked the format drawings and I also see that each trendline is being printed twice. Will it keep printing a trendline and text every time a bar is completed? If so, that would use a lot of ressources wouldn't it? I saw in the TradersExchange link, that his code only prints 1 line and 1 text object per formula. Is it something in his IF Time or IF Date formula that I need to do the same for my code?
...


What he did was to create the text once...
then move it around as needed.

Remember, MultiCharts re-evaluates your logic EVERY BAR, and re-executes your command, in accordance with your instruction (your code).
According to your logic, not only you will get double text, with live data, you will get a new text at the end of every bar (or tick) !
These users thanked the author TJ for the post:
olobay

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

Thanks for the help TJ. I understand I need a conditional statement so that my trendline and text is only created once but I can't even think in English what type of statement I need. I suppose what I want is that once Time equals my StartTime then start drawing the TL and Text but just keep extending it as Time continues but I have no idea how to code that. I've tried a few things but they have not worked.

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

Do I need to go back and assign a value to the TL and Text objects like in the following:

Code: Select all

   // Draw the OR Low Line
   If TodayOnly and LineId2 <> -1 and LineId2 <> ID2 Then TL_Delete(LineId2);
   If TodayOnly and LineId2 <> -1 and LineId2 <> ID2 Then Text_Delete(LineId2); 
   If TodayOnly Then LineId2 = Id2;
   ID2 = TL_New(Date, StartTime, LowDay, Date, Time, LowDay);
   //If TodayOnly then Value1 = TL_SetExtRight(ID2, True);
   value2= TL_SetEnd(ID2, Date, Time + Text_Offset, LowDay);
   value2= TL_SetColor(ID2, IB_Color);
   value2= TL_SetStyle(ID2, IB_Style);
   value2= TL_SetSize(ID2, IB_LineSize);
   value2= Text_New(Date, Time + Text_Offset, LowDay, "OR  Low");
   value2= Text_SetStyle(ID2, 0, 1);   
   value2= Text_SetColor(ID2, IB_Color);
   value2= Text_SetFontName(ID2, Font_Name);
   value2= Text_SetSize(ID2, Font_Size);
   value2= Text_SetLocation(ID2, Date, Time + Text_Offset, LowDay);

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

I'm watching the indicator update realtime and it is drawing 2 trendlines and 2 text objects.

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 23 Sep 2012

olobay wrote:Thanks for the help TJ. I understand I need a conditional statement so that my trendline and text is only created once but I can't even think in English what type of statement I need. I suppose what I want is that once Time equals my StartTime then start drawing the TL and Text but just keep extending it as Time continues but I have no idea how to code that. I've tried a few things but they have not worked.


You don't have to think in English. Nous parlons français.

Suggestion:

Go through your code and add comments to each line.

eg.

Code: Select all

// using identification of ID2, draw a new line from D/starttime/lowday to D/thisbar/lowday.
ID2 = TL_New(Date, StartTime, LowDay, Date, Time, LowDay); 

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

I started commenting the code and when I got here I thought this might be wrong:

Code: Select all

// Draw the OR High line
   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then TL_Delete(LineId1); //this deletes all trendlines except for today's trendline if the indicator is only plotting today
   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then Text_Delete(LineId1); //this deletes all text except for today's trendline if the indicator is only plotting today
   If TodayOnly then LineId1 = ID1; //i think this assigns a value to LineID1
   ID1 = TL_New(Date, StartTime, HighDay, Date, Time, HighDay); //using ID1, starts a TL  from D/starttime/highday price to D/currentbar time/highday price
   //If TodayOnly then Value1 = TL_SetExtRight(ID1, True);    
   TL_SetEnd(ID1, Date, Time + Text_Offset, HighDay); //sets the end of the TL using ID1 from D/currentbar time + 60min/highday price
   TL_SetColor(ID1, IB_Color);
   TL_SetStyle(ID1, IB_Style);
   TL_SetSize(ID1, IB_LineSize);   
   [b]Text_New(Date, Time + Text_Offset, HighDay, "OR  High");[/b]
   Text_SetStyle(ID1, 0, 1);   
   Text_SetColor(ID1, IB_Color);
   Text_SetFontName(ID1, Font_Name);
   Text_SetSize(ID1, Font_Size);
   Text_SetLocation(ID1, Date, Time + Text_Offset, HighDay);


The bolded part of the code does not have an ID value associated with it. Should I assign a value to it? If so, does it have to be an unused value or do I assign it an ID1 because it's part of that section?

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

The bold did not show up so this is the part I meant:

TL_SetStyle(ID1, IB_Style);
TL_SetSize(ID1, IB_LineSize);
Text_New(Date, Time + Text_Offset, HighDay, "OR High");
Text_SetStyle(ID1, 0, 1);

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 23 Sep 2012

olobay wrote:TL_SetStyle(ID1, IB_Style);
TL_SetSize(ID1, IB_LineSize);
Text_New(Date, Time + Text_Offset, HighDay, "OR High");
Text_SetStyle(ID1, 0, 1);


Where did this ID1 come from ???

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 23 Sep 2012

ps. Put some space (blank lines) between codes. They are free, and makes reading easier.
These users thanked the author TJ for the post:
olobay

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

TJ wrote:Where did this ID1 come from ???


It came from this part of the code, the first TL.

Code: Select all

//using ID1, starts a TL  from D/starttime/highday price to D/currentbar time/highday price

ID1 = TL_New(Date, StartTime, HighDay, Date, Time, HighDay);


Sorry about not putting a space. I really appreciate the help.

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 23 Sep 2012

Please add comments to ALL the codes.
EVERY SINGLE LINE !
No exceptions.
If you don't know what the line is doing, delete it.


Why are we doing this exercise?

Each line of code is telling the computer to perform an action for us.
We have to know exactly WHAT we are telling the computer.

Ever heard of the term GIGO?

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

I commented everything until the first TL and Text section because after that, everything just repeats itself with only the ID numebrs changing.

Code: Select all

If Date <> Date[1] Then Begin      // Initialize vars at max of ranges If today's date is not yesterday then begin

   HighDay = 0; //sets a value for the Highday
   LowDay = 99999; //sets a value for the LowDay
End;
 
If Time >= StartTime and Time <= EndTime Then Begin //sets what time to get the High and the Low

   // Get the high and low from the start time to end time

   If H > HighDay Then HighDay = H; //this captures the HIgh during the time between starttime and endtime

   If L < LowDay Then LowDay = L; //this captures the Low during the time between starttime and endtime
End;
 
If Time >= EndTime Then Begin //Not sure what this does but it has something to do with plotting for all days instead of just today

   RangeToday = HighDay - LowDay;

   // Draw the OR High line

   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then TL_Delete(LineId1); //this deletes all trendlines except for today's trendline if the indicator is only plotting today

   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then Text_Delete(LineId1); //this deletes all text except for today's trendline if the indicator is only plotting today

   If TodayOnly then LineId1 = ID1; //sets a value of ID1 to LineID1 when TodayOnly is true

   ID1 = TL_New(Date, StartTime, HighDay, Date, Time, HighDay); //using ID1, starts a TL  from D/starttime/highday price to D/currentbar time/highday price

   //If TodayOnly then Value1 = TL_SetExtRight(ID1, True);
   
   TL_SetEnd(ID1, Date, Time + Text_Offset, HighDay); //sets the end of the TL using ID1 from D/currentbar time + 60min/highday price

   TL_SetColor(ID1, IB_Color); //sets color of ID1 to IB_Color in inputs

   TL_SetStyle(ID1, IB_Style); //sets style of ID1 to IB_style in inputs

   TL_SetSize(ID1, IB_LineSize); //sets size of ID1 to IB_LineSize in inputs

   Text_New(Date, Time + Text_Offset, HighDay, "OR  High"); //I know what this is doing but I don't know to what ID

   Text_SetStyle(ID1, 0, 1);   //sets text style of ID1 to the right of the bar and above the price value

   Text_SetColor(ID1, IB_Color); //sets text color of ID1 to IB_color in inputs

   Text_SetFontName(ID1, Font_Name); //sets the font of ID1 to Font_name in inputs

   Text_SetSize(ID1, Font_Size);//sets text size of ID1 to Font_size in inputs

   Text_SetLocation(ID1, Date, Time + Text_Offset, HighDay);//using ID1 sets the location of the text to today at the current bar plus 60mins at the HighDay price

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 23 Sep 2012

Code: Select all

Text_New(Date, Time + Text_Offset, HighDay, "OR  High");
//I know what this is doing but I don't know to what ID


see post #5

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

I already asked you a question regarding this in Post #13 but you never replied.

Should I assign a value to it? If so, does it have to be an unused value like ID13 or do I assign it ID1 because it's part of that section?

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

I did the following but it is still printing 2 texts and 2 trendlines for the OR High line.

Code: Select all

// Draw the OR High line
   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then TL_Delete(LineId1); //this deletes all trendlines except for today's trendline if the indicator is only plotting today

   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then Text_Delete(LineId1); //this deletes all text except for today's trendline if the indicator is only plotting today

   If TodayOnly then LineId1 = ID1; //sets a value of ID1 to LineID1 when TodayOnly is true

   ID1 = TL_New(Date, StartTime, HighDay, Date, Time, HighDay); //using ID1, starts a TL  from D/starttime/highday price to D/currentbar time/highday price

   //If TodayOnly then Value1 = TL_SetExtRight(ID1, True);
   
   TL_SetEnd(ID1, Date, Time + Text_Offset, HighDay); //sets the end of the TL using ID1 from D/currentbar time + 60min/highday price

   TL_SetColor(ID1, IB_Color); //sets color of ID1 to IB_Color in inputs
   TL_SetStyle(ID1, IB_Style); //sets style of ID1 to IB_style in inputs
   TL_SetSize(ID1, IB_LineSize); //sets size of ID1 to IB_LineSize in inputs

   ID13 = Text_New(Date, Time + Text_Offset, HighDay, "OR  High"); //I know what this is doing but I don't know to what ID

   Text_SetStyle(ID13, 0, 1);   //sets text style of ID1 to the right of the bar and above the price value

   Text_SetColor(ID13, IB_Color); //sets text color of ID1 to IB_color in inputs
   Text_SetFontName(ID13, Font_Name); //sets the font of ID1 to Font_name in inputs
   Text_SetSize(ID13, Font_Size);//sets text size of ID1 to Font_size in inputs

   Text_SetLocation(ID13, Date, Time + Text_Offset, HighDay);//using ID1 sets the location of the text to today at the current bar plus 60mins at the HighDay price

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

TJ wrote:
olobay wrote:I already asked you a question regarding this in Post #13 but you never replied.

Should I assign a value to it? If so, does it have to be an unused value like ID13 or do I assign it ID1 because it's part of that section?

Have you read the chapter (actually it is a paragraph) in post #5?

If you have, why do you have to ask me that question? The answer is there.


I have read it but I am still not sure that's why I ask.

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

Does it have to be a Value1 or can it be a variable that I declared like ID13?

Well I tried both and they both still print 2 text objects and 2 TL.
Last edited by olobay on 23 Sep 2012, edited 1 time in total.

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

I have read it. I know you are trying to teach me and I do appreciate it but there comes a time when a student is just not getting it, that maybe a teacher should explain what is not working in the code and why. Maybe you have done that, but obviously I am not getting it.

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 23 Sep 2012

olobay wrote:I have read it. I know you are trying to teach me and I do appreciate it but there comes a time when a student is just not getting it, that maybe a teacher should explain what is not working in the code and why. Maybe you have done that, but obviously I am not getting it.

I am not trying to teach you, I am just trying to get you to read what is needed to fix your problem.

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 23 Sep 2012

If it needs to be placed in a conditional statement I already said that what I want is that once Time equals my StartTime then start drawing the TL and Text but just keep extending it as Time continues but I have no idea how to code that.

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 23 Sep 2012

olobay wrote:I already asked you a question regarding this in Post #13 but you never replied.

Should I assign a value to it? If so, does it have to be an unused value like ID13 or do I assign it ID1 because it's part of that section?

It is required to assign the Text_New reserved word to a variable
so that the text object return ID number is captured.

By assigning the text object number to a variable,
we can reference that text object ID
in other text object related formatting and manipulating reserved words.
These users thanked the author TJ for the post:
olobay

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 24 Sep 2012

I have changed all of my TL and Text codes to the following, of course incrementing the value number, but I still get doubled text.

Code: Select all

//Draw A Up Line
   If TodayOnly and LineId3 <> -1 and LineId3 <> ID3 Then TL_Delete(LineId3);

   If TodayOnly and LineId3 <> -1 and LineId3 <> ID3 Then Text_Delete(LineId3);

   If TodayOnly then LineId3 = ID3;

   ID3 = TL_New(Date, StartTime, HighDay + A_Val, Date, Time, HighDay + A_Val);

   //If TodayOnly then Value1 = TL_SetExtRight(ID3, True);
   
   TL_SetEnd(ID3, Date, Time + Text_Offset, HighDay + A_Val);

   TL_SetColor(ID3, A_Color);
   TL_SetStyle(ID3, A_Style);
   TL_SetSize(ID3, A_LineSize);

   If TodayOnly then
   value3 = Text_New(Date, Time + Text_Offset, HighDay + A_Val, "A  Up");

   Text_SetStyle(value3, 0, 1);   
   Text_SetColor(value3, IB_Color);
   Text_SetFontName(value3, Font_Name);
   Text_SetSize(value3, Font_Size);

   Text_SetLocation(value3, Date, Time + Text_Offset, HighDay + A_Val);

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 24 Sep 2012

olobay wrote:I have changed all of my TL and Text codes to the following, of course incrementing the value number, but I still get doubled text.
...


Of course you are still getting double text.
You have multiple problems in the code, there is no magic bullet that can solve all the problem at once. You must solve them one by one. The process in post #11 is only a beginning; you have to understand what each line of the code is doing.

The first missing link in your code is the object ID. Which you have finally corrected.

For the solution to the multiple text problem, please see post #7.

Make sure when you create the text once, you do not create it again.
ie. the code does not re-cycle every bar.

See example in post #2. See how he used Text_New only once.
You have everything you needed in that code.

Good luck.

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 26 Sep 2012

The only difference I can see between my code and the one in the link in post #2 is in the conditional statements. I can't see where I am creating the TL and Text more than once. The drawing of the TL and Text seem to me, to be the same between both studies. Am I on the right track? The only difference I see is that I put all the TL and Text together in one section while he put all the TL together and then all the text.

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 26 Sep 2012

olobay wrote:The only difference I can see between my code and the one in the link in post #2 is in the conditional statements. I can't see where I am creating the TL and Text more than once. The drawing of the TL and Text seem to me, to be the same between both studies. Am I on the right track? The only difference I see is that I put all the TL and Text together in one section while he put all the TL together and then all the text.


I can't really help you much with the limited information you have provided.

What is the condition "TodayOnly"?

How many times does it execute?

Code: Select all

If TodayOnly then
   value3 = Text_New(Date, Time + Text_Offset, HighDay + A_Val, "A  Up");



Note: we are not fixing syntax now, we have passed that stage. We are looking at logic.

olobay
Posts: 43
Joined: 28 Dec 2011
Has thanked: 15 times

Re: Why is my text doubled?

Postby olobay » 26 Sep 2012

TodayOnly if true plots only lines for today. If false then plots lines for all days in the chart. Right now it is executing 3 times per TL being drawn, 12 in total: twice to delete previous days TLs and Text objects and once to assign a condition to plot today's TLs and Text objects.

Code: Select all

If Date <> Date[1] Then Begin      // Initialize vars at max of ranges
   HighDay = 0;
   LowDay = 99999;
End;
 
If Time >= StartTime and Time <= EndTime Then Begin
   // Get the high and low from the start time to end time
   If H > HighDay Then HighDay = H;
   If L < LowDay Then LowDay = L;
End;
 
If Time >= EndTime Then Begin
   RangeToday = HighDay - LowDay;
   
   // Draw the OR High line

   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then TL_Delete(LineId1);
   If TodayOnly and LineId1 <> -1 and LineId1 <> ID1 Then Text_Delete(LineId1);
   If TodayOnly then LineId1 = ID1;

   ID1 = TL_New(Date, StartTime, HighDay, Date, Time, HighDay);    
   TL_SetEnd(ID1, Date, Time + Text_Offset, HighDay);
   TL_SetColor(ID1, IB_Color);
   TL_SetStyle(ID1, IB_Style);
   TL_SetSize(ID1, IB_LineSize);

   ID1Text = Text_New(Date, Time + Text_Offset, HighDay, "OR  High");
   Text_SetStyle(ID1Text, 0, 1);   
   Text_SetColor(ID1Text, IB_Color);
   Text_SetFontName(ID1Text, Font_Name);
   Text_SetSize(ID1Text, Font_Size);
   Text_SetLocation(ID1Text, Date, Time + Text_Offset, HighDay);

User avatar
TJ
Posts: 6601
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 971 times
Been thanked: 1910 times

Re: Why is my text doubled?

Postby TJ » 26 Sep 2012

olobay wrote:TodayOnly if true plots only lines for today. If false then plots lines for all days in the chart. Right now it is executing 3 times per TL being drawn, 12 in total: twice to delete previous days TLs and Text objects and once to assign a condition to plot today's TLs and Text objects.


Well, why are you drawing the text so many times?

See post #7 for instruction. Pay attention to "once".


Take a look at the example again in post #2.
This code is written by a professional programmer. It is one of the best code I have seen.

Pay attention to how he uses the Text_SetLocation.

Code: Select all

If PlaceTextRight then begin
            Text_SetLocation(R1Txt, Date, EndTime, RR1);



ps. his code might look complicated at first, but most are just duplicate drawing objects.


Return to “MultiCharts”