Using print for signals

Questions about MultiCharts and user contributed studies.
odrk
Posts: 4
Joined: 15 Aug 2018

Using print for signals

Postby odrk » 21 Aug 2018

I am trying to use the print-function to print some information to a file that a py-script will interpretate.

Right now it goes something like:

Code: Select all

condition1 = open[7] <= close[8] and high[4] > open[6];
if condition1 and long_on <> 1 then sellshort ("SE") 1 contract next bar open;
if marketposition = -1 then Print(File("C:\users\odrk\Desktop\name-enter-short.txt"),CurrentDate,CurrentTime);
if marketposition = -1 and barssinceentry >= holding_time-1 then sell ("timeX") all contracts next bar open;
if marketposition = 0 then Print(File("C:\users\odrk\Desktop\name-short-cover.txt"),CurrentDate,CurrentTime);

This returns the date and the time the short signal was triggered as expected, but the second print-statement writes an entry for every bar that a short position is not on. What I would like it to do is to print the date and time that the short was covered, otherwise I end up with a file with a lot of time stamps in it, most of them are not of interest.

Does anyone have any suggestions on how to do that?

Thanks in advance!
Last edited by odrk on 21 Aug 2018, edited 1 time in total.

odrk
Posts: 4
Joined: 15 Aug 2018

Re: Using print for signals

Postby odrk » 21 Aug 2018

Ok looked into this a bit further. It prints every bar it is in a short position and every time it is not. Clearly I am very wrong. What I would like is to have it print the date and time for the short entry and then the date and time for the short cover

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Using print for signals

Postby TJ » 21 Aug 2018

See post #1 & post #2
viewtopic.php?t=11713

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Using print for signals

Postby ABC » 22 Aug 2018

Hi odrk,

you wrote your code to print when "MarketPosition = -1" i.e. short and when "MarketPosition = 0" i.e. flat.. The best way to tackle this will depend a bit on how your systems trades, for example if it only evaluates trades at the end of the bar and never exits on the same bar as an entry you could store the Marketposition in a variable (for example vMarketPosition) and then use something along the lines of the below code to identify the entry and exit bars:

Code: Select all

vMarketPosition = MarketPosition ;

if vMarketPosition < vMarketPosition[1] then ... //the system is now short

if vMarketPosition = 0 and vMarketPosition[1] < 0 then... //the system is now flat from being short
Regards,

ABC

odrk
Posts: 4
Joined: 15 Aug 2018

Re: Using print for signals

Postby odrk » 28 Aug 2018

Hi ABC,

Thank you for your help.

The only issue with this solution is that since I use

Code: Select all

if condition1 and long_on <> 1 then sellshort ("SE") 1 contract next bar open;
and

Code: Select all

if marketposition = -1 and barssinceentry >= 3 then buyToCover("SX") all contracts next bar open;
I will only get the time/date printed one bar after the position was opened/closed, e.g. if 15 minute candles are used the short positon will be entered 09:00 but the entry in the text file will be made 09:15 but it will read "09:00" (the same for the exit).

It would be ideal if PRINT to be active as soon as the positioned is entered and as soon as the position is closed, instead of waiting for the bar to close

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: Using print for signals

Postby ABC » 28 Aug 2018

Hi odrk,

when prints appear depends on when the conditions for the prints are valid and when your code gets executed. If your strategy only computes end of bar, the prints could only appear at the end of the bar. You can take a look at the IntrabarOrderGeneration attribute for a way of executing strategies tick by tick.

Regards,

ABC

odrk
Posts: 4
Joined: 15 Aug 2018

Re: Using print for signals

Postby odrk » 28 Aug 2018

Yeah sure, but this strategy computes at the open of the next bar (lets call this bar X), and then PRINT only computes on the close of X. This means that there is a a lag between them. I would like PRINT to compute the same moment as the short position is entered, not at the close of bar X


Return to “MultiCharts”