Please help - code to make trade in specific year  [SOLVED]

Questions about MultiCharts and user contributed studies.
Airke07
Posts: 10
Joined: 20 Apr 2021

Please help - code to make trade in specific year

Postby Airke07 » 03 Jun 2023

Hello Community!

Please help this very simple part of the code to just start executing trades after May 18, 2023. The "year" part is obviously not working. I am not a coder and super frustrated of why Multicharts can't understand the simple 2023 :)

Can somebody just show me how to make this little part of the code work? Greatly appreciate your help!!! Thanks, many thanks!

Inputs:
StartDay (18),
StartMonth (5),
StartYear (2023);

if (Dayofmonth(Date)>=StartDay) and (Month(Date)>=StartMonth)and(Year(Date)=StartYear) Then Buy this bar on close;
if close > close [1] Then Sell this bar on close;

Regards,
Airke

User avatar
rrams
Posts: 128
Joined: 10 Feb 2011
Location: USA
Has thanked: 7 times
Been thanked: 70 times
Contact:

Re: Please help - code to make trade in specific year

Postby rrams » 03 Jun 2023

Airke07,

The PowerLanguage date and time routines are based on legacy UNIX "Posix" structure and are thus not completely intuitive to remember. Hence, it is best to make a link to the MultiCharts64.chm help file in the MultiCharts directory and keep that open to search for the proper keyword to use to convert dates.

The year keyword returns a three number code referring to the last two year numbers and beginning with a digit indicating zero for the 20th century "1900-1999" or one for the 21st century "2000-2099".

So your StartYear variable should hold 123 not 2023.

A better way to write this code would be like this:

Code: Select all

if D>=JulianToDate(StringToDate("05/18/2023")) then Buy this bar on close;

Airke07
Posts: 10
Joined: 20 Apr 2021

Re: Please help - code to make trade in specific year  [SOLVED]

Postby Airke07 » 04 Jun 2023

Hi Rrams,

Thank you so much for the input. I tried and the code definitely works. But it was critical for me to have the dates as inputs, so that I can change the day every week (as per my strategy). Now I am figuring how to do that, since in the working code there is no inputs :)) But thank you so much anyway, something new to think about now..

Airke
Airke07,

The PowerLanguage date and time routines are based on legacy UNIX "Posix" structure and are thus not completely intuitive to remember. Hence, it is best to make a link to the MultiCharts64.chm help file in the MultiCharts directory and keep that open to search for the proper keyword to use to convert dates.

The year keyword returns a three number code referring to the last two year numbers and beginning with a digit indicating zero for the 20th century "1900-1999" or one for the 21st century "2000-2099".

So your StartYear variable should hold 123 not 2023.

A better way to write this code would be like this:

Code: Select all

if D>=JulianToDate(StringToDate("05/18/2023")) then Buy this bar on close;


Return to “MultiCharts”