Gamestudio Links
Zorro Links
Newest Posts
New Zorro version 2.30
by Zheka. 08/03/20 15:24
script CurrencyStrength
by jcl. 08/03/20 14:01
Moving Panels together
by Aku_Aku. 08/03/20 12:22
Why gamestudio USE Lite_C
by txesmi. 08/03/20 11:49
Price clusters
by jcl. 08/03/20 10:04
Zorro.exe return codes
by jcl. 08/03/20 09:41
objective - based to DD
by Grat. 08/03/20 05:14
AUM Magazine
Latest Screens
The Space Between
Pogostuck: Rage With Your Friends
Worst Case Z
AckCon'18 - Lotter vs the World 2 - Preview Release
Who's Online Now
8 registered members (aariassanta, deepscreener, exile, AndrewAMD, Jerome8911, Dooley, Zheka, 1 invisible), 469 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Al82, Alibert, jsch, daan, TianYu
18487 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: Increasing Lots Size [Re: Qw3rty] #480922
07/24/20 13:38
07/24/20 13:38
Joined: Feb 2017
Posts: 1,062
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,062
Chicago
Originally Posted by Qw3rty
I would like to reset the counter or Lot size to 1 for a specific condition when Equity has reached a new high by $X.
Your code is not measuring Equity. Use Zorro's Equity variable to check for new maximums. Ideally, this should be a global variable or static var.

If you declare var Count inside of run, Zorro will forget its value every time another bar arrives. So don't do that. This should also be a global variable or static var.

Originally Posted by Qw3rty
What I am trying to achieve is when a trades loses I increase the lot size BUT if the trade wins I might want to increase the lot size depending on if the Equity has reached a new high by X dollars.
All trades are losing from the moment they are entered because of commission and spread, so you need establish a better definition of "losing trade". You're not monitoring this.

Did you know that that your code is generating a bad Count and simply increasing/decreasing the position by that much? You really have no idea what your position is because your code is clearly not tracking it at all.

Originally Posted by Qw3rty
The above is sample code
It's not clear how much you're leaving out intentionally. But at the end of the day, it looks nothing like what you are describing.

Re: Increasing Lots Size [Re: Morris] #480929
07/25/20 05:00
07/25/20 05:00
Joined: Jun 2019
Posts: 23
Q
Qw3rty Offline OP
Newbie
Qw3rty  Offline OP
Newbie
Q

Joined: Jun 2019
Posts: 23
Originally Posted by Morris
Qw3rty,

I must concede I don't fully understand what you are trying to do. But when I look at your for(closed_trades), and you want Count to be reset to 1 and stay there, you might want to add a break statement:

Code
for(closed_trades) {
    if (crossOver(SMA30,SMA100)) {
        Count++;
    } else if (crossUnder(SMA30,SMA100)) {
        Count = 1;
        break_trades;	// to prevent the loop from keeping on counting up
    }
}


But then, wouldn't it be more straightforward to re-shuffle like this, since the loop does not affect the result of the if conditions:

Code
if (crossOver(SMA30,SMA100)) {
    for(closed_trades) {
        Count++;   // Or count this elsewhere to avoid the loop
    }
} else if (crossUnder(SMA30,SMA100)) {
    Count = 1;
}


Again, with the caveat that your intention isn't entirely clear to me...



Thanks Morris, this is interesting. I may be able to get rid of the For Loop now but it still doesn't give the result I want i.e. resetting the counter to 1 on trades that result in a higher high of equity. See next post for code update.

Re: Increasing Lots Size [Re: AndrewAMD] #480930
07/25/20 05:03
07/25/20 05:03
Joined: Jun 2019
Posts: 23
Q
Qw3rty Offline OP
Newbie
Qw3rty  Offline OP
Newbie
Q

Joined: Jun 2019
Posts: 23
Originally Posted by AndrewAMD
Originally Posted by Qw3rty
I would like to reset the counter or Lot size to 1 for a specific condition when Equity has reached a new high by $X.
Your code is not measuring Equity. Use Zorro's Equity variable to check for new maximums. Ideally, this should be a global variable or static var.

If you declare var Count inside of run, Zorro will forget its value every time another bar arrives. So don't do that. This should also be a global variable or static var.

Originally Posted by Qw3rty
What I am trying to achieve is when a trades loses I increase the lot size BUT if the trade wins I might want to increase the lot size depending on if the Equity has reached a new high by X dollars.
All trades are losing from the moment they are entered because of commission and spread, so you need establish a better definition of "losing trade". You're not monitoring this.

Did you know that that your code is generating a bad Count and simply increasing/decreasing the position by that much? You really have no idea what your position is because your code is clearly not tracking it at all.

Originally Posted by Qw3rty
The above is sample code
It's not clear how much you're leaving out intentionally. But at the end of the day, it looks nothing like what you are describing.


AndrewAMD, you are correct and thank you for pointing this all out. I have declared a global variable of Count (I think I have done it correctly). A losing trade in this instance is one where the moving averages cross but there is no new equity high (keeping it simple without the rollover and spread etc.).

Below is my updated code which I think is very very close except looking at the "testtrades" log file it seems to be increasing the Count for every bar when the trade opens and not with each "losing" trade. Attached is the outcomes I would expect with lots increasing and then resetting on new highs.

How can I fix the Count on "losing" trades instead of every bar?

Thanks for all the help!

/////////////////////////Code/////////////////////

static int Count = 1; //Global Variable needed for incremental count outside of Run function

function run()
{
set(LOGFILE|PLOTNOW|BALANCE|OPENEND);
StartDate = 2016;
EndDate = 2017;
BarPeriod = 5;
LookBack = 5000;
LotAmount = 0.1; //1000 or 0.1;
MaxLong = 1;
MaxShort = 1;
vars Prices = series(priceClose(0));
vars SMA100 = series(SMA(Prices,100));
vars SMA30 = series(SMA(Prices,30));
LotAmount = 0.1;
Lots = 1;
vars total_equity = series(Equity);
vars max_equity = series(MaxVal(total_equity,LookBack));
//static int Count = Lots;

for(closed_trades)
{
if ((total_equity[0]< max_equity[0]))
{
Count++;
}
else
{
Count = 1; //Trying to reset counter to 1 for loop.
break_trades;
}

}

//FOR Loop might not be needed but yields different results
/* if ((total_equity[0]< max_equity[0]))
Count++;
else
Count = 1; //Trying to reset counter to 1 for loop.
*/


//Zorro Forum Code Test
/*if (crossOver(SMA30,SMA100)) {
for(closed_trades) {
Count++; // Or count this elsewhere to avoid the loop
}
} else if (crossUnder(SMA30,SMA100)) {
Count = 1;
}
*/
if(crossOver(SMA30,SMA100))
enterLong(Count);
if (total_equity[0] > max_equity[0])
exitLong();

if(crossUnder(SMA30,SMA100))
enterShort(Count);
if (total_equity[0] >= max_equity[0])
exitShort();


plot("SMA30",SMA30,0,RED);
plot("SMA100",SMA100,0,BLUE);
plot("Count",Count,NEW,BLUE);
plot("Lots",Lots,NEW,BLUE);
plot("Max Equity",max_equity,NEW,BLUE);
plot("Total Equity",total_equity,NEW,BLUE);


}

Attached Files
Count.JPG (5 downloads)
Re: Increasing Lots Size [Re: Qw3rty] #481007
08/01/20 09:26
08/01/20 09:26
Joined: Jun 2019
Posts: 23
Q
Qw3rty Offline OP
Newbie
Qw3rty  Offline OP
Newbie
Q

Joined: Jun 2019
Posts: 23
Why is this code counting every bar in the closed_trades loop, see attached? I just want it to count for each condition and reset the counter to 1 when the condition has been met.

for(closed_trades)
{
if ((total_equity[0]<max_equity[0]))
{
Count++;
}
else
Count = 1; //Trying to reset counter to 1 for loop.

}

Attached Files
Count.JPG (5 downloads)
Re: Increasing Lots Size [Re: Qw3rty] #481012
08/01/20 14:22
08/01/20 14:22
Joined: Feb 2017
Posts: 1,062
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,062
Chicago
I'm not sure. Below are some troubleshooting and debugging tips:
https://manual.zorro-project.com/trouble.htm
https://zorro-project.com/manual/en/watch.htm
https://zorro-project.com/manual/en/chart.htm

Anyways, definitely take a peek at this Zorro manual page regarding Martingale systems. It's no longer published in the Table of Contents, and I really don't know why. It's very good:
https://zorro-project.com/manual/en/tutorial_scam.htm

Re: Increasing Lots Size [Re: Qw3rty] #481014
08/01/20 15:13
08/01/20 15:13
Joined: Jul 2017
Posts: 476
Z
Zheka Online
Senior Member
Zheka  Online
Senior Member
Z

Joined: Jul 2017
Posts: 476
Zorro's example on "Equity curve trading" that you are following is wrong: your "total_equity" and "max_equity" are series, i.e. are updated at each BAR (have no connection to each Trade).
(When a system is out of the market - guess what will happen?)

Because of this, in your loop you make comparisons of exactly the same values and increment Count "closed_trades" number of times.

To implement this correctly, you have several options:

- use static series and update it manually at trade exit: ( http://manual.zorro-trader.com/shift). Then you do not need a for(closed_trades) loop.
- at trade exit (in a tmf) save Equity to a TradeVar and separately keep track of the max Equity(no need for a series). Then you access TradeVars and compare these in for(trades) loop and increment Count as needed.

Page 2 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