|
4 registered members (JimSimons, TipmyPip, 3run, 1 invisible),
15,917
guests, and 1
spider. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
TMF when price crosses an indicator
#482485
02/13/21 20:24
02/13/21 20:24
|
Joined: Feb 2018
Posts: 25
1ND1G0
OP
Newbie
|
OP
Newbie
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]
#482493
02/14/21 15:30
02/14/21 15:30
|
Joined: Jul 2017
Posts: 788
Zheka
User
|
User
Joined: Jul 2017
Posts: 788
|
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.
|
|
|
|