NexusFi: Find Your Edge


Home Menu

 





Floating-Point division


Discussion in EasyLanguage Programming

Updated
    1. trending_up 1,569 views
    2. thumb_up 2 thanks given
    3. group 3 followers
    1. forum 4 posts
    2. attach_file 1 attachments




 
Search this Thread

Floating-Point division

  #1 (permalink)
rawos
Rome
 
Posts: 10 since Feb 2010
Thanks Given: 1
Thanks Received: 3

Hi, I have an indicator which plot two band when the linear regression channel's angle is = 0.
It's a simple pretty way for spotting congestion movements though the code is quite extensive and Multicharts keeps to give me the floating poin division error.

I was unable to see where the division = 0 is and so to put a condition IF to avoid that, can anyone help me?
Thanks

 
Code
inputs: 
	LinRegLength (  ceiling(5000/1000)*6), 
	LinRegPrice(        Close), 
	UseHighLowForBand (    false) ,
	Extend_CurChnl_Right (false),
	Extend_PastChnl_Right (true), 
	___Color_Selections____ ("Channel Colors"),
	Use_Grad.Colors_1_Const.Colors_2 (1),
	Up_Color(        blue), 
	Gradient_UPCautionColor(darkcyan),
	Dn_Color(        darkred),
	Gradient_DNCautionColor(darkmagenta),
	Flat_Color (yellow),
	Flat_Chnl_LineWidth (2),
	CenterLineColor(        rgb(80,80,80)), 
	LineThickness(2), 
	UpperStyle(        Tool_solid),
	CenterStyle_1_to_5 (5), 
	LowerStyle(        Tool_solid),
	Show_UC_LC (false),
	Enable_Alerts(true);
 
variables:
	intrabarpersist Dir (0), 
	intrabarpersist LinRegTL_ID_L( 0 ), 
	intrabarpersist UpperTL_ID_L( 0 ), 
	intrabarpersist LowerTL_ID_L( 0 ), 
	intrabarpersist LRV_L( 0 ), 
	intrabarpersist LRVAgo_L( 0 ), 
	intrabarpersist PosMaxPrice_L( 0 ), 
	intrabarpersist NegMinPrice_L( 0 ), 
	intrabarpersist MaxPosExtension_L( 0 ), 
	intrabarpersist MaxNegExtension_L( 0 );
	 
if CurrentBar = 1 then 
begin 
	LinRegTL_ID_L = TL_New( Date, Time, Close, Date, Time, Close ) ; 
	TL_SetColor( LinRegTL_ID_L, CenterLineColor ) ; 
	TL_SetStyle( LinRegTL_ID_L, CenterStyle_1_to_5 ) ; 
	TL_SetSize( LinRegTL_ID_L, LineThickness ) ; 
	TL_SetExtRight( LinRegTL_ID_L, Extend_CurChnl_Right ) ;	 
	 
	UpperTL_ID_L = TL_New( Date, Time, Close, Date, Time, Close ) ; 
	TL_SetColor( UpperTL_ID_L, Up_Color) ; 
	TL_SetStyle( UpperTL_ID_L, UpperStyle ) ;
	TL_SetSize( UpperTL_ID_L, LineThickness ) ; 
	 
	LowerTL_ID_L = TL_New( Date, Time, Close, Date, Time, Close ) ; 
	TL_SetColor( LowerTL_ID_L,Dn_Color ) ; 
	TL_SetStyle( LowerTL_ID_L, LowerStyle ) ; 
	TL_Setsize( LowerTL_ID_L, LineThickness ) ; 
	
end ;	 
 
LRV_L = LinearRegValue( LinRegPrice, LinRegLength, 0 ) ;  
LRVAgo_L = LinearRegValue( LinRegPrice, LinRegLength, LinRegLength - 1 ) ; 
 
if LinRegTL_ID_L > 0 then 
begin 
	TL_SetEnd( LinRegTL_ID_L, Date, Time, LRV_L ) ; 
	TL_SetBegin( LinRegTL_ID_L, Date[LinRegLength - 1], Time[LinRegLength - 1], LRVAgo_L ) ; 
	TL_SetSize( LinRegTL_ID_L, LineThickness ) ; 
				 
	for Value1 = LinRegLength - 1 downto 1 
	begin 
		if UseHighLowForBand then 
		begin 
			PosMaxPrice_L = High[Value1] ; 
			NegMinPrice_L = Low[Value1] ; 
		end 
		else 
		begin 
			PosMaxPrice_L = MaxList( Open[Value1], Close[Value1] ) ; 
			NegMinPrice_L = MinList( Open[Value1], Close[Value1] ) ; 
		end ; 
		if value1 = LinRegLength - 1 then 
		begin 
			MaxPosExtension_L = PosMaxPrice_L - TL_GetValue( LinRegTL_ID_L, Date[Value1], Time[Value1] ) ; 
			MaxNegExtension_L = TL_GetValue( LinRegTL_ID_L, Date[Value1], Time[Value1] ) - NegMinPrice_L  ; 
		end 
		else 
		begin 
			if PosMaxPrice_L - TL_GetValue( LinRegTL_ID_L, Date[Value1], Time[Value1] ) > MaxPosExtension_L then 
				MaxPosExtension_L = PosMaxPrice_L - TL_GetValue( LinRegTL_ID_L, Date[Value1], Time[Value1] ) ;				 
			if TL_GetValue( LinRegTL_ID_L, Date[Value1], Time[Value1] ) - NegMinPrice_L > MaxNegExtension_L then 
				MaxNegExtension_L = TL_GetValue( LinRegTL_ID_L, Date[Value1], Time[Value1] ) - NegMinPrice_L ; 
		end ; 
	end ; 
end ; 
 var: intrabarpersist Color(white),intrabarpersist _LE(true),intrabarpersist SE(true);
 
 var:intrabarpersist L_Slope(0),intrabarpersist S_Slope(0),intrabarpersist HLslope(-99999),intrabarpersist HSslope(99999);
 
  L_slope = TLSlopeEasy(LinRegPrice, 0, LinRegLength);
  S_Slope = TLSlopeEasy(LinRegPrice, 0, LinRegLength);
  
  If L_slope>0 then begin
   		If L_slope > HLslope then HLslope = L_slope else HLslope = HLslope[1]; 	
  end else
  If S_slope<0 then begin
   		If S_slope < HSslope then HSslope = S_slope else HSslope = HSslope[1];
  end; 
 var:intrabarpersist Lcolor(white),intrabarpersist Scolor(white);
 //GradientColor(  dValue,  dMin,  dMax,  nFromColor,  nToColor  ) 
 Lcolor = gradientcolor(L_slope,0,HLslope,Gradient_UPCautionColor,up_color);
 Scolor = gradientcolor(absvalue(S_slope),0,absvalue(HSslope),Gradient_DNCautionColor,Dn_Color);
 
 If LRV_L + MaxPosExtension_L > LRVAgo_L + MaxPosExtension_L then begin 
 	If Use_Grad.Colors_1_Const.Colors_2 = 1 then 
 	 color = gradientcolor(L_slope,0,HLslope,Gradient_UPCautionColor,up_color) else color = Up_color;
 	_LE = true; 
 	 SE = false;
 	 S_slope = 0;
 	 Dir = 1;
 end else
 If LRV_L + MaxPosExtension_L < LRVAgo_L + MaxPosExtension_L then begin
 	If Use_Grad.Colors_1_Const.Colors_2 = 1 then 
 	 color = gradientcolor(absvalue(S_slope),0,absvalue(HSslope),Gradient_DNCautionColor,Dn_Color) else color = Dn_Color;
 	_LE = false; 
 	 SE = true;
 	 L_Slope = 0;
 	 Dir = -1;
 end else begin 
 	 color = yellow;
 	_LE = false; 
 	 SE = false;
 	 S_Slope = 0;
 	 L_Slope = 0;
 end;



if UpperTL_ID_L > 0 and _LE = true then 
begin 
	TL_SetEnd( UpperTL_ID_L, Date, Time, LRV_L + MaxPosExtension_L ) ;  
	TL_SetBegin( UpperTL_ID_L, Date[LinRegLength - 1], Time[LinRegLength - 1], LRVAgo_L + MaxPosExtension_L ) ; 
	TL_SetColor( UpperTL_ID_L, color) ; 
	TL_setStyle(UpperTL_ID_L,1);
	TL_SetSize( UpperTL_ID_L, LineThickness ) ; 
	TL_SetExtRight( UpperTL_ID_L, Extend_CurChnl_Right ) ; 
	
end else
If _LE = False then begin
	TL_SetColor( UpperTL_ID_L, Flat_Color) ;
 	TL_setStyle(UpperTL_ID_L,1);
 	TL_setSize(UpperTL_ID_L,Flat_Chnl_LineWidth);
 	TL_SetExtRight( UpperTL_ID_L, Extend_PastChnl_Right) ; 
 	HLslope = 0;
end;


	 
if LowerTL_ID_L > 0 and _LE = true then 
begin 
	TL_SetEnd( LowerTL_ID_L, Date, Time, LRV_L - MaxNegExtension_L ) ;  
	TL_SetBegin( LowerTL_ID_L, Date[LinRegLength - 1], Time[LinRegLength - 1], LRVAgo_L - MaxNegExtension_L ) ;
	TL_SetColor( LowerTL_ID_L,Color ) ; 
	TL_setStyle(LowerTL_ID_L,1);
	TL_SetSize(LowerTL_ID_L, LineThickness ) ;  
	TL_SetExtRight( LowerTL_ID_L, Extend_CurChnl_Right ) ;  
end else
If _LE = False then begin
	TL_SetColor( LowerTL_ID_L, Flat_Color) ;
	TL_setStyle(LowerTL_ID_L,1);
	TL_setSize(LowerTL_ID_L,Flat_Chnl_LineWidth);
	TL_SetExtRight( LowerTL_ID_L, Extend_PastChnl_Right ) ; 
	HLslope = 0;
end;	 

var:EndDate_L(0),EndTime_L(0),intrabarpersist EndUpperPrice_L(0),intrabarpersist EndLowerPrice_L(0),intrabarpersist End_LRV_L(0);
var:BeginDate_L(0),BeginTime_L(0),intrabarpersist BeginUpperPrice_L(0),intrabarpersist BeginLowerPrice_L(0),intrabarpersist Begin_LRV_L(0);
{
If Currentbar = 1 then begin
Value1 = TL_new(EndDate_L,EndTime_L,EndUpperPrice_L,EndDate_L,EndTime_L,EndLowerPrice_L);
Value2 = TL_new(BeginDate_L,BeginTime_L,BeginUpperPrice_L,BeginDate_L,BeginTime_L,BeginLowerPrice_L);
end;
}
If _LE = False and _LE[1] = true then begin
	EndDate_L = date[1];
	EndTime_L = time[1];
	EndUpperPrice_L = LRV_L[1] + MaxPosExtension_L[1];
	EndLowerPrice_L = LRV_L[1] - MaxPosExtension_L[1];
	End_LRV_L = LRV_L[1];
	
	BeginDate_L = Date[LinRegLength];
	BeginTime_L = Time[LinRegLength];
	BeginUpperPrice_L = LRVAgo_L[1] + MaxPosExtension_L[1];
	BeginLowerPrice_L = LRVAgo_L[1] - MaxNegExtension_L[1];
	Begin_LRV_L = LRVAgo_L[1];
	
	{
	Value1 = TL_new(EndDate_L,EndTime_L,EndUpperPrice_L,EndDate_L,EndTime_L,EndLowerPrice_L);
	//TL_SetEnd( value1,EndDate_L,EndTime_L,EndUpperPrice_L);
	//TL_Setbegin( value1,EndDate_L,EndTime_L,EndLowerPrice_L);
	TL_SetColor(value1,Flat_Color);
	TL_setStyle(value1,3);
	
	Value2 = TL_new(BeginDate_L,BeginTime_L,BeginUpperPrice_L,BeginDate_L,BeginTime_L,BeginLowerPrice_L);
	TL_SetColor(value2,Flat_Color);
	TL_setStyle(value2,3);
	}
end;

VAR:intrabarpersist UC_L(0),intrabarpersist LC_L(0);

UC_L = LRV_L + MaxPosExtension_L;
LC_L = LRV_L - MaxNegExtension_L;

// short ==========================================================================================================

 
variables: 
	intrabarpersist LinRegTL_ID_S( 0 ), 
	intrabarpersist UpperTL_ID_S( 0 ), 
	intrabarpersist LowerTL_ID_S( 0 ), 
	intrabarpersist LRV_S( 0 ), 
	intrabarpersist LRVAgo_S( 0 ), 
	intrabarpersist PosMaxPrice_S( 0 ), 
	intrabarpersist NegMinPrice_S( 0 ), 
	intrabarpersist MaxPosExtension_S( 0 ), 
	intrabarpersist MaxNegExtension_S( 0 ) ; 
	 
if CurrentBar = 1 then 
begin 
	LinRegTL_ID_S = TL_New( Date, Time, Close, Date, Time, Close ) ; 
	TL_SetColor( LinRegTL_ID_S, CenterLineColor ) ; 
	TL_SetStyle( LinRegTL_ID_S, 3 ) ;
	TL_SetSize(LinRegTL_ID_S, LineThickness) ; 
	TL_SetExtRight( LinRegTL_ID_S, Extend_CurChnl_Right ) ;	 
	 
	UpperTL_ID_S = TL_New( Date, Time, Close, Date, Time, Close ) ; 
	TL_SetColor( UpperTL_ID_S, Up_Color) ; 
	TL_SetStyle( UpperTL_ID_S, UpperStyle ) ; 
	TL_SetSize(UpperTL_ID_S, LineThickness ) ;
	 
	LowerTL_ID_S = TL_New( Date, Time, Close, Date, Time, Close ) ; 
	TL_SetColor( LowerTL_ID_S,Dn_Color ) ; 
	TL_SetStyle( LowerTL_ID_S, LowerStyle ) ; 
 	TL_SetSize(LowerTL_ID_S, LineThickness ) ;
end ;	 
 
LRV_S = LinearRegValue( LinRegPrice, LinRegLength, 0 ) ;  
LRVAgo_S = LinearRegValue( LinRegPrice, LinRegLength, LinRegLength - 1 ) ; 
 
if LinRegTL_ID_S > 0 then 
begin 
	TL_SetEnd( LinRegTL_ID_S, Date, Time, LRV_S ) ; 
	TL_SetBegin( LinRegTL_ID_S, Date[LinRegLength - 1], Time[LinRegLength - 1], LRVAgo_S ) ; 
	TL_SetSize(LinRegTL_ID_S, LineThickness ) ;			 
	for Value1 = LinRegLength - 1 downto 1 
	begin 
		if UseHighLowForBand then 
		begin 
			PosMaxPrice_S = High[Value1] ; 
			NegMinPrice_S = Low[Value1] ; 
		end 
		else 
		begin 
			PosMaxPrice_S = MaxList( Open[Value1], Close[Value1] ) ; 
			NegMinPrice_S = MinList( Open[Value1], Close[Value1] ) ; 
		end ; 
		if value1 = LinRegLength - 1 then 
		begin 
			MaxPosExtension_S = PosMaxPrice_S - TL_GetValue( LinRegTL_ID_S, Date[Value1], Time[Value1] ) ; 
			MaxNegExtension_S = TL_GetValue( LinRegTL_ID_S, Date[Value1], Time[Value1] ) - NegMinPrice_S  ; 
		end 
		else 
		begin 
			if PosMaxPrice_S - TL_GetValue( LinRegTL_ID_S, Date[Value1], Time[Value1] ) > MaxPosExtension_S then 
				MaxPosExtension_S = PosMaxPrice_S - TL_GetValue( LinRegTL_ID_S, Date[Value1], Time[Value1] ) ;				 
			if TL_GetValue( LinRegTL_ID_S, Date[Value1], Time[Value1] ) - NegMinPrice_S > MaxNegExtension_S then 
				MaxNegExtension_S = TL_GetValue( LinRegTL_ID_S, Date[Value1], Time[Value1] ) - NegMinPrice_S ; 
		end ; 
	end ; 
end ; 



 
 If LRV_S + MaxPosExtension_S > LRVAgo_S + MaxPosExtension_S then begin
 	 If Use_Grad.Colors_1_Const.Colors_2 = 1 then 
 	 color = gradientcolor(L_slope,0,HLslope,Gradient_UPCautionColor,up_color) else color = Up_Color; 
 	_LE = true; 
 	 SE = false;
 end else
 If LRV_S + MaxPosExtension_S < LRVAgo_S + MaxPosExtension_S then begin 
 	If Use_Grad.Colors_1_Const.Colors_2 = 1 then 	
 	 color = gradientcolor(absvalue(S_slope),0,absvalue(HSslope),Gradient_DNCautionColor,Dn_Color) else color = Dn_Color; 
 	_LE = false; 
 	 SE = true;
 end else begin 
 	 color = yellow;
 	_LE = false; 
 	 SE = false;
 end;



if UpperTL_ID_S > 0 and SE = true then 
begin 
	TL_SetEnd( UpperTL_ID_S, Date, Time, LRV_S + MaxPosExtension_S ) ;  
	TL_SetBegin( UpperTL_ID_S, Date[LinRegLength - 1], Time[LinRegLength - 1], LRVAgo_S + MaxPosExtension_S ) ; 
	TL_SetColor( UpperTL_ID_S, color) ;
	TL_setStyle(UpperTL_ID_S,1);
	TL_SetSize(UpperTL_ID_S, LineThickness ) ;
	TL_SetExtRight( UpperTL_ID_S, Extend_CurChnl_Right ) ;
end else
If SE = False then begin
	TL_SetColor( UpperTL_ID_S, Flat_Color) ; 
	TL_setStyle(UpperTL_ID_S,1);
	TL_setsize(UpperTL_ID_S,Flat_Chnl_LineWidth);
	TL_SetExtRight( UpperTL_ID_S, Extend_PastChnl_Right ) ;
	HSslope = 0; 
end;

	 
if LowerTL_ID_S > 0 and SE = true then 
begin 
	TL_SetEnd( LowerTL_ID_S, Date, Time, LRV_S - MaxNegExtension_S ) ;  
	TL_SetBegin( LowerTL_ID_S, Date[LinRegLength - 1], Time[LinRegLength - 1], LRVAgo_S - MaxNegExtension_S ) ;
	TL_SetColor( LowerTL_ID_S,Color ) ;
	TL_setStyle(LowerTL_ID_S,1);
	TL_SetSize(LowerTL_ID_S, LineThickness) ;
	TL_SetExtRight( LowerTL_ID_S, Extend_CurChnl_Right ) ;  
end else
If SE = False then begin
	TL_SetColor( LowerTL_ID_S, Flat_Color) ;
	TL_setStyle(LowerTL_ID_S,1);
	TL_setsize(LowerTL_ID_S,Flat_Chnl_LineWidth);
	TL_SetExtRight( LowerTL_ID_S, Extend_PastChnl_Right ) ; 
	 HSslope = 0;
end;	 

var:EndDate_S(0),EndTime_S(0),intrabarpersist EndUpperPrice_S(0),intrabarpersist EndLowerPrice_S(0),intrabarpersist End_LRV_S(0);
var:BeginDate_S(0),BeginTime_S(0),intrabarpersist BeginUpperPrice_S(0),intrabarpersist BeginLowerPrice_S(0),intrabarpersist Begin_LRV_S(0);

If SE = False and SE[1] = true then begin
	EndDate_S = date[1];
	EndTime_S = time[1];
	EndUpperPrice_S = LRV_S[1] + MaxPosExtension_S[1];
	EndLowerPrice_S = LRV_S[1] - MaxPosExtension_S[1];
	End_LRV_S = LRV_S[1];
	
	BeginDate_S = Date[LinRegLength ];
	BeginTime_S = Time[LinRegLength ];
	BeginUpperPrice_S = LRVAgo_S[1] + MaxPosExtension_S[1];
	BeginLowerPrice_S = LRVAgo_S[1] - MaxNegExtension_S[1];
	Begin_LRV_S = LRVAgo_S[1];
	{
	Value1 = TL_new(EndDate_S,EndTime_S,EndUpperPrice_S,EndDate_S,EndTime_S,EndLowerPrice_S);
	TL_SetColor(value1,Flat_Color);
	TL_setStyle(value1,3);
	
	Value2 = TL_new(BeginDate_S,BeginTime_S,BeginUpperPrice_S,BeginDate_S,BeginTime_S,BeginLowerPrice_S);
	TL_SetColor(value2,Flat_Color);
	TL_setStyle(value2,3);
	}	
end;

VAR:intrabarpersist UC_S(0),intrabarpersist LC_S(0);

UC_S = LRV_S + MaxPosExtension_S;
LC_S = LRV_S - MaxNegExtension_S;

VAR:intrabarpersist UC(0),intrabarpersist LC(0);
VAR:intrabarpersist hlUC(0),intrabarpersist hlLC(0);

If _LE = True THEN BEGIN
	UC = UC_L; LC = LC_L;
	hlUC = UC_L; hlLC = LC_L;
	
	If hlUC > hlUC[1] then hlUC = hlUC else hlUC = hlUC[1];
	If hlLC > hlLC[1] then hlLC = hlLC else hlLC = hlLC[1];
	
	SETPLOTCOLOR[1](1,RGB(0,180,0));
	SETPLOTCOLOR[1](2,RGB(0,180,0));
	SETPLOTCOLOR[1](3,RGB(0,80,0));
	SETPLOTCOLOR[1](4,RGB(0,80,0));
	
End ELSE 
If SE = True THEN BEGIN
	UC = UC_S; LC = LC_S;
	hlUC = UC_S; hlLC = LC_S;
	
	If hlUC < hlUC[1] then hlUC = hlUC else hlUC = hlUC[1];
	If hlLC < hlLC[1] then hlLC = hlLC else hlLC = hlLC[1];
	
	SETPLOTCOLOR[1](1,RGB(180,0,0));
	SETPLOTCOLOR[1](2,RGB(180,0,0));
	SETPLOTCOLOR[1](3,RGB(80,0,0));
	SETPLOTCOLOR[1](4,RGB(80,0,0));
	
End;

If Show_UC_LC = True then begin

PLOT1(hlUC,"hlUC",RGB(60,60,60));
PLOT2(hlLC,"hlLC",RGB(60,60,60));

PLOT3(UC,"UC",RGB(140,140,140));
PLOT4(LC,"LC",RGB(140,140,140));
end;

var: IntvTxt(""),BT(0);
Once BT = bartype;
 	
if BT =0  Then IntvTxt = numtostr(barinterval,0) + spaces(3)+"TickBar Interval" else
if BT =1  Then IntvTxt = numtostr(barinterval,0) + spaces(3)+"Minute Bar Interval" else
if BT =2  Then IntvTxt = "Daily Bar Interval" else
if BT =3  Then IntvTxt = "Weekly Bar Interval" else
if BT =4  Then IntvTxt = "Monthly Bar Interval" else
if BT =5  Then IntvTxt = "Point & Figure Bar Interval" else
if BT =6  Then IntvTxt = "(reserved) Bar Interval" else
if BT =7  Then IntvTxt = "(reserved) Bar Interval" else
if BT =8  Then IntvTxt = numtostr(boxsize,0) + spaces(3)+"Kagi Bar Interval" else
if BT =9  Then IntvTxt = numtostr(boxsize,0) + spaces(3)+"Case Bar Interval" else
if BT =10 Then IntvTxt = numtostr(boxsize,0) + spaces(3)+"Line Break Bar Interval" else
if BT =11 Then IntvTxt = numtostr(boxsize,0) + spaces(3)+"Momentum Bar Interval" else
if BT =12 Then IntvTxt = numtostr(boxsize,0) + spaces(3)+"Range Bar Interval" else
if BT =13 Then IntvTxt = numtostr(boxsize,0) + spaces(3)+"Renko Bar Interval" else
if BT =14 Then IntvTxt = numtostr(barinterval,0) + spaces(3)+"Second Bar Interval";	

If Enable_Alerts and Onealert(_LE = true and _LE[1] = false) then alert("LRC Alert at: " + ELTimeTostring(Time)+spaces(1)+iffstring(time<1200,"AM","PM")+ Spaces(3)+"Starting LONG Trend on" + Spaces (3) + IntvTxt); 
If Enable_Alerts and Onealert( SE = true and  SE[1] = false) then alert("LRC Alert at: " + ELTimeTostring(Time)+spaces(1)+iffstring(time<1200,"AM","PM")+ Spaces(3)+"Starting SHORT Trend on" + Spaces (3) + IntvTxt); 

//print("  HLslope:",HLslope:0:5,"  L_slope:",L_slope:0:5,"  HSslope:",HSslope:0:5,"  S_slope:",S_slope:0:5);


// arrow ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

// arrow code +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 Input:
 ___OnScreen_Arrow ("Text Arrow"),
 Show_Text_Arrow_0_1 (1), 
 Show_Text_Header (true),
 Text_Arrow_Header ("*LRC*"),
 // Name_1_Length_2_Both_3 (3),		
 V_Arrow_Loc (5),
 H_Arrow_Loc (99);


// Code to sort out indicator code and atrRadar screen code	
Variables:
	Value_1(0),
    Chart(False),
    Radar(False);
{ Code Used in Indicators not Strategies }
If CurrentBar = 1 then
begin
    Value_1 = GetAppInfo(aiApplicationType);
    If Value_1 = 1 then
	Chart = True
    else
    If Value_1 = 2 then
	Radar = True;
end; 				
 
 
If Show_Text_Arrow_0_1 = 1 and chart then begin
 
 Array:
intrabarpersist TextString[11](""),
intrabarpersist ArrowTxt[11](-1);

var:intrabarpersist LengthStr("");
Var:
DispH(0),
DispL(0),
Disp(0);
var:intrabarpersist value_311(-1);
var:intrabarpersist LabelText1("°");
var: intrabarpersist ang(0),intrabarpersist PreAng(0);

If _LE = True  and SE = False then begin
 If ang <> 0 then PreAng = ang;
	 ang = arctangent(HLslope); 
	 If ang = 0 then ang = preAng;
end else
If _LE = false and SE = true  then begin
	If ang <> 0 then PreAng = ang;
	ang = arctangent(HSslope);
	If ang = 0 then ang = preAng;
end;
	


// Calculate 1/2 Screen
DispH = Getappinfo(aihighestdispvalue) ; 
DispL = Getappinfo(aiLowestDispValue) ;  
Disp = DispH - DispL ;  
value_311 = DispL+0.5*Disp ; 
{
If Name_1_Length_2_Both_3 = 1 then	
LengthStr = "LRC" else
If Name_1_Length_2_Both_3 = 2 then	
LengthStr = numtostr(LinRegLength,0) else
If Name_1_Length_2_Both_3 = 3 then	
LengthStr = numtostr(LinRegLength,0)+".LRC" ;
}

// Construct the ARROW 
If Dir = 1 then begin {vwapdiff>0, or avg>avg[1]}
{
TextString[1]  = ""+Spaces(H_Arrow_Loc)+"/|\" ;   
TextString[2]  = ""+Spaces(H_Arrow_Loc)+"//\\" ; 
TextString[3]  = ""+Spaces(H_Arrow_Loc)+"//|\\" ; 
TextString[4]  = ""+Spaces(H_Arrow_Loc)+"///\\\" ;   
TextString[5]  = ""+Spaces(H_Arrow_Loc)+"///|\\\" ;   
TextString[6]  = ""+Spaces(H_Arrow_Loc)+"-----" ;  
TextString[7]  = ""+Spaces(H_Arrow_Loc)+"|||" ;
TextString[8]  = ""+Spaces(H_Arrow_Loc)+"--" ;
TextString[9]  = ""+Spaces(H_Arrow_Loc)+spaces(6) ; //"|||" 
TextString[10] = ""+Spaces(H_Arrow_Loc)+LengthStr ;
End else begin 
TextString[1]  = ""+Spaces(H_Arrow_Loc)+LengthStr;
TextString[2]  = ""+Spaces(H_Arrow_Loc)+spaces(6) ; //"|||" 
TextString[3]  = ""+Spaces(H_Arrow_Loc)+"--";
TextString[4]  = ""+Spaces(H_Arrow_Loc)+"|||";
TextString[5]  = ""+Spaces(H_Arrow_Loc)+"-----";
TextString[6]  = ""+Spaces(H_Arrow_Loc)+"\\\|///";
TextString[7]  = ""+Spaces(H_Arrow_Loc)+"\\\///";
TextString[8]  = ""+Spaces(H_Arrow_Loc)+"\\|//";
TextString[9]  = ""+Spaces(H_Arrow_Loc)+"\\//";
TextString[10] = ""+Spaces(H_Arrow_Loc)+"\|/";
}
TextString[1]  = ""+Spaces(H_Arrow_Loc)+{"/|\"}iffstring(Show_Text_Header = false,"/|\",Text_Arrow_Header);   
TextString[2]  = ""+Spaces(H_Arrow_Loc)+{"//\\"}iffstring(Show_Text_Header = false,"//\\","---"); 
TextString[3]  = ""+Spaces(H_Arrow_Loc)+"//|\\" ; 
TextString[4]  = ""+Spaces(H_Arrow_Loc)+"///\\\" ;   
TextString[5]  = ""+Spaces(H_Arrow_Loc)+"///|\\\" ;   
TextString[6]  = ""+Spaces(H_Arrow_Loc)+"------" ;  
TextString[7]  = ""+Spaces(H_Arrow_Loc)+"|||" ;
TextString[8]  = ""+Spaces(H_Arrow_Loc)+{"|||"}"--" ;
TextString[9]  = ""+Spaces(H_Arrow_Loc)+"" ;  
TextString[10] = ""+Spaces(H_Arrow_Loc)+{numtostr(LinRegLength,0)}" "+ numtostr(ang,2)  + LabelText1 ;
End else begin 
TextString[1]  = ""+Spaces(H_Arrow_Loc)+{numtostr(LinRegLength,0)}" "+ numtostr(ang,2)  + LabelText1 ;
TextString[2]  = ""+Spaces(H_Arrow_Loc)+"";
TextString[3]  = ""+Spaces(H_Arrow_Loc)+{"|||"}"--";
TextString[4]  = ""+Spaces(H_Arrow_Loc)+"|||";
TextString[5]  = ""+Spaces(H_Arrow_Loc)+"------";
TextString[6]  = ""+Spaces(H_Arrow_Loc)+"\\\|///";
TextString[7]  = ""+Spaces(H_Arrow_Loc)+"\\\///";
TextString[8]  = ""+Spaces(H_Arrow_Loc)+"\\|//";
TextString[9]  = ""+Spaces(H_Arrow_Loc)+{"\\//"}iffstring(Show_Text_Header = false,"\\//","---");
TextString[10] = ""+Spaces(H_Arrow_Loc)+{"\|/"}iffstring(Show_Text_Header = false,"\|/",Text_Arrow_Header); 

end;
var:value_4(1),value_5(1),value_6(1),value_7(1),value_8(1),value_9(1),value_13(1);
// Initiate Text
 if barnumber = 1 then 
 begin
 	For value_4 = 1 to 10 
 	begin
 		ArrowTxt[value_4] = Text_New(Date, Time, High," " ) ;
 	end;;
end;


// Location of arrow 
if C<value_311 then 
begin
		Text_SetLocation(ArrowTxt[1],Date, Time, DispH-Disp*(V_Arrow_Loc*.01     ));
	For value_5 = 1 to 9 begin
  		Text_SetLocation(ArrowTxt[value_5+1],Date, Time, DispH-Disp*(V_Arrow_Loc*.01+(value_5*.01)));
	end;
End else
if C>value_311 then 
begin
		Text_SetLocation(ArrowTxt[10],Date,Time, DispL+Disp*(V_Arrow_Loc*.01+0.00)) ;
	For value_6 = 9 downto 1 begin
		Text_SetLocation(ArrowTxt[10-value_6],Date, Time, DispL+Disp*(V_Arrow_Loc*.01+(value_6*.01){0.09})) ;
	end;
end;

// Set String
 For value_7 = 1 to 10 begin
 Text_SetString(ArrowTxt[value_7], TextString[value_7] );
 end;

// Set Color
Var:intrabarpersist Acolor(white);

If Dir =  1 then Acolor = green else
If Dir = -1 then Acolor = red;

For value_8 = 1 to 10 begin
If Dir = 1  then {vwapdiff>0}
Text_SetColor(ArrowTxt[value_8], Acolor) else Text_SetColor(ArrowTxt[value_8], Acolor); 

end;    

// Set Style
If Dir = 1 then {vwapdiff>0}
begin
	For value_9 = 1 to 10 
	begin
		Text_SetStyle(ArrowTxt[value_9],2,2);  
	end; 
End else 
begin
	For value_13 = 1 to 10 
	begin
		Text_SetStyle(ArrowTxt[value_13],2,1); 
	end;
end;			

end;

Reply With Quote

Can you help answer these questions
from other members on NexusFi?
REcommedations for programming help
Sierra Chart
Better Renko Gaps
The Elite Circle
MC PL editor upgrade
MultiCharts
Trade idea based off three indicators.
Traders Hideout
NT7 Indicator Script Troubleshooting - Camarilla Pivots
NinjaTrader
 
Best Threads (Most Thanked)
in the last 7 days on NexusFi
Just another trading journal: PA, Wyckoff & Trends
34 thanks
Tao te Trade: way of the WLD
24 thanks
My NQ Trading Journal
14 thanks
GFIs1 1 DAX trade per day journal
11 thanks
Vinny E-Mini & Algobox Review TRADE ROOM
10 thanks
  #3 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627


rawos,

from glancing at your code it doesn't appear to be a typical division by 0 error - unless I am overlooking it, too. Your best bet will likely be to block all of the code and then unblock it again piece by piece until the error is triggered again. This should help you in narrowing it down. Once you know what code is causing the error it will be easier to fix.

Regards,

ABCTG

Follow me on Twitter Reply With Quote
Thanked by:
  #4 (permalink)
rawos
Rome
 
Posts: 10 since Feb 2010
Thanks Given: 1
Thanks Received: 3


ABCTG View Post
rawos,

from glancing at your code it doesn't appear to be a typical division by 0 error - unless I am overlooking it, too. Your best bet will likely be to block all of the code and then unblock it again piece by piece until the error is triggered again. This should help you in narrowing it down. Once you know what code is causing the error it will be easier to fix.

Regards,

ABCTG

Hi, ABCTG you rock! I even though about it, the error seems to reside in this piece of chunk
I removed the part _LE = true and SE = true

but it doesn't work as intended, no plotting any channel at 0 angle (no plotting any agle but 65 and -75) just the usual LRC

plus the code is a really mess with multiple inputs and vars spread all over than maybe the issue could be only on MC

Anyway thanks for the great tips

 
Code
if UpperTL_ID_L > 0 and _LE = true then
 
Code
if LowerTL_ID_L > 0 and _LE = true then
 
Code
if UpperTL_ID_S > 0 and SE = true then
 
Code
if LowerTL_ID_S > 0 and SE = true then

Attached Thumbnails
Click image for larger version

Name:	20160402152629lrc1.png
Views:	200
Size:	24.3 KB
ID:	219417  
Reply With Quote
Thanked by:
  #5 (permalink)
 ABCTG   is a Vendor
 
Posts: 2,433 since Apr 2013
Thanks Given: 481
Thanks Received: 1,627

Hi rawos,

thanks for the feedback. In my opinion the error messages can't be directly triggered by the lines you posted, but they could be within the code blocks that these lines start.

The code you posted has two custom functions in it (Onealert and ELTimeTostring), let's assume for a moment that they are not causing the problem. That leaves "gradientcolor" as suspect number 1. When you block the gradient color calls, the code doesn't trigger the error message anymore.
Now you'll have to track down the problem using print statements. My guess is that you have cases where the min and max inputs into the gradient color reserved word are equal. This would trigger the floating point error.

Regards,

ABCTG

Follow me on Twitter Reply With Quote




Last Updated on October 21, 2016


© 2024 NexusFi™, s.a., All Rights Reserved.
Av Ricardo J. Alfaro, Century Tower, Panama City, Panama, Ph: +507 833-9432 (Panama and Intl), +1 888-312-3001 (USA and Canada)
All information is for educational use only and is not investment advice. There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
About Us - Contact Us - Site Rules, Acceptable Use, and Terms and Conditions - Privacy Policy - Downloads - Top
no new posts