Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
3 registered members (VoroneTZ, monk12, Quad), 829 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Increasing Lots Size #480865
07/20/20 11:01
07/20/20 11:01
Joined: Jun 2019
Posts: 24
Q
Qw3rty Offline OP
Newbie
Qw3rty  Offline OP
Newbie
Q

Joined: Jun 2019
Posts: 24
Is there a way to increase the Lots size continuously based on a given condition?

if(condition)
Lots = Lots+1; //Lots++
else
Lots = 1;

The above doesn't continuously add to Lots.

I've looked at using TradeLots but no luck. Also using Lots in a vars series didn't work either.

Any ideas?

Re: Increasing Lots Size [Re: Qw3rty] #480866
07/20/20 11:57
07/20/20 11:57
Joined: Mar 2019
Posts: 357
D
danatrader Offline
Senior Member
danatrader  Offline
Senior Member
D

Joined: Mar 2019
Posts: 357
Use your Lots in a static var and add +1 per closed trade.

Re: Increasing Lots Size [Re: Qw3rty] #480878
07/21/20 11:05
07/21/20 11:05
Joined: Jun 2019
Posts: 24
Q
Qw3rty Offline OP
Newbie
Qw3rty  Offline OP
Newbie
Q

Joined: Jun 2019
Posts: 24
I have tried with a static var and added +1 but the problem is it only adds 1 lot when the condition happens. If the condition happens again it doesn't add another lot so it always sits at a max of 2.

How do I use the close trades without a loop?

I am trying the following:

for(closed_trades) //for(all_trades)
{
if (Equity[0] < max_equity[0])
Count++;
else
Count=1; //doesn't reset the entire counter to 1 and the countr carries on from the last Count++
}

I am using Count as Lots now for enterLong(Count) and enterShort(Count);

Now it increments but I can't get it to reset to 1 and start all over.

See the attached output of trade log lots, Count lots (loop) and Max Lots (Static Var).

Surely there must be an easier way?

Thanks for teh help!

Attached Files
Lots.JPG (17 downloads)
Count.JPG (15 downloads)
MaxLots.JPG (15 downloads)
Re: Increasing Lots Size [Re: Qw3rty] #480880
07/21/20 14:15
07/21/20 14:15
Joined: Mar 2019
Posts: 357
D
danatrader Offline
Senior Member
danatrader  Offline
Senior Member
D

Joined: Mar 2019
Posts: 357
I am sure there is, maybe share your complete code, is always easier.
I am not a developer myself, so maybe others can help, but they won't if it is too much difficulty.

Everyone has limited time.

Re: Increasing Lots Size [Re: Qw3rty] #480889
07/22/20 09:37
07/22/20 09:37
Joined: Jun 2019
Posts: 24
Q
Qw3rty Offline OP
Newbie
Qw3rty  Offline OP
Newbie
Q

Joined: Jun 2019
Posts: 24
Really appreciate the help on this. Also not a developer so I'm bangiing my head every step of the way and reading the maunal as much as posible.

Sample code. How do I reset the Count in the loop to 1.

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

for(closed_trades)
{
if (crossOver(SMA30,SMA100))
Count++;
else if (crossUnder(SMA30,SMA100))
Count = 1; //Trying to reset counter to 1 for loop but no luck

}

if(crossOver(SMA30,SMA100))
{
enterLong(Count);
}

if(crossUnder(SMA30,SMA100))
{
enterShort(Count);
}

plot("SMA",SMA30,0,RED);
plot("SMA",SMA100,0,BLUE);
plot("Count",Count,NEW,BLUE);
plot("Lots",Lots,NEW,BLUE);

}

I'll take other creative ideas as well.

Re: Increasing Lots Size [Re: Qw3rty] #480896
07/22/20 13:36
07/22/20 13:36
Joined: Feb 2017
Posts: 1,718
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,718
Chicago
Originally Posted by danatrader
I am not a developer myself
Originally Posted by Qw3rty
Also not a developer so I'm bangiing my head every step of the way and reading the maunal as much as posible.
You just might be a developer if you are:
* writing Zorro code and
* banging your head on the keyboard.

Welcome to the club! grin

If you can write a paragraph explaining how and why you want to increase the lot size, I think I can give better advice. Your ultimate goal is not exactly clear.

Re: Increasing Lots Size [Re: Qw3rty] #480908
07/22/20 22:31
07/22/20 22:31
Joined: Mar 2020
Posts: 41
J
jbhunter Offline
Newbie
jbhunter  Offline
Newbie
J

Joined: Mar 2020
Posts: 41
This may be good code to review if you are looking for more samples. It increases the position size as a z score hits predefined levels.

https://robotwealth.com/pairs-trading-zorro/

Re: Increasing Lots Size [Re: jbhunter] #480914
07/24/20 07:33
07/24/20 07:33
Joined: Jun 2019
Posts: 24
Q
Qw3rty Offline OP
Newbie
Qw3rty  Offline OP
Newbie
Q

Joined: Jun 2019
Posts: 24
Originally Posted by jbhunter
This may be good code to review if you are looking for more samples. It increases the position size as a z score hits predefined levels.

https://robotwealth.com/pairs-trading-zorro/


Looks interesting, thank you. I couldn't get it to fully work downloading the assets (that's another story). But this looks more like a grid trading system or trading at specific zones.

Re: Increasing Lots Size [Re: AndrewAMD] #480915
07/24/20 07:54
07/24/20 07:54
Joined: Jun 2019
Posts: 24
Q
Qw3rty Offline OP
Newbie
Qw3rty  Offline OP
Newbie
Q

Joined: Jun 2019
Posts: 24
Originally Posted by AndrewAMD
Originally Posted by danatrader
I am not a developer myself
Originally Posted by Qw3rty
Also not a developer so I'm bangiing my head every step of the way and reading the maunal as much as posible.
You just might be a developer if you are:
* writing Zorro code and
* banging your head on the keyboard.

Welcome to the club! grin

If you can write a paragraph explaining how and why you want to increase the lot size, I think I can give better advice. Your ultimate goal is not exactly clear.


The life of a developer then lol.

The above is sample code but the outcome is still the same. 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.

When trading using crossovers (as an example) one theory is to double down or use the martingale method on your losses to turn them into a profit. This works in theory but the moving average is exactly that, an average of price which isn’t sufficient and there can be unlimited losses and not an unlimited amount of money. With the moving average crossover there is a high and a low before a new cross happens (peak and trough of the trade). 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. If a new Equity high is reached then the Lot value (count) moves to 1. Otherwise increase the count by X.

If open trade = new equity high then close trade.
If open trade <> new equity high then increase lot (regardless of winning or losing trade).

I really appreciate all the help. My head really hurts trying to get this right.

Let me know if I need to explain further.

Re: Increasing Lots Size [Re: Qw3rty] #480920
07/24/20 11:51
07/24/20 11:51
Joined: May 2020
Posts: 27
Germany
M
Morris Offline
Newbie
Morris  Offline
Newbie
M

Joined: May 2020
Posts: 27
Germany
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...

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