Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (dr_panther, Quad, AndrewAMD, 7th_zorro), 945 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
TradeProfit while TradeIsClosed #454908
09/28/15 23:06
09/28/15 23:06
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline OP
User
Sphin  Offline OP
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
I've seen other codes in here where it should work, but:

Code:
int TradeLong() {
   if (TradeIsClosed) {
      print(TO_LOG,"\nTradeProfit: %.2f",TradeProfit);
   }
}

...
enterLong(TradeLong);
...


produces:

Code:
[668: Mon 06.01.14 15:45]  +1 +0 2/0
TradeProfit: 0.00
[EUR/USD::L6502] Target 1@1.3639: +0.89 at 15:47


Is it normal that TradeProfit is no more available when the trade is closed?

Thanks, Sphin

Re: TradeProfit while TradeIsClosed [Re: Sphin] #454922
09/29/15 10:35
09/29/15 10:35
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
If the trade were really closed, TradeLong would not be executed anymore and thus nothing would be printed. I wonder why you get a printout at all. For the parameters of closed trades you normally need a for(all_trades) loop.

Can you post that script or send it to support? I'd like to check where this mysterious print comes from.




Re: TradeProfit while TradeIsClosed [Re: jcl] #454925
09/29/15 14:37
09/29/15 14:37
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline OP
User
Sphin  Offline OP
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
It's a bit crazy. If I'm right, the use of the TMF should not change anything concerning trading bevaviour, or does it? I thought to use it for documentation purposes only. But if I take the simple script

Code:
int TradeLong() {
   if (TradeIsClosed) {
      print(TO_LOG,"\nTradeProfit: %.2f",TradeProfit);
   }
}

function run()
{
        set(LOGFILE+TICKS)
	vars Price = series(price());
	vars Trend = series(LowPass(Price,500));
	
	Stop = 4*ATR(100);
	TakeProfit = 10*PIP;

	if(valley(Trend) && NumOpenLong == 0) 
		enterLong(TradeLong);
}



and run it with "enterLong(TradeLong)" and then compare it with "enterLong()" without the TMF, the behaviour of the script changes and it does really strange things when using the TMF. BTW: TakeProfit seems to be necessary to provoke the printing of TradeProfit to the Log.

Re: TradeProfit while TradeIsClosed [Re: Sphin] #454993
10/01/15 11:58
10/01/15 11:58
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
The trade is not yet closed. If it were closed, the TMF would not run anymore. The profit of trades is only known _after_ they are really closed, so you can retrieve it in a for(all_trades) loop.

The last run of a TMF happens between hitting the stop and closing the trade. This is here the case. So at that time the trade is still open, despite the triggered stop. I suppose its profit is therefore still unknown, that's why you get no value. I can also not see with your script any difference with and without TMF. In both cases the end profit is +92 pips.

Re: TradeProfit while TradeIsClosed [Re: jcl] #454994
10/01/15 12:59
10/01/15 12:59
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline OP
User
Sphin  Offline OP
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
That's strange. For comparism reason I added to my script:

Code:
LookBack=200;
StartDate = 2009;
EndDate = 2015;



From the select box I choose EUR/USD and ran one test with

enterLong(TradeLong);

and Zorro said: Annual +20% +122p

and then I ran one test with

enterLong();

and Zorro said: Annual +5% +31p

In my opinion this is a difference. My Zorro version is 1.34.1.

Re: TradeProfit while TradeIsClosed [Re: Sphin] #454997
10/01/15 13:15
10/01/15 13:15
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Are you using the TICKS flag? Try 1.36 and let me know if you then still have the problem. There is a bug listed for 1.34 with the TICKS flag and TMFs - that might be the reason of your difference. If you still have the same problem with 1.36, please let me know - I'll then check that again.

- Update: I just notice a bug in your printf statement - you're printing a float instead of a var. So your printout can not work anyway - see remarks under "Trade Mangement Functions" in the manual.

Re: TradeProfit while TradeIsClosed [Re: jcl] #454998
10/01/15 13:40
10/01/15 13:40
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline OP
User
Sphin  Offline OP
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
Yes, I used ticks and indeed 1.36 shows "Annual +6% +40p" at the end of both versions. Must be the bug described.

Re: TradeProfit while TradeIsClosed [Re: Sphin] #454999
10/01/15 13:42
10/01/15 13:42
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It's still strange because I got +92p with your script. Or have you changed something, f.i. downloaded newer prices?

Re: TradeProfit while TradeIsClosed [Re: jcl] #455004
10/01/15 15:45
10/01/15 15:45
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline OP
User
Sphin  Offline OP
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
Okay, if I trade exactly the script from entry #3 in this thread (with a semikolon at the end of 'set(LOGFILE+TICKS)' of course) without the modifications from entry #5 and using the EURUSD_X.bar files from the zip archive of 1.36 I get 'Annual +21% +83p' both with and without the TMF. It's really near to your +92p but anywhere in between there are 9 PIPs lost ...

Re: TradeProfit while TradeIsClosed [Re: Sphin] #455089
10/08/15 20:47
10/08/15 20:47
Joined: Dec 2013
Posts: 568
Fuerth, DE
Sphin Offline OP
User
Sphin  Offline OP
User

Joined: Dec 2013
Posts: 568
Fuerth, DE
From the manual:

Quote:
TradeProft: The current profit or loss of the trade in units of the account currency, including costs such as spread, rollover, slippage, and commission.


In this context your statement

Quote:
The profit of trades is only known _after_ they are really closed


confuses me a little because I unterstand the manual's "current" as if TradeProfit shows the actual profit of a trade at any time during the trade. What is right?


And concerning

Quote:
Update: I just notice a bug in your printf statement - you're printing a float instead of a var.


I think I tried to print a var. From the manual:

Quote:
For printing float variables with the %f placeholder, typecast them to (var).


Should I better use

Code:
print(TO_LOG,"\nTradeProfit: %.2f",(var)TradeProfit);



if TradeProfit is a float?

Page 1 of 2 1 2

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