Gamestudio Links
Zorro Links
Newest Posts
Accessing All Historical Price Data
by JohnJits. 10/22/19 22:37
file_write var array ?
by laz. 10/22/19 16:00
SAV_STATS
by MatPed. 10/22/19 13:57
Instrument Price Zorro Chart
by jcl. 10/22/19 10:39
Calculating with price series
by AndrewAMD. 10/21/19 14:31
Error E355: Startup failure
by Dooley. 10/21/19 06:47
Today real live account blown - my experience
by Clifford_B. 10/19/19 17:09
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
4 registered members (JohnJits, AndrewAMD, Clifford_B, 1 invisible), 627 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
VillageTalkies, line7, Shutch, Clifford_B, Paulius
18310 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
How to code this for() condition? #478035
08/28/19 10:52
08/28/19 10:52
Joined: Feb 2018
Posts: 23
T
tomaslolo Offline OP
Newbie
tomaslolo  Offline OP
Newbie
T

Joined: Feb 2018
Posts: 23
Hi all, I´m bad coding, I try many things and fail, but keep learning. I have a condition I´m triying to code and I ask for help:.

If (priceClose(0)>SMA(200)) during the last 100 bars. How can I code It?

Do I have to write 100 times the condition?

Code
vars priceC=series(priceClose());
vars mySMA200=series(SMA(priceC,200));

if(priceC[0]>mySMA200[0]
and priceC[1]>mySMA200[1]
and priceC[2]>mySMA200[2]
.....

and priceC[100]>mySMA200[100])

enterLong()


Because if I code this;

Code
int i;
for(i=0;i<100;i++)
if (priceC[i]>mySMA200[i])
enterLong();


I guess enters Long if the condition is met any time during last 100 bars, and I want to enterLong only if the whole last 100 priceClose are above SMA(200).

Any clues?

Thank you very much

Re: How to code this for() condition? [Re: tomaslolo] #478037
08/28/19 12:38
08/28/19 12:38
Joined: Feb 2015
Posts: 568
Milano, Italy
M
MatPed Offline
User
MatPed  Offline
User
M

Joined: Feb 2015
Posts: 568
Milano, Italy
int i
bool flag= true;
for(i=0;i<100;i++)
if (priceC[i]<mySMA200[i]) flag= false;
if(flag) enterLong();

double check the sintax. Ciao

Re: How to code this for() condition? [Re: tomaslolo] #478040
08/28/19 21:08
08/28/19 21:08
Joined: Feb 2018
Posts: 23
T
tomaslolo Offline OP
Newbie
tomaslolo  Offline OP
Newbie
T

Joined: Feb 2018
Posts: 23
Thank you very much. I understand your logic, I wouldn´t though about it.

But it doesn´t enter any trade, even if I limit int i to 10, even to 3, to make sure it should enterLong.

As I understand:
1.- Every new bar flag is true
2.- If any (the last 100 bars) priceC<mySMA200 flag would be false, so next condition if(flag) would never be true, so no trade is opened.
3. But if priceC>mySMA200 (all last 100 bars), flag would continue being true so it should enterLong, but it doesn´t. Why??

What´s wrong??

Re: How to code this for() condition? [Re: tomaslolo] #478044
08/29/19 08:42
08/29/19 08:42
Joined: Feb 2018
Posts: 23
T
tomaslolo Offline OP
Newbie
tomaslolo  Offline OP
Newbie
T

Joined: Feb 2018
Posts: 23
It´s working fine. Had to restart Zorro.

Thank you very much MatPed, I really apreciate.

Vielen Dank!

Re: How to code this for() condition? [Re: tomaslolo] #478050
08/29/19 15:36
08/29/19 15:36
Joined: Jan 2019
Posts: 73
berlin
L
laz Offline
Junior Member
laz  Offline
Junior Member
L

Joined: Jan 2019
Posts: 73
berlin
According to your rules you can also stop searching after 1 false is found:

if(priceC[i]<mySMA200[i]) { flag=false; break; }

Not so important for only 100 loops but maybe you increase that later wink

Re: How to code this for() condition? [Re: tomaslolo] #478053
08/29/19 22:10
08/29/19 22:10
Joined: Feb 2018
Posts: 23
T
tomaslolo Offline OP
Newbie
tomaslolo  Offline OP
Newbie
T

Joined: Feb 2018
Posts: 23
Good point! Thank you for noting the break rule.

Vielen Dank laz!!

Re: How to code this for() condition? [Re: tomaslolo] #478054
08/29/19 22:51
08/29/19 22:51
Joined: Jan 2019
Posts: 73
berlin
L
laz Offline
Junior Member
laz  Offline
Junior Member
L

Joined: Jan 2019
Posts: 73
berlin
gerne doch wink


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