Here is my correction:
The only difference is that I made you .....BuyAtStop ( Bar + 1, .....). I think you need to know first if the ADX is below a certain level. Then on the next bar you can take the action. Else I think the code looks ok. If you have any further questions please let me know (I emailed you too). Oh, and I added the indicator.
Regards.
Volker
{Use 30 minute bars}
var Bar: integer;
for Bar := 20 to BarCount - 1 do
begin
if LastPositionActive then begin
if (PositionLong( LastPosition )) and (ADX( Bar, 14 ) < 25) then
SellAtStop(Bar + 1, Lowest( Bar, #Low, 5), LastPosition,'Sell');
end;
if LastPositionActive then begin
if (PositionShort( LastPosition )) and (ADX( Bar, 14 ) < 25) then
CoverAtStop(Bar + 1, Highest( Bar, #High, 5), LastPosition,'Cover');
end;
if not LastPositionActive then begin
if ADX( Bar, 14 ) < 25 then begin
BuyAtStop( Bar + 1, Highest( Bar, #High, 15),'Buy');
ShortAtStop( Bar + 1, Lowest( Bar, #Low, 15),'Short');
end;
end;
end;
var ADXPane: integer;
ADXPane := CreatePane( 100, true, true );
PlotSeries( ADXSeries( 14 ), ADXPane, 009, #Thin );
DrawLabel( 'ADX(14)', ADXPane );
The only difference is that I made you .....BuyAtStop ( Bar + 1, .....). I think you need to know first if the ADX is below a certain level. Then on the next bar you can take the action. Else I think the code looks ok. If you have any further questions please let me know (I emailed you too). Oh, and I added the indicator.
Regards.
Volker
{Use 30 minute bars}
var Bar: integer;
for Bar := 20 to BarCount - 1 do
begin
if LastPositionActive then begin
if (PositionLong( LastPosition )) and (ADX( Bar, 14 ) < 25) then
SellAtStop(Bar + 1, Lowest( Bar, #Low, 5), LastPosition,'Sell');
end;
if LastPositionActive then begin
if (PositionShort( LastPosition )) and (ADX( Bar, 14 ) < 25) then
CoverAtStop(Bar + 1, Highest( Bar, #High, 5), LastPosition,'Cover');
end;
if not LastPositionActive then begin
if ADX( Bar, 14 ) < 25 then begin
BuyAtStop( Bar + 1, Highest( Bar, #High, 15),'Buy');
ShortAtStop( Bar + 1, Lowest( Bar, #Low, 15),'Short');
end;
end;
end;
var ADXPane: integer;
ADXPane := CreatePane( 100, true, true );
PlotSeries( ADXSeries( 14 ), ADXPane, 009, #Thin );
DrawLabel( 'ADX(14)', ADXPane );
