Need help creating study that will plot high and low of FIRST Day of Month on chart

edited June 2016 in Charting

Im trying to write a study that will plot the high and low of the 1st trading day of each month. Ive been playing around a bit and thought using SetRst was the correct route to go so I tried converting an Opening Range indicator I use. So far I have this for the high plot ....

time:=SetRst(Month(@) <> Month(@)[-1] AND Day(@)<;>Day(@)[-1],Day(@)<;>Day(@)[-1]);
A:=time+ (time=0 AND time[-1]=1);
B:= BarsSince(A=0,1,400);
hi:= HiLevel(@,B,0);
hi WHEN Day(@) = Day(@)[-1];

......It starts plotting on the 1st trading day and continues for about 6 more trading days but then it just stops plotting. I really dont know the "A" variable from my Opening Range indicator is doing therefore im not sure if i should be using it as is from the original study. Also, if someone has a different approach im open to all suggestions. Any help would be appreciated. 



  • From one of our Product Specialists:

    I wrote a condition to mark first day of month.

    ( LocalMonth(@) <> LocalMonth(@)[-1])

    Wrote a study

    High: MaxPrd(@,1) WHEN ( LocalMonth(@) <> LocalMonth(@)[-1])

    Low: MinPrd(@,1) WHEN ( LocalMonth(@) <> LocalMonth(@)[-1])

    These mark the bar on a daily chart and put lines at the high and low.


  • Thank you for responding,

    3 things...

    The condition works correctly, but i cannot get the study to work. Im using the alpha platform not production so dont know if there might be an issue with that. When i created study on my system i created curves High and Low and inserted your  2 lines of code into each of there respective curves and only the low plots, plus the result is no where close. 

    Third thing is that i completely forgot to mention that i need to be able to apply this study to intraday timeframes.



  • Hi Dean,

    Here is some additional info from the Product Specialists:

    High(@),D when (LocalMonth(@)[0]<;>LocalMonth(@)[-1]

    For intraday first day of month high… it will plot 400 bars into the future which is a default in CQG.  The plotting starts on the start of the second day of the month.

  • Dean,

    Here are some more steps to take:
    • Right-click on the single study line your chart shows
    • Select Modify study
    • Under display, make the high and low curves different colors
    • Change "ShareScale" from "Auto" to "On" for both curves
    • Then apply
    Let me know if that helps!
  • Your 2nd version worked fine. I was also able to get your original version working. Had to change it around a bit.

    High: MaxPrd(@,1) WHEN ( LocalMonth(@) <> LocalMonth(@)[-1])

    What worked for me....
    High:= MaxPrd(High(@),1) WHEN ( LocalMonth(@) <> LocalMonth(@)[-1])

    I also realized my version was working all along. 

    The default 400 bar study calculation setting  was the culprit all along due to the fact that i was testing with a 5 minute chart.

    Thank you again,

  • Ok Dean, glad to hear it's working.
Sign In or Register to comment.