Ok, so I've been messing with this script for about 2 days now and finally decided I needed to ask for some help. I can normally do enough research to find the parts I need and then piece them together. It helps me build my skills in the technology for a nice time investment. However, I'm missing something very very simple that I can't seem to figure out and I would love someone to shed some light on my problem (stupidity) - lack of thinkscript dynamics.
Background: I am a day trader and I closely watch the price of a ticker relative to whole dollars. For example, if a stock has a current price of $423.44, then I will be closely watching its movement between the $423.00 and $424.00 range which is can often be the support and resistance levels. My chart shows 20 days of data in 1m intervals (bars) for the ticker.
Goal: I wanted to write a new script that would plot a horizontal line at the whole value above and below the current mark price. Actually for transparency, i want to plot 3 lines above and 3 lines below, but i can easily do that after doing the first two. So if the last mark price was $423.44, then I would want to draw a horizontal line at both $423.00 and $424.00. But I want to draw (plot) the line only for the current day even though I'm showing 20 days of data. I dont care where the lines would have been relative to other days. I only care about today's lines. So, if the price moves from $423.44 up through $424.00 and lands say at $424.15, then i would like to plot the lines now at $424.00 and $425.00. I want these lines to move with the CURRENT price as it moves up and down.
Along with reading some of the documentation and my research, I found a few golden nuggets to help me achieve some of my goals.
Get the Current Day so I could use If statements to only plot based on the current day
def isCurrentDay = if GetLastDay() == GetDay() then 1 else 0;
Plot the support and resistance lines only if it is the current day
Plot firstResistance = if iscurrentDay then Ceil(423.44) else Double.NaN;
firstResistance.setPaintingStrategy(paintingStrategy.HoRIZONTAL);
firstResistance.SetDefaultColor(Color.Red);
Plot firstSupport = if iscurrentDay then Floor(423.44) else Double.NaN;
firstSupport.setPaintingStrategy(paintingStrategy.HoRIZONTAL);
firstSupport.SetDefaultColor(Color.Green);
Ok, great, now I have my lines that only show up for the current day and they are right where i want them, but unfortunately I have a hard coded value of 423.44 in my examples. The next thing I needed was to find out the current price so my lines would redraw based on that current price. And like WTF, i can't for the life of me get the current price of the current Mark value of the current bar to fill in that hard coded value. I tried using this kind of stuff to get the values...
def isLastBar = !IsNaN(close) and IsNaN(close[-1]);
def LastKnownPrice = If isLastBar Then Ceil(close[0]) else Double.NaN;
Sure, it gets the value of the most recent bar, but since the charting gets painted from the left to the right, i dont know the latest bar value before i need it and obviously if i used the few lines above it will only draw the line if its the last bar. I need to know the current mark/close price back when the chart paints the first bar of that day. I also tried to use CompoundValue, but i dont think i was using it correctly. Does anyone have some advice on how to achieve my task? How do i get the current close/mark price regardless of Aggregation period, etc. Thanks in advance
Background: I am a day trader and I closely watch the price of a ticker relative to whole dollars. For example, if a stock has a current price of $423.44, then I will be closely watching its movement between the $423.00 and $424.00 range which is can often be the support and resistance levels. My chart shows 20 days of data in 1m intervals (bars) for the ticker.
Goal: I wanted to write a new script that would plot a horizontal line at the whole value above and below the current mark price. Actually for transparency, i want to plot 3 lines above and 3 lines below, but i can easily do that after doing the first two. So if the last mark price was $423.44, then I would want to draw a horizontal line at both $423.00 and $424.00. But I want to draw (plot) the line only for the current day even though I'm showing 20 days of data. I dont care where the lines would have been relative to other days. I only care about today's lines. So, if the price moves from $423.44 up through $424.00 and lands say at $424.15, then i would like to plot the lines now at $424.00 and $425.00. I want these lines to move with the CURRENT price as it moves up and down.
Along with reading some of the documentation and my research, I found a few golden nuggets to help me achieve some of my goals.
Get the Current Day so I could use If statements to only plot based on the current day
def isCurrentDay = if GetLastDay() == GetDay() then 1 else 0;
Plot the support and resistance lines only if it is the current day
Plot firstResistance = if iscurrentDay then Ceil(423.44) else Double.NaN;
firstResistance.setPaintingStrategy(paintingStrategy.HoRIZONTAL);
firstResistance.SetDefaultColor(Color.Red);
Plot firstSupport = if iscurrentDay then Floor(423.44) else Double.NaN;
firstSupport.setPaintingStrategy(paintingStrategy.HoRIZONTAL);
firstSupport.SetDefaultColor(Color.Green);
Ok, great, now I have my lines that only show up for the current day and they are right where i want them, but unfortunately I have a hard coded value of 423.44 in my examples. The next thing I needed was to find out the current price so my lines would redraw based on that current price. And like WTF, i can't for the life of me get the current price of the current Mark value of the current bar to fill in that hard coded value. I tried using this kind of stuff to get the values...
def isLastBar = !IsNaN(close) and IsNaN(close[-1]);
def LastKnownPrice = If isLastBar Then Ceil(close[0]) else Double.NaN;
Sure, it gets the value of the most recent bar, but since the charting gets painted from the left to the right, i dont know the latest bar value before i need it and obviously if i used the few lines above it will only draw the line if its the last bar. I need to know the current mark/close price back when the chart paints the first bar of that day. I also tried to use CompoundValue, but i dont think i was using it correctly. Does anyone have some advice on how to achieve my task? How do i get the current close/mark price regardless of Aggregation period, etc. Thanks in advance