Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (ozgur, EternallyCurious, howardR, 1 invisible), 623 guests, and 0 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Trade management functions ( TMF ) #482089
12/22/20 14:55
12/22/20 14:55
Joined: Aug 2020
Posts: 59
London
Neb Offline OP
Junior Member
Neb  Offline OP
Junior Member

Joined: Aug 2020
Posts: 59
London

Hi,

I have a few issue with using TMF to set/change my stop losses or trail my profit.

1)

When I am using TMF to setup and move my SL, it is not setting up SL at all ?

int myTMF()
{

for(open_trades) {
if(TradeIsLong && TradeProfit>0) TradeStopLimit = max(TradeStopLimit, priceClose()-4*ATR(40));

else if(TradeIsShort && TradeProfit>0) TradeStopLimit = min(TradeStopLimit, priceClose()+4*ATR(40));

if(TradeStopLimit != 0) plot("Stop",TradeStopLimit,DOT|MAIN,BLUE);

}
return 0;
}


Picture attached.


2) As I found out, I can't use distance in TMF to set it up ?

This won't work ->

TradeStopLimit = 50*PIP;

It set my stop basically to the price value of 50, as my test shows.

3)

TradeStopLimit = priceClose()-4*ATR(40));

I found this to work, but problem is that it is going up and down and in long trade I want it to go only up or not to change once it has been setup.

4)

How I can setup trail, as it said I can't setup with distance in PIP.
How actually I am setting it up, if I want to use different TradeTrailLock, according to the level of profit ?

if (TradeProfit >0)
{
TradeTrailLock = 0.2
}
if (TradeProfit >0.05*Balance)
{
TradeTrailLock = 0.8
}


I am not great in programming, just learning, sorry

Thanks in advance !!

Neb

Attached Files TradeStopLoss.JPG
Re: Trade management functions ( TMF ) [Re: Neb] #482090
12/22/20 16:18
12/22/20 16:18
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Never run trade loops inside a TMF, unless you have a very good reason to! (This is not one of them.)

Also, I assume you correctly assigned a TMF to a trade. Did you do that? This happens when you call enterLong(myTMF) or enterShort(myTMF).

Re: Trade management functions ( TMF ) [Re: AndrewAMD] #482091
12/22/20 16:45
12/22/20 16:45
Joined: Aug 2020
Posts: 59
London
Neb Offline OP
Junior Member
Neb  Offline OP
Junior Member

Joined: Aug 2020
Posts: 59
London
Hi Andrew,

Thanks for quick reply !!!

You meant about for {} loop ?
Ok !
Actually it is redundant I suppose, cause I've been calling for all open trades and then again checking if trade is long or short.

I did call enterLong(myTMF) and enterShort(myTMF) inside run{}, as it was in one of the examples. Is that ok or ... ?

Thanks !

Re: Trade management functions ( TMF ) [Re: Neb] #482092
12/22/20 17:09
12/22/20 17:09
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Yes and yes.

The TMF answers the question: "I have this trade open. What do I do with it?"

A trade loop such as for(open_trades) explicitly iterates through all open trades, which is a different way to handle trades or get information about them. Normally, you'd execute this from run() or tick().

Re: Trade management functions ( TMF ) [Re: AndrewAMD] #482093
12/22/20 17:12
12/22/20 17:12
Joined: Aug 2020
Posts: 59
London
Neb Offline OP
Junior Member
Neb  Offline OP
Junior Member

Joined: Aug 2020
Posts: 59
London
Thanks , got it !


And instead of using Trail, what actually not work inside TMF, i can use something like this:

if(TradeProfit>0.03*Balance && TradeIsLong)
{
TradeStopLimit = max(0.5*(TradePriceClose-TradePriceOpen), TradePriceClose-3*ATR(25));
plot("Stop",TradeStopLimit-10*PIP,MINV,BLUE);
}
if(TradeProfit>0.03*Balance && TradeIsShort)
{
TradeStopLimit = min(0.5*(TradePriceOpen-TradePriceClose), TradePriceClose+3*ATR(25));
plot("Stop",TradeStopLimit+10*PIP,MAXV,RED);
}


Last edited by Neb; 12/22/20 17:12.
Re: Trade management functions ( TMF ) [Re: Neb] #482094
12/23/20 01:58
12/23/20 01:58
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
I don't think it works to call plot() from a TMF.
Quote
If plot is called several times with the same Name in the same run cycle, only the last data value is plotted.
https://manual.zorro-project.com/plot.htm

More importantly, why are you using the value TradePriceClose when it is impossible to know what TradePriceClose is because your trade is still open? Use priceClose() instead.

Re: Trade management functions ( TMF ) [Re: AndrewAMD] #482095
12/23/20 10:37
12/23/20 10:37
Joined: Aug 2020
Posts: 59
London
Neb Offline OP
Junior Member
Neb  Offline OP
Junior Member

Joined: Aug 2020
Posts: 59
London
Hi Andrew,

It works, at least I was using it only to see how my SL was moving (debugging steps)
But generally, I can delete it.

Re TradePriceClose manual says:

https://zorro-project.com/manual/en/trade.htm

"If the trade is still open, it's the current price of the asset or contract".

So, this is why I was using it laugh

Re: Trade management functions ( TMF ) [Re: Neb] #482097
12/23/20 12:09
12/23/20 12:09
Joined: Aug 2020
Posts: 59
London
Neb Offline OP
Junior Member
Neb  Offline OP
Junior Member

Joined: Aug 2020
Posts: 59
London


Can I use optimize() and how inside TMF function ?
I would like to see where is the most optimal to move my SL ?
Or you maybe suggest to plot MAE and price profile ?

Thanks,

Neb

Re: Trade management functions ( TMF ) [Re: Neb] #482098
12/23/20 13:48
12/23/20 13:48
Joined: Feb 2017
Posts: 1,725
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,725
Chicago
Originally Posted by Neb
"If the trade is still open, it's the current price of the asset or contract".

So, this is why I was using it laugh
I think you're right!
Originally Posted by Neb
Can I use optimize() and how inside TMF function ?
I would like to see where is the most optimal to move my SL ?
Or you maybe suggest to plot MAE and price profile ?

Thanks,

Neb
Call optimize() in run(). If you need the optimized values in your TMF, share the return value from optimize() with your TMF, such as with a global value, AssetVar, or TMF parameter., i.e. enterLong(myTMF, parameter1, parameter2, ...).

Re: Trade management functions ( TMF ) [Re: AndrewAMD] #482146
01/03/21 16:55
01/03/21 16:55
Joined: Aug 2020
Posts: 59
London
Neb Offline OP
Junior Member
Neb  Offline OP
Junior Member

Joined: Aug 2020
Posts: 59
London
Thanks Andrew !

Much appreciated !

Neb

Page 1 of 2 1 2

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1