Gamestudio Links
Zorro Links
Newest Posts
AlpacaZorroPlugin v1.3.0 Released
by kzhao. 05/20/24 01:28
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
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
1 registered members (AndrewAMD), 636 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
Placing BuyStop and SellStop Orders #487865
10/19/23 18:41
10/19/23 18:41
Joined: Sep 2023
Posts: 18
Freiburg
S
steyr Offline OP
Newbie
steyr  Offline OP
Newbie
S

Joined: Sep 2023
Posts: 18
Freiburg
Hello dear community,

I am working with the MT5 bridge, and currently I am struggling to place Buy Limit and Sell Limit orders.

When I run my code, the Buy/Sell Limit order is placed almost directly at the current price, instead of at a 0.2% distance from the current price.

Furthermore, I am wondering how to program Buy/Sell Stop orders in Zorro. The manual doesn't seem to provide proper code examples. Can anyone of you help me out with this?

Best regards,
steyr




Code
		if(priceC(0) <=  priceO(0) and NumPendingShort <= 0)
			{
				OrderLimit = priceO(0)-(priceC(1)*(0.2/100)); // 0.2% Distance from current Price
				MaxShort = 1;
				enterShort(OrderLimit);
			}

			else if(priceC(0) >= priceO(0) and NumPendingLong <= 0)
			{
					
				OrderLimit = priceO(0)+(priceC(1)*(0.2/100));// 0.2% Distance from current Price
				MaxLong = 1;
				enterLong(OrderLimit);
					
			}

Last edited by steyr; 10/19/23 19:00.
Re: Placing BuyStop and SellStop Orders [Re: steyr] #487866
10/19/23 20:05
10/19/23 20:05
Joined: Feb 2017
Posts: 1,731
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,731
Chicago
OrderLimit is a global variable and not an argument for enterLong/short. Just set OrderLimit before you call enterLong.

Re: Placing BuyStop and SellStop Orders [Re: AndrewAMD] #487868
10/20/23 09:46
10/20/23 09:46
Joined: Sep 2023
Posts: 18
Freiburg
S
steyr Offline OP
Newbie
steyr  Offline OP
Newbie
S

Joined: Sep 2023
Posts: 18
Freiburg
Thank you for your hint, Andrew.

However, it's the case that it doesn't place the Limit Order around +- 0.2% from the current price but rather in close proximity to the price...

I don't understand this logic.
Code
		if(priceC(0) <=  priceO(0) and NumPendingShort <= 0)
			{
				OrderLimit = priceO(0)-(priceC(1)*(0.2/100)); // 0.2% Distance from current Price
				MaxShort = 1;
				enterShort();
			}

			else if(priceC(0) >= priceO(0) and NumPendingLong <= 0)
			{
					
				OrderLimit = priceO(0)+(priceC(1)*(0.2/100));// 0.2% Distance from current Price
				MaxLong = 1;
				enterLong();
					
			}

Last edited by steyr; 10/20/23 09:46.
Re: Placing BuyStop and SellStop Orders [Re: steyr] #487869
10/20/23 12:36
10/20/23 12:36
Joined: Feb 2017
Posts: 1,731
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,731
Chicago
Your code does not match your description. It is relative to both the current bar and the previous bar, which is wrong. Don’t call priceC(1).

Re: Placing BuyStop and SellStop Orders [Re: AndrewAMD] #487870
10/20/23 15:30
10/20/23 15:30
Joined: Sep 2023
Posts: 18
Freiburg
S
steyr Offline OP
Newbie
steyr  Offline OP
Newbie
S

Joined: Sep 2023
Posts: 18
Freiburg
I see, unfortunately, changing the approach as you said before hasn't resolved the issue with the inexplicable placement of OrderLimit.
Even though the correct price level is displayed in the print statement, it's not being placed accurately in the market.

In the attached image, priceO(0) and the OrderLimit variable are printed, showing a difference of 0.02%. Despite this, a sell position is opened at 0.00006 immediately afterward. What could be going wrong here?


Code

		if(priceC(0) <=  priceO(0) and NumPendingShort <= 0)
			{
				OrderLimit = priceO(0)-(priceO(0)*(0.2/100)); // 0.2% Distance from current Price
				MaxShort = 1;
				enterShort();
			}

			else if(priceC(0) >= priceO(0) and NumPendingLong <= 0)
			{
					
				OrderLimit = priceO(0)+(priceO(0)*(0.2/100));// 0.2% Distance from current Price
				MaxLong = 1;
				enterLong();
					
			}



Attached Files Orderlimit issue.jpg
Last edited by steyr; 10/20/23 15:40.
Re: Placing BuyStop and SellStop Orders [Re: steyr] #487872
10/20/23 17:49
10/20/23 17:49
Joined: Feb 2017
Posts: 1,731
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,731
Chicago
It still doesn't match your description. The latest price is priceC(0). run() is called when a bar closes.

Also, try rounding OrderLimit to the nearest PIP, and if that doesn't work, contact support.

Re: Placing BuyStop and SellStop Orders [Re: steyr] #487879
10/23/23 08:57
10/23/23 08:57
Joined: Sep 2023
Posts: 18
Freiburg
S
steyr Offline OP
Newbie
steyr  Offline OP
Newbie
S

Joined: Sep 2023
Posts: 18
Freiburg
Rounding the OrderLimit variable using round() unfortunately doesn't change the outcome. I will now contact the support team.

Thank you for your assistance until now.

This is how the final code looks like

Code
                      tick()
                      {		
                        if(priceC(0) <=  priceO(0) and NumPendingShort <= 0)
			{
				OrderLimit = roundto( (priceO(0) - (priceO(0) * (BarRange/100)) ),PIP); // 0.2% Distance from current Price
				MaxShort = 1;
				enterShort(OrderLimit);
			}

			else if(priceC(0) >= priceO(0) and NumPendingLong <= 0)
			{
					
				OrderLimit = roundto( (priceO(0) + (priceC(1) * (0.2/100)) ),PIP); // 0.2% Distance from current Price
				MaxLong = 1;
				enterLong(OrderLimit);
					
			}
                      }

Last edited by steyr; 10/23/23 08:58.
Re: Placing BuyStop and SellStop Orders [Re: steyr] #487883
10/23/23 15:26
10/23/23 15:26
Joined: Feb 2017
Posts: 1,731
Chicago
AndrewAMD Online
Serious User
AndrewAMD  Online
Serious User

Joined: Feb 2017
Posts: 1,731
Chicago
You did it again... Don't do this:
Code
enterShort(OrderLimit);
enterLong(OrderLimit);
enterLong() and enterShort() are documented here.
https://zorro-project.com/manual/en/buylong.htm

Re: Placing BuyStop and SellStop Orders [Re: steyr] #487890
10/24/23 20:11
10/24/23 20:11
Joined: Sep 2023
Posts: 18
Freiburg
S
steyr Offline OP
Newbie
steyr  Offline OP
Newbie
S

Joined: Sep 2023
Posts: 18
Freiburg
Oh sorry, my fault..

in the running script its correct..

Code
            tick()
                      {		
                        if(priceC(0) <=  priceO(0) and NumPendingShort <= 0)
			{
				OrderLimit = roundto( (priceO(0) - (priceO(0) * (BarRange/100)) ),PIP); // 0.2% Distance from current Price
				MaxShort = 1;
				enterShort();
			}

			else if(priceC(0) >= priceO(0) and NumPendingLong <= 0)
			{
					
				OrderLimit = roundto( (priceO(0) + (priceC(1) * (0.2/100)) ),PIP); // 0.2% Distance from current Price
				MaxLong = 1;
				enterLong();
					
			}
                      }

Last edited by steyr; 10/25/23 06:57.

Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1