Help needed

Questions about MultiCharts and user contributed studies.
Rigitti
Posts: 2
Joined: 28 Sep 2012

Help needed

Postby Rigitti » 10 Jan 2013

Hi all

since quite a long time I'm trading the very simple strategie described below discretionary and it works very well. Unfortunately I don't reach to wright the strategie on that way, that signals are only given, if MA 20 is rising or descending and MACD has to be positiv or crossing over the MA 20 for LE, and inverse for SE.

Positions are protected by a SL and a percent TrailingStopp 20% (this, because the SL is different from one instrument to an other. SL = 1.5 bricks).

Is there anyone who want to help me to do the script correctly?

Strategie
LongEntry:
Condition1 - Close over MA 20
Condition2 - MACD (crosses or is positiv) over MA 20 (in Masterchart)
Condition3 - MA 20 is rising

ShortEntry:
Inversed

Code Long:

Code: Select all

inputs: Price( Close ), Length( 20 ), ConfirmBars( 1 ), //MA
FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ; //MACD

variables: var0( 0 ), //MA
var1( 0 ), var2( 0 ) ; //MACD

var1 = MACD( Close, FastLength, SlowLength ) ;
var2 = XAverage( var1, MACDLength ) ;


condition1 = Price > AverageFC( Price, Length ) and CurrentBar > 2 and var1 > var2 ;

if condition1 then
var0 = var0 + 1
else
var0 = 0 ;

condition1 = CurrentBar > ConfirmBars and var0 = ConfirmBars ;
if condition1 then
Buy ( "LE" ) next bar at market ;
Code Short:

Code: Select all

inputs: Price( Close ), Length( 20 ), ConfirmBars( 1 ), //MA
FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ; //MACD

variables: var0( 0 ), //MA
var1( 0 ), var2( 0 ) ; //MACD

var1 = MACD( Close, FastLength, SlowLength ) ;
var2 = XAverage( var1, MACDLength ) ;


condition1 = Price < AverageFC( Price, Length ) and CurrentBar > 2 and var1 < var2 ;

if condition1 then
var0 = var0 + 1
else
var0 = 0 ;

condition1 = CurrentBar > ConfirmBars and var0 = ConfirmBars ;
if condition1 then
Sellshort ( "SE" ) next bar at market ;
Thanks in advance for your help!
Rigitti
Attachments
strategie.JPG
Screenshot
(48.54 KiB) Downloaded 388 times

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Help needed

Postby TJ » 10 Jan 2013

Hi all

since quite a long time I'm trading the very simple strategie described below discretionary and it works very well. Unfortunately I don't reach to wright the strategie on that way, that signals are only given, if MA 20 is rising or descending and MACD has to be positiv or crossing over the MA 20 for LE, and inverse for SE.

Positions are protected by a SL and a percent TrailingStopp 20% (this, because the SL is different from one instrument to an other. SL = 1.5 bricks).

Is there anyone who want to help me to do the script correctly?

Strategie
LongEntry:
Condition1 - Close over MA 20
Condition2 - MACD (crosses or is positiv) over MA 20 (in Masterchart)
Condition3 - MA 20 is rising

ShortEntry:
Inversed

Code Long:
inputs: Price( Close ), Length( 20 ), ConfirmBars( 1 ), //MA
FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ; //MACD

variables: var0( 0 ), //MA
var1( 0 ), var2( 0 ) ; //MACD

var1 = MACD( Close, FastLength, SlowLength ) ;
var2 = XAverage( var1, MACDLength ) ;


condition1 = Price > AverageFC( Price, Length ) and CurrentBar > 2 and var1 > var2 ;

if condition1 then
var0 = var0 + 1
else
var0 = 0 ;

condition1 = CurrentBar > ConfirmBars and var0 = ConfirmBars ;
if condition1 then
Buy ( "LE" ) next bar at market ;

Code Short:
inputs: Price( Close ), Length( 20 ), ConfirmBars( 1 ), //MA
FastLength( 12 ), SlowLength( 26 ), MACDLength( 9 ) ; //MACD

variables: var0( 0 ), //MA
var1( 0 ), var2( 0 ) ; //MACD

var1 = MACD( Close, FastLength, SlowLength ) ;
var2 = XAverage( var1, MACDLength ) ;


condition1 = Price < AverageFC( Price, Length ) and CurrentBar > 2 and var1 < var2 ;

if condition1 then
var0 = var0 + 1
else
var0 = 0 ;

condition1 = CurrentBar > ConfirmBars and var0 = ConfirmBars ;
if condition1 then
Sellshort ( "SE" ) next bar at market ;


Thanks in advance for your help!
Rigitti
I haven't looked at your code in detail,
here is a suggestion that can help:

Do not use the generic variable names. ie. condition1, var1, var2, etc.,
Please use a meaningful name for each variable; this will help you to understand your logic, and reduce the time in debugging.


ps. please use code tag when posting codes. It makes reading codes easier. Just highlight the codes you are about to post, and click the "Code" button located at the top of the message window. (I have tagged them for you in your post).

Rigitti
Posts: 2
Joined: 28 Sep 2012

Re: Help needed

Postby Rigitti » 10 Jan 2013

Hi TJ

thank you for the fast replay and the advice to post codes.

What I didn't understand are the words to use right tags. I saw this message so many times, but I don't get it. The tags used are originally out of MC. I have just put MA and MACD signals together and it works.

What I need is help to wright that signals are only given out if MA is rising or descending.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Help needed

Postby TJ » 10 Jan 2013

Hi TJ

thank you for the fast replay and the advice to post codes.

What I didn't understand are the words to use right tags. I saw this message so many times, but I don't get it. The tags used are originally out of MC. I have just put MA and MACD signals together and it works.

...
Please see How to Post Codes
viewtopic.php?f=16&t=11713

bowlesj3
Posts: 2180
Joined: 21 Jul 2007
Has thanked: 227 times
Been thanked: 429 times

Re: Help needed

Postby bowlesj3 » 13 Jan 2013

What I need is help to wright that signals are only given out if MA is rising or descending.
It sounds like you need to read the manual to get an overview of what MC's Power Language can do. In there you will learn how to reference historic bar information for any indicator you can plot and that will give you ideas on how to determine if your MA is moving up or down over whatever period of time you feel is best for your strategy. You should also scan the Help (I assume it is the Wiki now) command reference to view only the descriptions/purpose of the commands (without digging too deep) until you again have a second overview. Lastly an overview scan of the user contributed posts is a good idea. Reading the FAQ thread descriptions is a good idea (just the description of the thread first). Essentially it is learning what tools are available before you get too deep into attempting to code. I read the manual front to back and the command reference front to back before I touched any coding. The reason is simple. Without this knowledge you end up coding without knowledge of certain tools that are available to make it a lot easier. Of note, I also did a scan of all the indicators that come with MC at one point. I always make a list of what might be useful and come back to it when the time is right. That makes it a lot easier to learn the details of a new command because you immediately put it to use (reading all the details on a few commands before the overview is not that good an idea). I did two passes through the EL collections manual before I really started to understand it. The first pass was the overview of what it basically could do for me. The second pass (several months later) answered more questions and got me started using it. The third pass was when I was digging in to specific commands and trying to apply them (random rereads as needed to answer specific questions).


Return to “MultiCharts”