high of first day
Author: maninjapan
Creation Date: 11/20/2009 12:25 PM
profile picture

maninjapan

#1
Hi Guys, what would I add to this Stop order to refer to the low of the first bar of day?

Thanks

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

Cone

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

maninjapan

#3
Sorry Cone, need to ask you for some more help on this.....
I added it, but it doesnt seem to be right...

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

Eugene

#4
CODE:
Please log in to see this code.

Right.
CODE:
Please log in to see this code.

Correct.
CODE:
Please log in to see this code.

These brackets are wrong. Remove them.
profile picture

maninjapan

#5
Thanks Eugene, works fine now. Id like to change the exit to, exit at the close of the day, not just the intraday bar. Any examples of how to do that around?
I would also like to stop it entering on the 1st bar of the day too...
Thanks!
profile picture

Eugene

#6
QUOTE:
Id like to change the exit to, exit at the close of the day, not just the intraday bar.

Please see this KB article in the Wealth-Lab 5 Wiki:

Intraday / Multi-Time Frame | Keep from holding positions overnight
QUOTE:
I would also like to stop it entering on the 1st bar of the day too...

See Bars object > IntradayBarNumber in the QuickRef.
profile picture

maninjapan

#7
Thanks Eugene, works good. Can you point me in the direction of an example to stop pyramiding. (getting same side entries of every bar at the moment).

Thanks,
profile picture

maninjapan

#8
I attempted the following but didnt get very far....

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

Eugene

#9
You can find an article on pyramiding in the same Wealth-Lab 5 Wiki section I pointed in a message earlier today.

Warning: until version 5.6, pyramiding in portfolio simulation mode can result in pyramided entries created w/o the initial (base) position taken. A PosSizer already coded will take care of that.
profile picture

maninjapan

#10
Eugene, I had a look and i figure it has something to do with 'ActivePositions.Count'
but when I added it and ended up with the following I now get nothing (it compiles ok though....)
Am I even close?

QUOTE:
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()
{
for(int bar = 1; bar < Bars.Count; bar++)
{ for (int p = ActivePositions.Count - 1; p > -1; p-- ) // Do I need this part here?


{ int firstBarToday = bar - Bars.IntradayBarNumber(bar);
double lowOfFirstBar = Low[firstBarToday];

double highOfFirstBar = High[firstBarToday];

if( Bars.IsLastBarOfDay(bar) )
{
// exit on the last bar of the day
if( IsLastPositionActive )
ExitAtClose( bar, LastPosition, "Last Bar" );

}
else
{
if (ActivePositions.Count > -1 )
{
ShortAtStop(bar + 1, lowOfFirstBar - Bars.SymbolInfo.Tick, "Group2|");
}

else
if (ActivePositions.Count < 1 )
{
BuyAtStop(bar + 1, highOfFirstBar + Bars.SymbolInfo.Tick, "Group1|");
}
}
}
}
}
}
}
profile picture

Eugene

#11
Oops, sorry - I misread your reply which actually said "stop pyramiding". There are no specific pyramid rules and you seem to keep adding a twist every day, so I thought it has to do with adding pyramiding.

QUOTE:
(getting same side entries of every bar at the moment).

Your code is working exactly as written. There's no "pyramiding" at all. You have yet to implement selling/shorting at the end of day yet, until then it will bail out every bar.

Dismiss the ActivePositions thing, and concentrate on the link in my reply @ 11/23/2009 5:02 AM.

In addition, here's how you need to fix your entries:
CODE:
Please log in to see this code.

P.S. Good try on using tags, just not the QUOTE tag but the CODE tag should be used to properly format the code.
profile picture

maninjapan

#12
Thanks Eugene, yes, Im trying to build it step by step. More a learning excercise than anything. Below is the code as it stands (with the Activepositions thing removed).

The problem I am having is it is getting multiple long entries. The strategy is supposed to be a simple ORB (Im using 30 mintue data). Goes long 1 tick above the high of the first bar, goes short at the low minus 1 tick. It should reverse where required and Close out at the close of the last bar of the day. However, as the code stands, it enters multiple positions in the same direction. If the stock trends down all day, it enters short ever bar close.

CODE:
Please log in to see this code.

profile picture

Eugene

#13
See how it should be:
CODE:
Please log in to see this code.
profile picture

maninjapan

#14
Thanks Eugene, I guess its getting there, not getting multiplt entries. But now it enters on the first bar of the day and exits on the last. It then skips the next day, and then enters on the first close of the following day.... Did I miss something?
CODE:
Please log in to see this code.
profile picture

Eugene

#15
My code above contained an extra condition from your code in an inappropriate place (the inevitable effect of multi-tasking). Sorry for an error in the Wiki article that was misleading you.

Move if( Bars.IsLastBarOfDay(bar) ) to where it belongs i.e. on top of the ExitAtClose method. See the updated example above.
profile picture

maninjapan

#16
ok Eugene I can almost taste it. That fixed that problem, only one thing left, its not reversing the positions. If it goes long at 1 tick above the high, its should reverse if it goes below the low - 1 tick. That should have it running perfect....
profile picture

Eugene

#17
Since reversing wasn't mentioned anywhere, it isn't the problem. ;) We can go on forever adding yet another ad-lib, the problem is that we don't have that forever.

Looks like you're moving too fast. To keep your busy, take a look at some bundled strategies that do reverse the positions.
profile picture

maninjapan

#18
Eugene, I do appreciate your patience on this, perhaps I am getting in above my head, but I did actually go over the strategy including reverse entry (see 11/23/2009 3:11 PM)
QUOTE:
Thanks Eugene, yes, Im trying to build it step by step. More a learning excercise than anything. Below is the code as it stands (with the Activepositions thing removed).

The problem I am having is it is getting multiple long entries. The strategy is supposed to be a simple ORB (Im using 30 mintue data). Goes long 1 tick above the high of the first bar, goes short at the low minus 1 tick. It should reverse where required and Close out at the close of the last bar of the day. However, as the code stands, it enters multiple positions in the same direction. If the stock trends down all day, it enters short ever bar close.


I will take your advice and have a look, but if there are any specific examples that come to mind, it would be much appreciated. I'll also be sure to post the finished product.

Thanks.
profile picture

Eugene

#19
QUOTE:
I will take your advice and have a look, but if there are any specific examples that come to mind, it would be much appreciated.

1. Wealth-Lab 5 Wiki FAQ | Strategies and WealthScript > How to create a stop-and-reverse system in a Rule-based Strategy?
2. Here's a dedicated Wiki article on WealthScript Techniques | Creating a Stop-And-Reverse (SAR) system.
CODE:
Please log in to see this code.
profile picture

maninjapan

#20
Thanks Eugene, thats awesome!! Ive jsut tried it on 30 minute bar chart (imported ASCII data) though and it works well for the most part but there are some days where there are no trades when there is a clear break of the opening range. Any ideas on why this might be happening?


Thanks again for the code though, and those links.
profile picture

Eugene

#21
Can it be explained by your position size and commissions/slippage settings?
profile picture

maninjapan

#22
Dont think so... There are a few days here and there where there are no trades (a couple are strong down trend days) and then it trades as expected. Ive run it on raw profit mode with 1000 shares per contract. Other times it misses the first break, but then enters on the reverse. Id attach a screen shot, but not sure how.
profile picture

Eugene

#23
Dreaded multi-tasking several projects and support tickets! :) I apologize. Please copy the updated strategy from the same post above (edited).
profile picture

maninjapan

#24
Eugene, your time on this is much appreciated. Works like a charm. Looking forward to testing and tweaking!

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).