Indicator values to be included in Signals

Studies that have been contributed to the community by other users. If you’ve got something useful to share, that’s great!
XIKON
Posts: 23
Joined: 15 Dec 2010
Has thanked: 3 times
Been thanked: 3 times

Indicator values to be included in Signals

Postby XIKON » 05 Mar 2012

Dear All,

I am sure this has come up in the past however cannot find any information on this. I am wondering if anyone can assist.

I am trying to build a strategy whereby when a certain indicator hits a certain value, a buy or sell signal is generated. For example if MACD value (reading from the indicator) is below zero (non to be confused with MACDDiff) and the MACDIFF is above zero to get me into the trade. I have tried to use

Code: Select all

MACD > 0
which I was sure would not work and it didn't.

Is there anyway the value of indicators can be included in signals such as above example?

Many thanks for all the support.

Kind regards,

XIKON

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

Re: Indicator values to be included in Signals

Postby TJ » 05 Mar 2012

Dear All,

I am sure this has come up in the past however cannot find any information on this. I am wondering if anyone can assist.

I am trying to build a strategy whereby when a certain indicator hits a certain value, a buy or sell signal is generated. For example if MACD value (reading from the indicator) is below zero (non to be confused with MACDDiff) and the MACDIFF is above zero to get me into the trade. I have tried to use

Code: Select all

MACD > 0
which I was sure would not work and it didn't.

Is there anyway the value of indicators can be included in signals such as above example?

Many thanks for all the support.

Kind regards,

XIKON
lots of examples here:
http://www.tradersxchange.com/viewforum.php?f=31


ps. if you are serious about creating your own strategy,
it won't hurt to spend a few weekends on the manuals.

start from here:
post #1 and post #2
viewtopic.php?f=16&t=6929

XIKON
Posts: 23
Joined: 15 Dec 2010
Has thanked: 3 times
Been thanked: 3 times

Re: Indicator values to be included in Signals

Postby XIKON » 06 Mar 2012

Dear TJ,

Many thanks. I have gone through a lot of material but still seem to be puzzled by a few concepts and how the script has to be written. To mention one as an example I have been trying to sort out one just now after spending more than 5 hours trying to test a piece of script and modifying it to get what it was intended to do I finally gave up. On this one I tried a simple rule where when the moving averages cross over to buy and sell after five days. However for purpose of optimisation, I would like to keep the barssinceentry on the input line. However I have problem referring to this value in the script so that it reads the value from the input line.

Code: Select all

inputs: Price( open ), FastLength( 50 ), SlowLength( 200 ), barssinceentry(4);
variables: var0( 0 ), var1( 0 ) ;

var0 = XAverage( Price, FastLength );
var1 = XAverage( Price, SlowLength ) ;

if var0 crosses over var1 then Buy ( "XIKON XMA2CrossLE" ) next bar at market;

if MarketPosition = 1 AND BarsSinceEntry = (to read from input line) then Sell next bar at Market;
.

There are also a few more which I am struggling with. Would any assistance be available?

Many thanks in advance.

Best regards,

XIKON

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

Re: Indicator values to be included in Signals

Postby TJ » 06 Mar 2012

Dear TJ,
...

There are also a few more which I am struggling with. Would any assistance be available?

Many thanks in advance.

Best regards,

XIKON
Paid assistance?

Contact ABC, he is a regular contributor here.

or contact technical support at MultiCharts. They provide programming services.

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

Re: Indicator values to be included in Signals

Postby TJ » 06 Mar 2012

Dear TJ,

Many thanks. I have gone through a lot of material but still seem to be puzzled by a few concepts and how the script has to be written. To mention one as an example I have been trying to sort out one just now after spending more than 5 hours trying to test a piece of script and modifying it to get what it was intended to do I finally gave up. On this one I tried a simple rule where when the moving averages cross over to buy and sell after five days. However for purpose of optimisation, I would like to keep the barssinceentry on the input line. However I have problem referring to this value in the script so that it reads the value from the input line.

Code: Select all

inputs: Price( open ), FastLength( 50 ), SlowLength( 200 ), barssinceentry(4);
variables: var0( 0 ), var1( 0 ) ;

var0 = XAverage( Price, FastLength );
var1 = XAverage( Price, SlowLength ) ;

if var0 crosses over var1 then Buy ( "XIKON XMA2CrossLE" ) next bar at market;

if MarketPosition = 1 AND BarsSinceEntry = (to read from input line) then Sell next bar at Market;
.

There are also a few more which I am struggling with. Would any assistance be available?

Many thanks in advance.

Best regards,

XIKON
Before I get into your code, one word of advice:

Avoid using generic variable names like var0, value1, condition1, etc.,

I know the canned indicators have them, that's because they are re-gen'd from another source. For your own code, you should always create meaningful variable names, so that when you read the code, you can follow the logic easily. And when you re-visit your code in a few month's time, you do not have to scratch your head and spend hours trying to figure out the logic. This is important especially when you have expanded your logic and your "simple" code turned into hundreds of lines. This is critical if your code have to deal with your MONEY$$$. You do not want a small misunderstanding in variables turn into thousands of dollar in losses.


eg. which reads better?

Code: Select all


if var0 crosses over var1 then Buy...

if Fast.MA crosses over Slow.MA then Buy...
Just my 2 cents worth.


Return to “User Contributed Studies and Indicator Library”