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
2 registered members (7th_zorro, 1 invisible), 942 guests, and 7 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
ThisTrade crashes test #483325
05/19/21 14:36
05/19/21 14:36
Joined: Apr 2021
Posts: 41
Slovakia
T
tomna1993 Offline OP
Newbie
tomna1993  Offline OP
Newbie
T

Joined: Apr 2021
Posts: 41
Slovakia
Hi,

I would like to assign trade pointer to ThisTrade when I enter a trade in tick function, but it crashes the test. I tried it two ways:
Code
function tick()
{
	if (LongSignal && (priceClose(0) >= LongSignalEntry) && !TradeIsOpen)
	{	
		Lots = ceil(RISK / ((LongSignalEntry - GridTakeProfit[0]) * POINT_CURRENCY_VALUE));
		TRADE* RunningLongTrade = enterLong(LongTradeManagement);
	}	


and
Code
function tick()
{
	if (LongSignal && (priceClose(0) >= LongSignalEntry) && !TradeIsOpen)
	{	
		Lots = ceil(RISK / ((LongSignalEntry - GridTakeProfit[0]) * POINT_CURRENCY_VALUE));
		ThisTrade = enterLong(LongTradeManagement);
	}	


I think now that I can't assign to ThisTrade the trade pointer in tick function, I did not try it in run function, but anyway it's no way I open trade in run (because of low timeframes I trade).
I use trade variables in run and in TMF functions and they work correctly but I read in manual I should set ThisTrade to be sure that trade variables have correct values. There is !TradeIsOpen which is checked before trade is open. What can I do in that situations? Create a global bool variable and use it till I open trade?

Re: ThisTrade crashes test [Re: tomna1993] #483326
05/19/21 14:46
05/19/21 14:46
Joined: Feb 2017
Posts: 1,726
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,726
Chicago
TradeIsOpen is invalid until you specify a trade.

Perhaps you should be checking one of the trade statistics instead.
https://zorro-project.com/manual/en/winloss.htm

Re: ThisTrade crashes test [Re: tomna1993] #483330
05/20/21 13:08
05/20/21 13:08
Joined: Apr 2021
Posts: 41
Slovakia
T
tomna1993 Offline OP
Newbie
tomna1993  Offline OP
Newbie
T

Joined: Apr 2021
Posts: 41
Slovakia
Thanks for the idea Andrew, I'll try it!
After I opened a position can I use trade variables without assigning the enterLong function to ThisTrade?

Re: ThisTrade crashes test [Re: tomna1993] #483331
05/20/21 13:20
05/20/21 13:20
Joined: Feb 2017
Posts: 1,726
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,726
Chicago
No. ThisTrade must be assigned in order for trade variables to work.

Also, if a trade fails, enterLong can return 0 (a null pointer). So if ThisTrade is assigned a null pointer, accessing trade variables can crash your script. Always check that enterLong returns a valid pointer before using the pointer.

Re: ThisTrade crashes test [Re: AndrewAMD] #483333
05/20/21 17:11
05/20/21 17:11
Joined: Apr 2021
Posts: 41
Slovakia
T
tomna1993 Offline OP
Newbie
tomna1993  Offline OP
Newbie
T

Joined: Apr 2021
Posts: 41
Slovakia
Ohh, that was the problem! Thank you for your help! Have a nice day!


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1