Coding a strategy with green/red candles
Author: gl2
Creation Date: 1/11/2010 12:35 AM
profile picture

gl2

#1
Hi,

I am trying to program a strategy that if there is a long entry signal,such as RSI oversold, then take the trade, if the next candle is green( Close[bar]>Open[bar]) and there is another long entry signal, ignore the signal and don't take another trade, until there is at least one red candle between the two long entry signals, and for short entry signals, it's the opposite, i.e, don't act on the second short signal until there is at least one green candle between the two short signals. The following is an example:

Candle 1: Green, Signal:Long( Long signal #1), Action: Take the long trade ( Long trade #1)
Candle 2: Green, Signal:None, Action: None
Candle 3: Green, Signal:Long( Long signal #2), Action: None ( Do NOT take the long trade)
Candle 4: Red, Signal:None, Action: None
Candle 5: Green, Signal:Long( Long signal #3), Action: Take the long trade ( Long trade #2)
Candle 6: Red, Signal:Short( Short signal #1), Action: Take the short trade ( Short trade #1)
Candle 7: Red, Signal:Short( Short signal #2), Action: None ( Do NOT take the short trade)
Candle 8: Green, Signal:None, Action: None
Candle 9: Green, Signal:None, Action: None
Candle 10: Red, Signal:Short( Short signal #3), Action: Take the short trade ( Short trade #2)

Here is my test code and it's not working, can anyone help me to solve this problem? Your help will be greatly appreciated.

Best regards

Greg

CODE:
Please log in to see this code.
profile picture

Eugene

#2
Designing a sound exit strategy is more important than working on entries, but I can't see this important component here. And it really matters, because w/o exits, the rules seem incomplete to me. See for yourself:

* When do you close the long trades? You don't want to enter more and more long and short trades until you run out of capital.
* The primary, the subsequent ones - closed by the same rule or different?
* Or is the short signal meant to close the long trades, and vice versa?

profile picture

Cone

#3
Also, do the signals occur if the RSI is simply above/below 70/30, or do they occur on crossover/under? How many Positions per symbol are allowed? Would short signals be an exit condition for long trades and vice versa? Requirements!

Note: You don't have to check for p.Active when looping through Positions in the ActivePositions list (they are for sure active).
profile picture

Eugene

#4
QUOTE:
Note: You don't have to check for p.Active when looping through Positions in the ActivePositions list (they are for sure active).

Sure, but since the whole code looks like made in Wizard, that's a "feature" of the wizard - an unnecessary checking for p.Active while looping through ActivePositions.
profile picture

Cone

#5
Sure is, thanks. I'll call that one in :)