Gamestudio Links
Zorro Links
Newest Posts
MT5 bridge not working on MT5 v. 5 build 4160
by EternallyCurious. 04/25/24 20:49
Data from CSV not parsed correctly
by EternallyCurious. 04/25/24 10:20
Trading Journey
by howardR. 04/24/24 20:04
M1 Oversampling
by Petra. 04/24/24 10:34
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (EternallyCurious, AndrewAMD, TipmyPip, Quad), 889 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Mega_Rod, EternallyCurious, howardR, 11honza11, ccorrea
19048 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
TMF when price crosses an indicator #482485
02/13/21 20:24
02/13/21 20:24
Joined: Feb 2018
Posts: 25
1
1ND1G0 Offline OP
Newbie
1ND1G0  Offline OP
Newbie
1

Joined: Feb 2018
Posts: 25
I've been trying to write a very simple TMF that would exit Long trades when the current price (tick) crossed below any kind of moving average, but am not having much luck.

I can't seem to find any examples of this in the manual, as these functions are generally more about trade management - i.e. amending stop losses.

I am using 30 minutes bars in run function, so, for now, I have added the below into the main code, however as this is only called once every 30 minutes, I can see in my back-testing there are many examples where the price has not only gone through the moving average but by the time this is called and actioned, it is a much greater loss than it would have been if the trade was closed as soon as the price went through the MA:

if(crossUnder(Prices,ALMA))
exitLong();

I've also looked into tick() and tock() but not having any joy there either.

Last edited by 1ND1G0; 02/13/21 20:25.
Re: TMF when price crosses an indicator [Re: 1ND1G0] #482486
02/13/21 21:47
02/13/21 21:47
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Why are you trying to do this from a TMF when you could do it from run()? You could only acquire a series and crossover from run, so you might as well apply the info from run.

Use trade loops.

Re: TMF when price crosses an indicator [Re: 1ND1G0] #482487
02/13/21 22:03
02/13/21 22:03
Joined: Feb 2018
Posts: 25
1
1ND1G0 Offline OP
Newbie
1ND1G0  Offline OP
Newbie
1

Joined: Feb 2018
Posts: 25
Evening Andrew,

I thought that any logic I included in run() would only be triggered at the end of each bar, so in this example, I would only have the option of exiting a trade based on this condition every 30 minutes?

I was hoping that by using a TMF, or perhaps tick(), I could check for this particular exit criteria in real time, so that as soon as the asset price crossed under the moving average line, the trade would close.

Does that make sense? Apologies in advance if my explanation is still not clear.

Re: TMF when price crosses an indicator [Re: 1ND1G0] #482489
02/14/21 00:21
02/14/21 00:21
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Crossovers only happen once every 30 minutes at most.

And this criterion is only determined at run(). Therefore, it is appropriate to act on crossovers upon a run() call.

Re: TMF when price crosses an indicator [Re: 1ND1G0] #482493
02/14/21 15:30
02/14/21 15:30
Joined: Jul 2017
Posts: 784
Z
Zheka Offline
User
Zheka  Offline
User
Z

Joined: Jul 2017
Posts: 784
A solution more efficient than using a TMF or tick() would be to use a more granular BarPeriod (say, 1-min) and use TimeFrame=30 to build your "decision" price/indicator (MA) series.

priceClose(0) will then be a close of 1-min bar and you can check for the exit condition right in the run().


There might be some value in waiting for the close of a 30-min bar to crossover the MA before exiting a trade, but if you really, really want to close it "on-the-line" (and 1-min bar crossovers are not enough),
then just set/adjust TradeStopLimit=MA (in a trade loop).

Zorro will monitor the trade and exit accordingly.

Last edited by Zheka; 02/14/21 15:42.
Re: TMF when price crosses an indicator [Re: 1ND1G0] #482494
02/14/21 17:05
02/14/21 17:05
Joined: Feb 2018
Posts: 25
1
1ND1G0 Offline OP
Newbie
1ND1G0  Offline OP
Newbie
1

Joined: Feb 2018
Posts: 25
Many thanks, Zheka - most appreciated.

Re: TMF when price crosses an indicator [Re: 1ND1G0] #482522
02/17/21 13:40
02/17/21 13:40
Joined: Feb 2018
Posts: 25
1
1ND1G0 Offline OP
Newbie
1ND1G0  Offline OP
Newbie
1

Joined: Feb 2018
Posts: 25
Just a quick update on this - following on from Zhekas suggestion I did the following:

Set BarPeriod to 5minutes, then used TimeFrame = frameSync(12); for use in creating various indicators that represented a 60minute period (I found this more stable than the 30 minute periods I was using before). I could then also set TimeFrame = 1; so that I could use a faster price and frequency to check if this crossed my MA every 5 minutes rather than every 60.

Seems to be doing what I expect, however, I will continue to analyse my exits as not totally happy there yet.

Attached Files

Moderated by  Petra 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1