Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (SBGuy), 652 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
[Oanda restapi]not opening more than 1 unit) #465863
05/15/17 18:25
05/15/17 18:25
Joined: May 2017
Posts: 5
S
slyths Offline OP
Newbie
slyths  Offline OP
Newbie
S

Joined: May 2017
Posts: 5
Hello I'm testing the scripting language to randomly open position, then increase the lot size based on the amount of positions I have open already and if the sum of the positions are losing.
The issues are 2:
1) I cannot seem to open more than 1 of the smallest tradeable unit in oanda fxtrade, regardless of the amount of Lots I insert(Lots = 1, Lots = 6 etc etc.)
2) therefore going back to the code when there are more than 5 positions open it doesn't increase the lot size as it should, therefore it doesn't continue trading.

I need the script to do exactly what I've tried described below. I'm aware that there are different ways to open lot sizes, but i wanted to see if zorro is capable of doing it this way.

This is the code for the lot size opening:

Any help will be greatly appreciated.
Code:
function run()
{
  StartDate = 2016;
  BarPeriod = 5; 
  LookBack = 500;
  Hedge = 5:

if (WinTotal < 0*PIP)
	if(NumOpenTotal < 5)
	{
		Lots = 1;
	} 
	if((NumOpenTotal > 6) and (NumOpenTotal < 10)) 
	{
		Lots = 2;
	}
	if((NumOpenTotal > 11) and (NumOpenTotal < 15))
	{
		Lots = 3;
	}

  if(NumOpenTotal == 0) { 
    if(random() < 0)
      enterShort();
    else 
      enterLong();
  }
}


Re: [Oanda restapi]not opening more than 1 unit) [Re: slyths] #465864
05/15/17 19:09
05/15/17 19:09
Joined: Feb 2017
Posts: 369
D
Dalla Offline
Senior Member
Dalla  Offline
Senior Member
D

Joined: Feb 2017
Posts: 369
Your code doesn't work because your conditions are wrong.
You are basically saying
"If less than 5 positions are open, use 1 lot, if more than 6 positions are open, use 2 lots".
Your code does not handle the case when you have exactly 5 or 6 open positions, same goes for 10 and 11.

Your probably use an else statement at the end also to handle the case when there are more than 15 open positions.
And use else if to make the code more efficient.
Something along these lines:

Code:
if(NumOpenTotal <= 5) {
	Lots = 1;
} else if((NumOpenTotal >= 6) and (NumOpenTotal <= 10)) {
	Lots = 2;
} else if((NumOpenTotal >= 11) and (NumOpenTotal <= 15)) {
	Lots = 3;
} else {
        Lots = 4;
}



Last edited by Dalla; 05/15/17 19:09.
Re: [Oanda restapi]not opening more than 1 unit) [Re: Dalla] #465865
05/15/17 21:37
05/15/17 21:37
Joined: May 2017
Posts: 5
S
slyths Offline OP
Newbie
slyths  Offline OP
Newbie
S

Joined: May 2017
Posts: 5
Originally Posted By: Dalla
Your code doesn't work because your conditions are wrong.
You are basically saying
"If less than 5 positions are open, use 1 lot, if more than 6 positions are open, use 2 lots".
Your code does not handle the case when you have exactly 5 or 6 open positions, same goes for 10 and 11.

Your probably use an else statement at the end also to handle the case when there are more than 15 open positions.
And use else if to make the code more efficient.
Something along these lines:

Code:
if(NumOpenTotal <= 5) {
	Lots = 1;
} else if((NumOpenTotal >= 6) and (NumOpenTotal <= 10)) {
	Lots = 2;
} else if((NumOpenTotal >= 11) and (NumOpenTotal <= 15)) {
	Lots = 3;
} else {
        Lots = 4;
}




Thanks for the reply.
Unfortunately it still is not working. It continues to open 1 unit, regardless. I have around 10 different trades of 1 unit.

Any other suggestions?

Last edited by slyths; 05/15/17 21:37.
Re: [Oanda restapi]not opening more than 1 unit) [Re: slyths] #465963
05/18/17 18:03
05/18/17 18:03
Joined: May 2017
Posts: 5
S
slyths Offline OP
Newbie
slyths  Offline OP
Newbie
S

Joined: May 2017
Posts: 5
Still need help with this.

Re: [Oanda restapi]not opening more than 1 unit) [Re: slyths] #465965
05/18/17 19:06
05/18/17 19:06
Joined: Feb 2017
Posts: 369
D
Dalla Offline
Senior Member
Dalla  Offline
Senior Member
D

Joined: Feb 2017
Posts: 369
What are you trying to achieve with this line of code

if (WinTotal < 0*PIP)

0*PIP will always be 0

Re: [Oanda restapi]not opening more than 1 unit) [Re: Dalla] #466010
05/19/17 21:47
05/19/17 21:47
Joined: May 2017
Posts: 5
S
slyths Offline OP
Newbie
slyths  Offline OP
Newbie
S

Joined: May 2017
Posts: 5
Originally Posted By: Dalla
What are you trying to achieve with this line of code

if (WinTotal < 0*PIP)

0*PIP will always be 0


If the sum of all trades are in a lossg then open a trade.
If the trade is still losing at 5 or more trades then open trade at 2 units and so on and so forth.
Thats all I want t o achieve.

So practically I just want to open trades and increase the lots as I continue losing. A sort of martingale that follows this pattern or similar( 1,1,1,1,2,2,2,2,2,5,5,5,5) it doesnt really matter as far as there is an increase after a certain amount of trades, as far as the sum is still a loss.

Re: [Oanda restapi]not opening more than 1 unit) [Re: slyths] #466012
05/20/17 05:48
05/20/17 05:48
Joined: Feb 2017
Posts: 369
D
Dalla Offline
Senior Member
Dalla  Offline
Senior Member
D

Joined: Feb 2017
Posts: 369
This is what the manual says about WinTotal

"Sum of profits of all trades won so far. When oversampling or phantom trades are used, WinLong or WinShort can be higher than WinTotal."

Sounds to me like that will never be less than zero

Re: [Oanda restapi]not opening more than 1 unit) [Re: Dalla] #466013
05/20/17 10:46
05/20/17 10:46
Joined: May 2017
Posts: 5
S
slyths Offline OP
Newbie
slyths  Offline OP
Newbie
S

Joined: May 2017
Posts: 5
Originally Posted By: Dalla
This is what the manual says about WinTotal

"Sum of profits of all trades won so far. When oversampling or phantom trades are used, WinLong or WinShort can be higher than WinTotal."

Sounds to me like that will never be less than zero


Ok I see:

I've changed it to

Code:
if (WinValTotal <= 0*PIP)



I'll test it when the market opens.

Thanks for your assistance so far.


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