EXITRUN only in simulations?

Posted By: Sphin

EXITRUN only in simulations? - 06/29/18 15:21

Trying to collect some information while trading and saving them after finishing the strategy, mostly done by pressing the Stop button. I thought this could be done in a for(all_trades) loop in EXITRUN but surprisingly this does not work.
Quote:
EXITRUN
Last run of the simulation. All trades are closed. [...]

Really only in simulations? Is there any function to use in live trading?
Posted By: Hredot

Re: EXITRUN only in simulations? - 06/30/18 01:52

If you know how long trading sessions take, you could use dataNew, dataAppendRow, dataSet and e.g. in half an hour intervals dataSave. Then roughly note the session start time and make sure to hit Stop only after the last half an hour has been dumped.
Posted By: Sphin

Re: EXITRUN only in simulations? - 06/30/18 11:21

Thanks, but the for(all_trades) loop itself is okay, my intention was more finding a trigger to execute it if trading of the strategy is stopped.
Posted By: Hredot

Re: EXITRUN only in simulations? - 06/30/18 12:17

I see, here is a hacky way:

Code:
...
if(file_date("your\path\stop.txt")>0){
    ... save data here ...
}
...



Create stop.txt shortly before stopping the script, and delete it right after.
Posted By: Sphin

Re: EXITRUN only in simulations? - 06/30/18 16:35

Quick and dirty, I use a lot of such solutions!

Quote:
Create stop.txt shortly before stopping the script, and delete it right after.

Hmm ... but instead of creating the stop.txt shortly before stopping the script I could also execute the for(all_trades) loop - if I only knew when the time is "shortly before stopping the script" but this is the time in question.
Posted By: Hredot

Re: EXITRUN only in simulations? - 06/30/18 17:26

Simplest solution would be of course, if you know exactly how long and at what hours of day the trading session starts and ends. Then you could execute the for(all_trades) loop e.g. exactly at market close time and just make sure to hit Stop a minute or two later.
Posted By: Sphin

Re: EXITRUN only in simulations? - 06/30/18 18:50

Simplest solution would be an 'onStop event handler' or making EXITRUN available also in trade mode. The evaluate (PERFORMANCE* perf) would be a possible workaround but in trade mode it is executed when the status page is updated, only in test mode at the end of a test or when Result is clicked. An onResultClick event in trade mode was also a viable way ...
Posted By: Hredot

Re: EXITRUN only in simulations? - 06/30/18 19:12

I agree, ideally they should implement this in Zorro so people don't have to do ritual dances around it to get it to work.
Posted By: Petra

Re: EXITRUN only in simulations? - 07/01/18 13:33

I hope they dont, because when I hit stop I want it to stop, not to start another run. There must be a better solution.
Posted By: Sphin

Re: EXITRUN only in simulations? - 07/01/18 13:44

Why start another run? if(is(EXITRUN)) is a trigger to execute some commands after the simulation. My intention is to make it or any substitute available not only in test but also in trade mode. It has nothing to do with restarting the run.
Posted By: Petra

Re: EXITRUN only in simulations? - 07/01/18 14:10

No, Exitrun is a flag that is set when Zorro starts its last run:

http://manual.zorro-project.com/is.htm

When you hit stop you want no exit run. Imagine the script places wrong trades or the market crashes, so you hit stop, then you dont want it to continue for another run.
Posted By: MatPed

Re: EXITRUN only in simulations? - 07/01/18 14:56

Originally Posted By: Petra
I hope they dont, because when I hit stop I want it to stop, not to start another run. There must be a better solution.


Hi Petra,
Can you explain why having a function activated pressing the STOP button pressed should be a bad thing?
I do not get it. Thank You
Posted By: Petra

Re: EXITRUN only in simulations? - 07/01/18 15:39

You think its no bad thing when Stop starts another run with possibly new trades? You must be very rich! laugh laugh
Posted By: Hredot

Re: EXITRUN only in simulations? - 07/01/18 15:47

EXITRUN should be special, where only functions wrapped in if(is(EXITRUN)){...} get executed. There, problem solved.
Posted By: MatPed

Re: EXITRUN only in simulations? - 07/01/18 16:06

Originally Posted By: Petra
You think its no bad thing when Stop starts another run with possibly new trades? You must be very rich! laugh laugh


that's not an answer. If you have a function you can use it well, wrong or do not use it at all.
Posted By: Sphin

Re: EXITRUN only in simulations? - 07/01/18 16:59

To give an example, what I'm doing is simply:
Code:
if(is(EXITRUN)) 		
  	for(all_trades) 
  		print(TO_CSV, "%s, %s, %.1f, %.2fn", strdate("%y%m%d %H:%M:%S", TradeEnterTime), Asset, SpecialKey, TradeProfit);


Means after the last run Zorro prints to CSV each trade together with a special key number (TradeVar). No restart of run or what ever, only printing trade results to CSV.

Or like MatPed said: you are not forced to use this function.
Posted By: Spirit

Re: EXITRUN only in simulations? - 07/01/18 22:34

I think the chance of such a "feature" is zero, because it would be not backwards compatible and users would not expect that a button named "stop" starts a new run. Why not using simply the evaluate or cleanup function?
Posted By: Sphin

Re: EXITRUN only in simulations? - 07/02/18 16:01

Quote:
users would not expect that a button named "stop" starts a new run

No one would expect it, me neither.

Quote:
Why not using simply the evaluate or cleanup function?

With pleasure. Could you please give me a hint how to call a function after the end of trading the with the evaluate function?

Quote:
From the manual:
For globally allocated memory areas, define a void cleanup() function that releases memory. The function will be automatically called at end or termination of the session.

Does this work:
Code:
void cleanup() {
   for(all_trades) 
  	print(TO_CSV, "%s, %s, %.1f, %.2fn", strdate("%y%m%d %H:%M:%S", TradeEnterTime), Asset, SpecialKey, TradeProfit);
}

Posted By: Sphin

Re: EXITRUN only in simulations? - 07/03/18 16:23

Amazing, with cleanup() at least a "hello-world-csv" is created when the stop button is hit. If the trade history is still present this moment I can indeed use it as a workaround for EXITRUN in trade mode.
© 2024 lite-C Forums