Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, SBGuy, TipmyPip, ozgur), 923 guests, and 6 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
MA PERFECT ORDER CODE #484724
12/06/21 18:09
12/06/21 18:09
Joined: Dec 2021
Posts: 13
S
Sage Offline OP
Newbie
Sage  Offline OP
Newbie
S

Joined: Dec 2021
Posts: 13
I'd love to code a moving average strategy. I saw it in a book and it goes

"Buy when 10SMA is above 20, 20 above 50 and 50 above 100. Exit when 10SMA crosses under the 20 SMA. (The reverse for a short trade)
In the book, 200 SMA was utilized but I cut it out personally.

I tried coding it this way but doesn't seem to work, guess I need a correction


function run()
{

SMA10 = series(SMA(seriesC(),10));
SMA20 = series(SMA(seriesC(),20));
SMA50 = series(SMA(seriesC(),50));
SMA100 = series(SMA(seriesC(),100));

if(crossOver(SMA10, SMA20) && crossOver(SMA20,SMA50) && crossOver(SMA50,SMA100))
enterLong();

if(crossUnder(SMA10, SMA20) && crossUnder(SMA20,SMA50) && crossUnder(SMA50,SMA100))
enterShort();

if(crossUnder(SMA10,SMA20)) exitLong();
if(crossOver(SMA10,SMA20)) exitShort();

}


Would be looking forward for the correct code. Thanks!

Re: MA PERFECT ORDER CODE [Re: Sage] #484725
12/06/21 18:24
12/06/21 18:24
Joined: Oct 2017
Posts: 52
Brazil
J
jmlocatelli Offline
Junior Member
jmlocatelli  Offline
Junior Member
J

Joined: Oct 2017
Posts: 52
Brazil
Your strategy says buy when 10SMA IS above 20SMA and 20SMA IS above 50SMA and so forth. It does not say buy when CROSS above.
The code should be:

if(SMA10[0]>SMA20[0] and SMA20[0]>SMA50[0] and SMA50[0]>SMA100[0])
enterLong();

Re: MA PERFECT ORDER CODE [Re: jmlocatelli] #484729
12/07/21 00:41
12/07/21 00:41
Joined: Dec 2021
Posts: 13
S
Sage Offline OP
Newbie
Sage  Offline OP
Newbie
S

Joined: Dec 2021
Posts: 13
Thank you


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