Floating-Point division - EasyLanguage Programming | futures.io
futures.io futures trading
 

Go Back   futures.io

> Futures Trading, News, Charts and Platforms > Platforms and Indicators > TradeStation > EasyLanguage Programming


Floating-Point division
Started:October 20th, 2016 (04:34 PM) by rawos Views / Replies:85 / 4
Last Reply:October 21st, 2016 (04:04 AM) Attachments:1

Welcome to futures.io.

Welcome, Guest!

This forum was established to help traders (especially futures traders) by openly sharing indicators, strategies, methods, trading journals and discussing the psychology of trading.

We are fundamentally different than most other trading forums:
  • We work extremely hard to keep things positive on our forums.
  • We do not tolerate rude behavior, trolling, or vendor advertising in posts.
  • We firmly believe in openness and encourage sharing. The holy grail is within you, it is not something tangible you can download.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.


You'll need to register in order to view the content of the threads and start contributing to our community. It's free and simple, and we will never resell your private information.

-- Big Mike
     

Reply
 
Thread Tools Search this Thread

Floating-Point division

Old October 20th, 2016, 04:34 PM   #1 (permalink)
Trading Apprentice
Rome
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 10 since Feb 2010
Thanks: 1 given, 2 received

Floating-Point division

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
     

Old October 20th, 2016, 04:34 PM   #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

     

Old October 20th, 2016, 06:07 PM   #3 (permalink)
 Vendor: abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,151 since Apr 2013
Thanks: 191 given, 648 received


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

Reply With Quote
     
The following user says Thank You to ABCTG for this post:
     

Old October 20th, 2016, 07:22 PM   #4 (permalink)
Trading Apprentice
Rome
 
Futures Experience: None
Platform: NinjaTrader
 
Posts: 10 since Feb 2010
Thanks: 1 given, 2 received


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
Floating-Point division-20160402152629lrc1.png  
Reply With Quote
     
The following user says Thank You to rawos for this post:
     

Old October 21st, 2016, 04:04 AM   #5 (permalink)
 Vendor: abctradinggroup.com 
Hamburg Germany
 
Futures Experience: Advanced
Platform: Multicharts, Tradestation, Multicharts.NET, NinjaTrader, MetaTrader
Broker/Data: DTN IQ
Favorite Futures: ES
 
Posts: 1,151 since Apr 2013
Thanks: 191 given, 648 received

Futures Edge on FIO
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

Reply With Quote
     

Reply



futures.io > Futures Trading, News, Charts and Platforms > Platforms and Indicators > TradeStation > EasyLanguage Programming > Floating-Point division

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)
 

Al Brooks: Stop Losing when a Good Trade goes Bad, Correcting Mistakes

Elite only
 

Trading Technologies: Algo Design Lab hands-on

Dec 13

Normal webinar schedule resumes after the holidays

January
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
{Exception}Floating-Point division by zero, signal only. RickW EasyLanguage Programming 2 September 22nd, 2015 04:13 AM
Floating point invalid operation? hughesfleming MultiCharts 2 September 16th, 2014 06:29 AM
floating error johni MultiCharts 1 June 12th, 2012 11:43 PM
New Regulations in the New Jersey Division of Motor Vehicle's kbit Jokes 1 November 14th, 2011 01:39 AM
Division by Zero, how to debug arjfca EasyLanguage Programming 6 September 30th, 2010 11:04 AM


All times are GMT -4. The time now is 06:01 PM.

Copyright © 2016 by futures.io. 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.
 
no new posts
Page generated 2016-12-08 in 0.10 seconds with 20 queries on phoenix via your IP 54.159.129.152