How to write basic trade information to file  [SOLVED]

Questions about MultiCharts and user contributed studies.
justme
Posts: 56
Joined: 08 Jan 2015
Has thanked: 9 times
Been thanked: 3 times

How to write basic trade information to file

Postby justme » 08 Jan 2015

Hi, I am new to MC. what is the cleanest way to write trade information to file, as it compiles in the chart?

I am looking for basic information, which can be found in existing functions. I am looking for something that will emulate the List of trades, found in performance summary. Just basic trade information:

Order#, Type, SignalName ,Date/Time, Price, Contracts

what does the code need to look like to produce a running file in the proper chronological order of entry/exit?

Thank you. Gordon

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

Re: How to write basic trade information to file

Postby TJ » 08 Jan 2015

Hi, I am new to MC. what is the cleanest way to write trade information to file, as it compiles in the chart?
I am looking for basic information, which can be found in existing functions. I am looking for something that will emulate the List of trades, found in performance summary. Just basic trade information:
Order#, Type, SignalName ,Date/Time, Price, Contracts
what does the code need to look like to produce a running file in the proper chronological order of entry/exit?
Thank you. Gordon
You can use the PRINT statement to output any data to an ascii file.

Check out the wiki for the relevant keywords for Order#, Type, SignalName ,Date/Time, Price, Contracts, etc.

justme
Posts: 56
Joined: 08 Jan 2015
Has thanked: 9 times
Been thanked: 3 times

Re: How to write basic trade information to file

Postby justme » 08 Jan 2015

Hi, I didn't explaining myself very well. I do know the functions and how to write to file, my issue is exactly how to I fire the code off, as it might be an exit that fired or it might have been an entry that fired. And I might have an exit and entry fire at the same time, how do I ensure that the trades are written in chronological order?

Thanks

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

Re: How to write basic trade information to file

Postby TJ » 08 Jan 2015

Hi, I didn't explaining myself very well. I do know the functions and how to write to file, my issue is exactly how to I fire the code off, as it might be an exit that fired or it might have been an entry that fired. And I might have an exit and entry fire at the same time, how do I ensure that the trades are written in chronological order?
Thanks
You can put the PRINT statement at all the critical points.

eg.

Code: Select all


If buy.condition = true then
BEGIN
Buy ("B") next bar at market;

PRINT...
END;

justme
Posts: 56
Joined: 08 Jan 2015
Has thanked: 9 times
Been thanked: 3 times

Re: How to write basic trade information to file

Postby justme » 08 Jan 2015

Thanks TJ, I am using stops, so I really can't code like you suggested. More or less, I will have to look for a change in TotalTrades, once that changes, then I know there is something to report. I can imagine something where I loop through the difference between TotalTrade and the prior Totaltrades, looking at EntryDateTime(x) and ExitDateTime(x), so then I know if I am dumping entryPrice or ExitPrice. But this seems very complicated and convoluted.

There really has to be a "simple" way to write to file so these trades are in chronological order.

Thanks again.
Gordon

User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: How to write basic trade information to file  [SOLVED]

Postby JoshM » 10 Jan 2015

Thanks TJ, I am using stops, so I really can't code like you suggested. More or less, I will have to look for a change in TotalTrades, once that changes, then I know there is something to report. I can imagine something where I loop through the difference between TotalTrade and the prior Totaltrades, looking at EntryDateTime(x) and ExitDateTime(x), so then I know if I am dumping entryPrice or ExitPrice. But this seems very complicated and convoluted.

There really has to be a "simple" way to write to file so these trades are in chronological order.
Just monitor whether there is an open position (while there wasn't previously), and vice versa. For example:

Code: Select all

Variables:
IntraBarPersist PrevMP(0),
MP(0);

MP = MarketPosition(0);

if (MP <> 0 and PrevMP = 0) then begin

Print("A new position has been opened");

if (MP > 0) then
Print(".. it's a long position")
else
Print(".. it's a short position");

end;

if (PrevMP <> 0 and MP = 0) then begin

Print("A position has been closed");

end;

PrevMP = MP;
For accessing trade (not position) information, there's a good Wiki article for that: Trades vs Orders With PosTrade Keywords.

justme
Posts: 56
Joined: 08 Jan 2015
Has thanked: 9 times
Been thanked: 3 times

Re: How to write basic trade information to file

Postby justme » 10 Jan 2015

Thanks Josh, much appreciated.


Return to “MultiCharts”