Moving Average crossover

Posted By: gra9

Moving Average crossover - 11/12/19 17:00

Hi Guys,

I'm new here,

How would i write a simple strategy of buying on a moving average cross over(simple MA)

if 13/31 moving average crosses over on(5 minute chart) upside buy.
if 13/31 moving average crosses over on(5 minute chart) downside the sell.

Thank you.
Blessings.
Posted By: felixfx

Re: Moving Average crossover - 11/13/19 10:00

function run()
{
set(PLOTNOW);
StartDate = 20100101;
EndDate = 20101231;
BarPeriod = 5;
vars close = series(priceClose());
vars sma13 = series(SMA(close, 13));
vars sma31 = series(SMA(close, 31));

if(crossOver(sma13, sma31)) enterLong();
if(crossUnder(sma13, sma31)) enterShort();

plot("sma13", sma13, MAIN, BLUE);
plot("sma31", sma31, 0, RED);
}

you'll find that a moving average crossover strategy loses money.
Posted By: gra9

Re: Moving Average crossover - 11/13/19 10:43

Thank you so much !!!
I currently use trade-ideas.com , whioh does not let me do custom moving averages like this , how do i get alerts on such signals in real time ?
Would love to have even a simple file generated in realtime , that will give me all these alerts say on a list of 30 stocks, or perhaps on the Nasdaq and New York.
Thank you !!! Blessings !!!
Posted By: felixfx

Re: Moving Average crossover - 11/20/19 13:57

I suppose you'll have to find a way to connect Zorro to trade-ideas.com's software, which I am completely unfamiliar with, and therefore would not even know whether they allow algorithmic trading.

I would suggest just sticking with Zorro begin backtesting ideas until you have developed a strategy that works.
Posted By: Figurehunter

Re: Moving Average crossover - 01/20/21 21:46

Alerts are possible with Zorro using email. I haven't measured the delay. These snippets are straight from the help file.

void main()
{
string To = "<me@myself.org>";
string From = "<zorro_alert@gmail.com>";
string Subject = "Zorro Message";
string Body = "Zorro has sent you a message!";
string Server = "smtps://smtp.gmail.com:465";
string User = "zorro_alert@gmail.com";
string Password = "zorros_password";
email(To,From,Subject,Body,Server,User,Password);
}

or....(my friend said he will use this code so he can then forward to a text alert which could be faster)


// send an email when a trade is enteredfunction sendEmailAboutTrade(){
// compose the message
string Content = strf("content=Zorro has entered a trade!\n%d Lots of %s",
Lots,Asset);
http_transfer("http://www.myserver.com/zorromail.php",Content);}
Posted By: BigW

Re: Moving Average crossover - 01/14/23 21:36

[quote=Figurehunter]Alerts are possible with Zorro using email. I haven't measured the delay. These snippets are straight from the help file.

void main()
{
string To = "<me@myself.org>";
string From = "<zorro_alert@gmail.com>";
string Subject = "Zorro Message";
string Body = "Zorro has sent you a message!";
string Server = "smtps://smtp.gmail.com:465";
string User = "zorro_alert@gmail.com";
string Password = "zorros_password";
email(To,From,Subject,Body,Server,User,Password);
}

I have set this up exactly as indicated in the help file and above in a new script page without any code ie to test sending emails separately from any trading script. The setup is using a new Google account set up for this purpose.

After running it I get the message:
Email test compiling...ok, but no 0 or non zero returned.
Does anyone have any experience using Google - or Outlook that works?

Following up I tried to set this up using Runbox instead of gmail and changed maun to a function which when runs returns 1 ie says email sent but still no email for some reason.


© 2024 lite-C Forums