How does one take a bond price, convert to Decimal


0
0

Basically using in an S/R Alert on  Spreads-  /ZF-/ZN.   I need to  convert  the Bond  Closes

close(“ZF”)  or close(“ZN”)  to a decimal so the following lines work as they do on other spread charts.

(These are just  few key lines in the code to see why I need them )

 

input Vposition={default AlertisAbove,AlertisBelow};

def ZFValue= (close(“ZF”) * 1000);

def ZNValue= (close(“ZN”) * 1000);

CurrentValue = ZFValue – ZNValue;

VAlertValue=AlertChartValue*1000;  # $1000 for on full pt or 128 ticks

AlertOn= if (Vposition == Vposition.AlertisAbove) && (CurrentValue >=VAlertValue) or   (Vposition == Vposition.AlertisBelow) && (CurrentValue <=VAlertValue) then yes else no;

Alert(AlertOn,”Price Reached”,Alert.BAR,Sound.Chimes);

plot PAlertValue = AlertChartValue;

 

 

RESOLVED
Marked as spam
Posted by (Questions: 13, Answers: 18)
Asked on December 1, 2017 3:29 pm
426 views
0
Private answer

There is no need to “convert” the bond prices to decimal values. That is handled automatically within the code. Screenshot below shows our 24Hr High/Low alert plotted on a 15 min chart of /ZF. You can see the gray chart labels in the upper left are displaying the decimal equivalent of the fractional value displayed at the red and green lines. There is nothing done within the code to convert those. It just happens. And it works the same with the open and close as it does with the high and the low.

Perhaps you are actually trying to achieve something else, and you feel you need to do this “conversion” in order to get there. In your code, you are trying to multiply by 1,000 in order to do what exactly? Your comment says “1000 for one full point, 128 ticks”. In that line of code you have “AlertChartValue*1000”, yet the variable (or input) named AlertChartValue has not been previously defined in your code. Are you trying to alert on a full point difference between the two bond prices? I’m really lost here without having the entire picture.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on December 2, 2017 9:25 am
0
Private answer

Thanks you helped me solve it!  It was a syntax error in switch/case option for  the spread ZNZF only( /ZN not ZN).  I kept blaming the bond conversion for the problems since all the other case option spreads worked fine.

Yes,  I basically copied the code from my Profit&Loss script where it is helpful(not necessary) to calculate the cash value of the instruments to get the Profit & Loss.  Certainly, not necessary in this program.  I probably should just delete the excess.

Marked as spam
Posted by (Questions: 13, Answers: 18)
Answered on December 4, 2017 10:52 am