[Oanda restapi]not opening more than 1 unit)

Posted By: slyths

[Oanda restapi]not opening more than 1 unit) - 05/15/17 18:25

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();
  }
}

Posted By: Dalla

Re: [Oanda restapi]not opening more than 1 unit) - 05/15/17 19:09

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;
}


Posted By: slyths

Re: [Oanda restapi]not opening more than 1 unit) - 05/15/17 21:37

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?
Posted By: slyths

Re: [Oanda restapi]not opening more than 1 unit) - 05/18/17 18:03

Still need help with this.
Posted By: Dalla

Re: [Oanda restapi]not opening more than 1 unit) - 05/18/17 19:06

What are you trying to achieve with this line of code

if (WinTotal < 0*PIP)

0*PIP will always be 0
Posted By: slyths

Re: [Oanda restapi]not opening more than 1 unit) - 05/19/17 21:47

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.
Posted By: Dalla

Re: [Oanda restapi]not opening more than 1 unit) - 05/20/17 05:48

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
Posted By: slyths

Re: [Oanda restapi]not opening more than 1 unit) - 05/20/17 10:46

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.
© 2024 lite-C Forums