How to use candle colors to initiate buy and sell.
Author: sofia
Creation Date: 8/10/2011 12:19 PM

#### sofia

#1
Need help coding candle colors to initiate buy and sell

Hello,

How do I code this.
I have certain criteria that I use to code color price candles.
The candles are either Yellow[bearish], black[change of direction], blue[bullish]

The code is either long or short.

CoverShort/Go Long
===================
cover all short positions if
candle[bar-1] is yellow and candle[bar] is black. //weak change of direction]
and
initiate first long position.
if candle [bar-1] is black and candle[bar] is blue // Strong trend bullish
initiate second long position at close

Sell Long/ Go Short
=====================
Sell all long positions at close if
candle[bar-1] is blue and candle[bar] is black // weak change of direction.
and initiate first short position.
if candle[bar-1] is black and candle[bar] is yellow // strong trend bearish
and initiate second short position.

Thanks.

Sofia

#### Eugene

#2
Here's a mockup using some dummy conditions for your colored candles:
CODE:

#### sofia

#3
Hi Eugene,

Thanks for the code.

One question regarding assigning boolean to colors.
I am not using price bars to assign value, but another condition defined as boolean.

bool vixtovxvup = directionvixtovxv[bar] < 0;
bool SMA11up = Close[bar] > SMA11[bar];

Then I define another boolean that uses the "anding" of the the bits to define final color.

bool yellow = vixtovxvup && SMA11up; //current bar
so to define boolean yellow1 for bar-1,

do I need to define it like this ?

bool vixtovxvup1 = directionvixtovxv[bar-1] < 0;
bool SMA11up1 = Close[bar-1] > SMA11[bar-1];

bool yellow1 = vixtovxvup1 && SMA11up1;

Regards,

Sofia

#4

#### sofia

#5
How to get percent data into dataseries.

Hello,

I am using the same thread as I started this one.
I want to store %change in bars in dataseries. Is there a function that I could use. I searched and
couldn't find one.
Here is the code,

using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;

namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
protected override void Execute()
{
//Equal weighted snp index
DataSeries index1 = GetExternalSymbol( "RSP", true ).Close;
//Market cap weighted snp index
DataSeries index2 = GetExternalSymbol( "SPY", true ).Close;

for(int bar = 20; bar < Bars.Count; bar++)
{

//How do I code this

//bool indexup = (percent close(index1[bar] - index1[bar-1]) > percent close(index2[bar] - index2[bar-1]);
//I want to compare percent closing price of one dataseries with respect to other
//Example index1 close up 3% and index2 close up 2.5% , then indexup is true else false
// index1 close down 2% and index2 close down 3%, then indexup is false else true

// is this right

index1percent = (index1[bar]-index1[bar-1])/index1[bar]*100;
index2percent = (index2[bar]-index2[bar-1])/index2[bar]*100;
How do I take absoulte values of above and then substitute as

bool indexup = index1percent > index2percent;

Thanks,

Sofia

#### Eugene

#6
QUOTE:
I want to store %change in bars in dataseries. Is there a function that I could use.

Percent change = Rate of Change. You can find it among Wealth-Lab's Standard Indicators:

ROC
QUOTE:
How do I take absoulte values of above and then substitute as

Look up Math.Abs in MSDN (on the internet).
QUOTE:
//I want to compare percent closing price of one dataseries with respect to other

CODE:

#7
Thanks Eugene.

Best regards,

Sofia

#### sofia

#8
How to set two different intraday scales.

My bar scale is 10min. i.e I am setting Scale as 10min on charts. But I want to use 30min interval for my position count.i.e I want to sample data after 30min.

[Can I use something like
// SetScale30min(); ??? similar to SerScaleDaily(); as the resolution is smaller and multiple of 30
DataSeries thirtyminclose = GetExternalSymbol( "SPY", true ).Close;
RestoreScale();
thirtyminclose = Synchronize( thirtyminclose );

{
int nn = Bars.BarInterval;

// setting the time interval of 30min that I want to use for my position count
int num = ( 30 / nn ) - 1;

for(int bar = 20; bar < Bars.Count; bar++)
{

bool up30 = thirtyminclose[bar] > thirtyminclose[bar-1]; //i.e bool up30 is checked after 30min.
bool up10 = Close[bar] > Close[bar-1]; //i.e bool up10 is checked after 10min

bool up = (up30 && up10);

Thanks,

Sofia

#9

#### sofia

#10
Hi Eugene,

Thanks for the link. I tried using that time frame, the code is getting compiled but cannot execute. While running the strategy I am getting run time error. I am using wealthlab Pro 6.2
SetBarColor( bar, Color.Blue);

The error:
Runtime error: Object reference not set to an instance of object

Here is my code
=================
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
protected override void Execute()
{

DataSeries SPY = GetExternalSymbol( "SPY", true ).Close; // Set to external intraday scale(less than 30min) 10 min
DataSeries intra30 = GetExternalSymbol( "SPY 30_30", true ).Close; // set to fixed 30min scale

///30 min sma
DataSeries SMA1_30 = SMA.Series( intra30, 10 );
DataSeries SMA2_30 = SMA.Series( intra30, 21 );

DataSeries SMA1 = SMA.Series( SPY, 10 );
DataSeries SMA2 = SMA.Series( SPY, 21 );

SMA1_30 = Synchronize( SMA1_30 ); //synchronize to external intraday scale
SMA2_30 = Synchronize( SMA2_30 );
PlotSeries( PricePane, SMA1_30, Color.Red, WealthLab.LineStyle.Solid, 1 );
PlotSeries( PricePane, SMA2_30, Color.Blue, WealthLab.LineStyle.Solid, 1 );
PlotSeries( PricePane, SMA1, Color.Pink, WealthLab.LineStyle.Solid, 1 );
PlotSeries( PricePane, SMA2, Color.Azure, WealthLab.LineStyle.Solid, 1 );

for(int bar = 20; bar < Bars.Count; bar++)
{
bool up30 = SMA1_30[bar] > SMA2_30[bar];
bool down30 = SMA1_30[bar] < SMA2_30[bar];

bool up = SMA1[bar] > SMA2[bar];
bool down = SMA1[bar] < SMA2[bar];

bool blue = up30 && up;
bool yellow = down30 && down;

if (blue) SetBarColor( bar, Color.Blue);
if (yellow) SetBarColor( bar, Color.Yellow);

}

}
}

}

==========

Thanks,

Sofia

#### Eugene

#11
Here's where the potential problem develops:
CODE:

1. The SPY may be ambiguous between DataSets, and you may as well be calling the Daily SPY with this. Follow the KB article and call exactly as suggested there.
2. Unless you have a symbol "SPY 30_30", the intra30 definition is plain invalid - you're confusing a DataSet name with symbol name.

As both calls are incorrect, I'd suggest taking a look at the QuickRef. Don't break the KB article code - follow it, learn the overloaded calls to GetExternalSymbol, and the error will go away.

#### sofia

#12
Eugene,

Thanks for the info. One more question, how to create offset series in wl6 code ?

I want to code following from older wl4 scripts to equivalent WL6 code

H = (int)OffsetSeries(SMASeries(WL_HIGH, 2), -10);
L = (int)OffsetSeries(SMASeries(WL_LOW, 2), -10);

Thanks,

Sofia

#### Eugene

#13
It's >>. See DataSeries Object in the QuickRef for a code snippet.

#### sofia

#14
Eugene,

Is this correct

DataSeries H = Highest.Series( High, 2) >> 10;
DataSeries L = Lowest.Series(Low,2) >> 10;

Thanks,

Sofia

#### Eugene

#15
The syntax is correct. But where you got with this is different from where you started. It's a highest 2-bar high shifted 10 bars to the right whereas your previous reply showed a 2-bar SMA of highs/lows shifted 10 bars. Consequently:
CODE:

P.S. I see you're scared of code tags? You never used them in this thread. I promise they will not bite. ;) When pasting code snippets, click the CODE button and place your code inside.

#### sofia

#16

Next time I will follow your instructions to use CODE tags. Also a question out of curiosity. You can choose not to answer.

-> Which is your favourate trading strategy that you have posted so far or any other public strategy on "strategies and trading site".

Best regards,

Sofia

#### sofia

#17
Hello,

Is it possible to display Renko bar boxes as graphics over the standard price display chart style in bars.
Since we cannot use 2 different chart style on one chart. I want to use bars for trading purposes, but want to overlap corresponding renko bar as an graphic overlay over regular prices.Since renko filters out noise and time, the box size of renko will display correponding highs and lows. This is very similar to Darva's box trading strategy on public strategy. Except for Darvas box this will be a Renko box.

If it is possible any help on how to implement it will be very helpful.

Thanks,

Sofia

#### Eugene

#18
QUOTE:
Is it possible to display Renko bar boxes as graphics over the standard price display chart style in bars.

Yes, hit Ctrl-Y (or right-click on the chart and select "Chart Style Settings") and check "Overlay HLC chart".

P.S. Please ask new questions which does not have a direct relation to your first post in a different/new thread. Renko is a perfect example of such question.