Hi there,
I want to write a very simple script for myself and hoping you can help me with.
I would like to draw a horizontal line on closing price of monthly, weekly and daily bases. The horizontal line start with end of month, week or day closes price and continue till next date to change. for example horizontal line for month of Sep is closes price on 31th Aug and end on 30 the Sep - new horizontal line generated for closes price on 30th Sep then continue for month of Oct. - same for weekly and daily chart
Majid Ghasemian
Hi,
If you are just starting out with scripting i’d highly recommend checking out the free courses first, before going any further. They will answer a lot of the questions you’ll have early on and make the setup process much quicker.
https://learn.optuma.com/scripting-courses/
With your specific example what you are after can be done using the Show Plot tool and a multi-plot script…
//Set the 3 plots V1 = CLOSE() ; V2 = CLOSE(Week(PERIODAMOUNT=1), OFFSET=1) ; V3 = CLOSE(Month(PERIODAMOUNT=1), OFFSET=1) ; //Display the 3 plots plot1 = v1; plot1.Colour = Black; plot2 = V2; plot2.Colour = Green; plot3 = V3 ; plot3.Colour = Red;
Each variable is using the Close function, but with different time frame overrides (Week, Month, etc) and then uses a 1 bar offset to make sure it’s the previous value being plotted.
Here is an example of how it looks on a daily chart:
Thanks for your prompt response, mate
I am looking for something cleaner, just to draw trend line and between the horizontal line too,
see attached
Hi,
The original script can be adjusted to display in a similar way to your screen shot. Just drop the daily plot and change the colours for the remaining two lines.
V2 = CLOSE(Week(PERIODAMOUNT=1), OFFSET=1) ; V3 = CLOSE(Month(PERIODAMOUNT=1), OFFSET=1) ; plot1 = V2; plot1.Colour = red; plot1.Plotstyle = Step; plot2 = V3 ; plot2.Colour = Aqua; plot2.LineWidth = 2; plot2.Plotstyle = Step;
Screen Shot:
Perfect, mate
Thanks a lot
I have couple of questions, here
- how is it possible to make scanner to show when red or green "show bar" turns to green or red.
- Is it possible to have only first show bar and not seen other until it changes
I want to write a scanning script to highlight on first red or green arrow -
red for selling short and green for buying long
as first entry would be best entry - my current scanning script pick up all the stocks - basically looking for script to pick when red arrows turns to green or vis versa
This is a perfect example - when green arrow just change to red arrow - my arrows scripts as follow
V1 = CLOSE(day(PERIODAMOUNT=1), OFFSET=1) ; V2 = CLOSE(Week(PERIODAMOUNT=1), OFFSET=1) ; V3 = CLOSE(Month(PERIODAMOUNT=1), OFFSET=1) ; close() > V1 and V1 > V2; and MACD(BAR1=12, BAR2=26, OSC=9).Histogram >= 0
V1 = CLOSE(day(PERIODAMOUNT=1), OFFSET=1) ; V2 = CLOSE(Week(PERIODAMOUNT=1), OFFSET=1) ; V3 = CLOSE(Month(PERIODAMOUNT=1), OFFSET=1) ; (close() < V1 or V1 < V2) and MACD(BAR1=12, BAR2=26, OSC=9) <= 0
Hi Majid,
Try changing the criteria from V1 > to V2 to V1 CrossesAbove V2 to get the signal:
V1 = CLOSE(day(PERIODAMOUNT=1), OFFSET=1); V2 = CLOSE(Week(PERIODAMOUNT=1), OFFSET=1); V3 = CLOSE(Month(PERIODAMOUNT=1), OFFSET=1); CLOSE() > V1 and V1 CrossesAbove V2 and MACD(BAR1=12, BAR2=26, OSC=9).Histogram >= 0
Also, when pasting a script formula in the forum please see this pinned post:
https://forum.optuma.com/topic/how-to-add-code-samples-to-forum-posts/