Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (AndrewAMD, Ayumi), 1,405 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Using the open_trades enumeration loop #430806
10/02/13 15:15
10/02/13 15:15
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
Hi there,
I would like to examine the open trades' open price and set a variable. Whenever I add this code the SCRIPT CRAASHES
The code works until a trade is actually opened. And it doesn't work in a called function.
Where am I going wrong?

if(TradeIsOpen) {
for(open_trades){
if(TradePriceOpen>CheckPivotH) {
CheckPivotH=TradePriceOpen;
}
if(TradePriceOpen<CheckPivotL) {
CheckPivotL=TradePriceOpen;
}
}
}
Thanks
P

Last edited by Pork; 10/02/13 15:17.
Re: Using the open_trades enumeration loop [Re: Pork] #430812
10/02/13 17:06
10/02/13 17:06
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi Pork,

TradeIsOpen is a trade variable, so it's designed to be accessed within the open_trades loop (or a TMF) for each trade, not outside the loop. You may be confusing it with NumOpenTotal, which is a global variable...

HTH.

Re: Using the open_trades enumeration loop [Re: DdlV] #430818
10/02/13 18:00
10/02/13 18:00
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
Thanks Ddlv, but NumOpenTotal also crashes. BTW v1.16
I also thought maybe look back might be causing it.
But removing that also didn't help.
It will work until the trade is opened, or until the comparison is true.
I thought maybe it was the TradeOpenPrice inside the loop, but the manual says that should work.
The loop is inside the run() function, but I tried it in it's own function and that didn't work either.
How should one retrieve the open price for each trade if multiple trades are open?
I can probably create an array and move the price when a trade is opened.
I'm stuck again.
Thanks
P

Re: Using the open_trades enumeration loop [Re: Pork] #430819
10/02/13 18:16
10/02/13 18:16
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
I read about the trade* pointer, will have to try that in a loop.
P

Re: Using the open_trades enumeration loop [Re: Pork] #430821
10/02/13 18:24
10/02/13 18:24
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
It's difficult to give advices without knowing your script. DdlV told you why your code above won't work, but we can't know what other crashes are in the rest of your script.

There are many, many ways to write code that crashes. A crash is often obvious, but if you can't immediately see it in the script, comment out parts until you found the line that crashed. Then examine the line and its context - the most frequent crash reason is an empty pointer.

Re: Using the open_trades enumeration loop [Re: jcl] #430830
10/02/13 20:20
10/02/13 20:20
Joined: Jun 2013
Posts: 1,609
D
DdlV Offline
Serious User
DdlV  Offline
Serious User
D

Joined: Jun 2013
Posts: 1,609
Hi Pork,

To answer your specific question, for(open_trades) loops through all Pending and Open trades. The Pending ones won't have a TradePriceOpen yet (use TradeIsOpen to bypass them), but the Open ones will.

Re. the crash, as jcl says it's pretty hard to debug a script without seeing all of it. If you don't want to post it follow the debug advice and narrow it down to what's causing the crash.

HTH.

Re: Using the open_trades enumeration loop [Re: DdlV] #430847
10/03/13 12:17
10/03/13 12:17
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
Thanks Guys, you did it again. Don't know what I would do without you.
I've attached a test file for you with appropriate commenting, sorry I didn't do it before.
But it comes down to these lines:

if(NumOpenTotal>0){
for(open_trades) {
...
...
}}

if(NumOpenTotal>0) {
//the following is the offending line that crashes the script. however it doesn't crash if open_trades is commented out. It also works the other way. If this line is commented out the open_trades line will not crash the script, but they don't appear to work together. shocked

if(TradeIsShort) {
...
...
}}

Thanks Again
P

Attached Files
atest2.zip (34 downloads)
Re: Using the open_trades enumeration loop [Re: Pork] #430851
10/03/13 13:11
10/03/13 13:11
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
This is still the same problem - you're still using trade variables like "TradeIsShort" or "TradeIsLong" outside the context of a trade.

Trade variables belong to a trade, they make no sense without. So you can not use them outside a TMF or an open_trades loop. This even crashes your script because you're reading from a nonexistent pointer.

Maybe you were confusing the "TradeIsShort" or "TradeIsLong" variables with something else? What did you want to do with them?

Re: Using the open_trades enumeration loop [Re: jcl] #430859
10/03/13 15:56
10/03/13 15:56
Joined: Jun 2013
Posts: 41
Ohio, USA
P
Pork Offline OP
Newbie
Pork  Offline OP
Newbie
P

Joined: Jun 2013
Posts: 41
Ohio, USA
OK. Great. Thank You.
I think I have it.
1. I can't have an open_trades loop without checking to be sure there is an open trade.
2. I have to use a global variable NumOpenTotal to check for open trades not a "trade variable" (TradeisOpen).
3. Pending trades don't have a TradePriceOpen, so I can only check that after checking the "TradeisOpen" trade variable.
4. I can't check any trade variables without doing so in either an open_trades loop or a separate "trade management function" (TMF).
so the correct sequence is:

if(NumOpenTotal>0)
for(open_trades)
if(TradeIsOpen)
perform some task
if TradeisLong
perform task #2
if TradeIsShort
performtask #3
endfor
endif

or maybe
if(NumOpenTotal>0)
performtmf();
then place the code including the open_trades loop in the performtmf function

Thanks again
P

Re: Using the open_trades enumeration loop [Re: Pork] #430879
10/04/13 10:13
10/04/13 10:13
Joined: Jul 2000
Posts: 27,986
Frankfurt
jcl Offline

Chief Engineer
jcl  Offline

Chief Engineer

Joined: Jul 2000
Posts: 27,986
Frankfurt
Almost correct, only the if(NumOpenTotal) is unnecessary, as this is handled by the loop anyway. You can find several examples of open_trades loops in the manual.

Whether to handle trades in loop or in a TMF depends on if you need to run the task once per bar or at every price tick.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1