mov avg question

Questions about MultiCharts and user contributed studies.
shanemcdonald
Posts: 196
Joined: 08 Aug 2012
Has thanked: 41 times
Been thanked: 41 times

mov avg question

Postby shanemcdonald » 17 May 2013

hi
What would the code look like for having long entries only when above 50 period mov avg and short entries when below 50 period mov avg.

I am migrating from a different platform and also I am not the sharpest tool in the shed.

thanks

shane

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: mov avg question

Postby Henry MultiСharts » 17 May 2013

Hello Shane,

Have you tried using the prebuilt signals MovAvg Cross LE and MovAvg Cross SE with Length input = 50 ?

shanemcdonald
Posts: 196
Joined: 08 Aug 2012
Has thanked: 41 times
Been thanked: 41 times

Re: mov avg question

Postby shanemcdonald » 17 May 2013

hi henry
yes, they do form the basis for the strategy. I just wanted to set up a scenario where only the
mov avg LE and SE are used when price is above the 50 period MA. In other words, the 15 period Mov Avg LE is triggered when price is above the 50 period MA. Does it make sense ?
thank you

shane

User avatar
ABC
Posts: 718
Joined: 16 Dec 2006
Location: www.abctradinggroup.com
Has thanked: 125 times
Been thanked: 408 times
Contact:

Re: mov avg question

Postby ABC » 18 May 2013

Hi shanemcdonald,

this is the condition for the price being above the average, taken from the "MovAvg Cross LE" signal.

Code: Select all

condition1 = Price > AverageFC( Price, Length ) ;
Let's assume your length is 15, what about simply adding another part to the condition:

Code: Select all

condition1 = Price > AverageFC( Price, Length ) [b]and Price > AverageFC(Price, 50)[/b];
In case you want two conditions for your strategy to add to other entries, do something like this:

Code: Select all

inputs: Price( Close ), Length( 50 );
Variables: MovAvg(0), AboveMA(false), BelowMA(false);

MovAvg = AverageFC(Price, Length);

//reset the flags
AboveMA = false;
BelowMA = false;

//check if Price is above the MA
AboveMA = AboveMA or (Price > MovAvg);

//check if Price is below the MA
BelowMA = BelowMA or (Price < MovAvg);

//now you can use these two flags together with your other entry conditions

if MyLongCondition1 and MyLongCondition2 .... and AboveMA then
Buy ("Long") next bar market;
This should get you going.

Regards,
ABC

shanemcdonald
Posts: 196
Joined: 08 Aug 2012
Has thanked: 41 times
Been thanked: 41 times

Re: mov avg question

Postby shanemcdonald » 18 May 2013

hi
thanks ABC

that will help
switching over to MC is tricky for me

also, I am using the SE .net version and I posted in the wrong forum ! haha lol
sorry about that


take care

shane


Return to “MultiCharts”