Plotting Indicators vs. Monitoring them
Author: Tobey
Creation Date: 12/17/2009 11:53 AM
profile picture

Tobey

#1
Thanks to Cone I am able to plot a lovely indicator of the up vs down volume.

The plot requires the loop
for(int bar = 1; bar < Bars.Count; bar++)

I added a Strategy of looking for new highs. It back tested fine with the same code
for(int bar = 1; bar < Bars.Count; bar++)

As I understand it, to turn this Strategy Monitoring I need to change

for(int bar = 1; bar < Bars.Count; bar++)
to
int bar = Bars.Count - 1;

This works but then the indicator plot is lost.

I could create two Strategies to explore the same conditions. For example:

StrategyOneChart &
StrategyOneMonitor

The first one for viewing and the second one for monitoring. Is this the way to go or is there a more eloquent solution?

Once again, thanks for the help !
Tobey

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

Cone

#2
QUOTE:
As I understand it, to turn this Strategy Monitoring I need to change
No, that change is not required and would be wrong for the S. Monitor. If you want to make it a simple screener (no backtest/Position history), then you could do that change.

QUOTE:
This works but then the indicator plot is lost.
You can use as many loops in Strategy code as required. For example, you might have one or more loops prior to and separate from the trading loop to create indicators.
profile picture

Tobey

#3
Hi Cone,

Thanks! I've got it running now with the two loops.

for(int bar = 1; bar < Bars.Count; bar++)
and
for(int bar = GetTradingLoopStartBar(65); bar < Bars.Count; bar++)

So in each Loop I would adjust "int bar = " to the number make the first calculation?
In the example below 65 for a 65 day moving average.


Also using the code

CODE:
Please log in to see this code.


I think I have added a stop loss at 4% under the buy price to a sell signal "Sell when the 10day moving average goes below the 21day moving average." Am I reading the code right?
profile picture

Cone

#4
QUOTE:
So in each Loop I would adjust
Sure, you can do it that way. GetTradingLoopStartBar is really meant to be used as a shortcut to determine the first bar if you've programmed sliders. The QuickRef covers this.

QUOTE:
Am I reading the code right?
Yes, that's right, but there's a minor logic error in the code that is of no consequence, but also a logical peeking error...

First The "else" doesn't belong after !SellAtStop since the idea is to execute the following statements if SellAtStop fails (returns false). Saying it another way, you don't want to execute the subsequent statements if SellAtStop results in a trade (returns true).

Better (but still peeking)
CODE:
Please log in to see this code.


The peeking problem comes from the fact that you're executing the SellAtStop on the next bar before the SellAtMarket. AtMarket signals must come first because they occur at the open. In other words, at the end of the current bar, you should check if the AtMarket condition is true, and if it's not, execute the SellAtStop.

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

Tobey

#5
Hi Cone,

Thanks Again! It's a lot to learn, Hopefully I'm catching on.

Tobey
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).