Hi
I want to define an initial stop after opening a long position which depends on the entry price and the then actual ATR. Right after the buy-order, I define the variable inistop accordingly. But somehow WLD does not recognize the value, because the stop is never executed. What is my error, and how has the code to be arranged ?
Thx & Kind Regards
QUOTE:
protected override void Execute()
{
double inistop=0;
PlotStops();
for(int bar = 100; bar < Bars.Count; bar++)
{
if (IsLastPositionActive)
{
//code your exit rules here
SellAtStop(bar,LastPosition,inistop,"Initial-Stop");
}
else
{
//code your entry rules here
if ( .... )
{
BuyAtLimit(bar+1,Bars.Close[bar],"Long-Entry");
inistop=LastPosition.EntryPrice - ATR.Value(bar, Bars, 20);
}
}
}
Size:
Color:
CODE:
Please log in to see this code.
Size:
Color:
Trading methods return a Position object if it was established. In other words, first you need to check that the Position has been created - by making sure it's not null.
Size:
Color:
Hello Eugene
thx again for the quick post, but I have to admit, I am bit lost now.
1. in my version, when it has executed the buyatlimit-line, it should know that a position is established and therefore should be able to calculate the inistop-variable ?
2. when I substitute my inistop-line with your suggestion, the stop is placed correctly, but mysteriously, it opens not one but two long-positions (and establishes only one stop) ???
Your support is highly appreciated
Size:
Color:
I don't believe in mystery, rather in an error somewhere else in the code.
P.S. That SellAtStop(bar..., initstop) alone looks very suspicious i.e. the variable is set at bar+1 and its value is used at bar+0, although I'm not telling it's the culprit.
Size:
Color: