If you using a simple keltner channel code for example, and then using the stops and targets , once a target has been hit, the code opens a second or third position straight away because the conditions are still present.
How do I stop this from happening so only one trade per crossover of the channel , with a stop and profit in place ?
Avoiding multiple entries.
- TJ
- Posts: 7745
- Joined: 29 Aug 2006
- Location: Global Citizen
- Has thanked: 1033 times
- Been thanked: 2224 times
Re: Avoiding multiple entries.
I am using the generic strategies found on the signal directory.
[IntrabarOrderGeneration = false]
inputs: Price( Close ), Length( 20 ), NumATRs( 1.5 ) ;
variables: var0( 0 ), var1( 0 ), var2( 0 ), var3( false ), var4( 0 ) ;
var0 = AverageFC( Price, Length ) ;
var1 = NumATRs * AvgTrueRange( Length ) ;
var2 = var0 + var1 ;
condition1 = CurrentBar > 1 and Price crosses over var2 ;
if condition1 then
begin
var3 = true ;
var4 = High ;
end
else
begin
condition1 = var3 and ( Price < var0 or High >= var4 + 1 point ) ;
if condition1 then
var3 = false ;
end;
if var3 then
Buy ( "KltChLE" ) next bar at var4 + 1 point stop
[IntrabarOrderGeneration = false]
inputs:
ShareOrPosition( 1 ),
ProfitTargetAmt( 5 ),
StopLossAmt( 1 ),
BreakevenFloorAmt( 0 ),
DollarTrailingAmt( 0 ),
PctTrailingFloorAmt( 0 ),
PctTrailingPct( 0 ),
ExitOnClose( false ) ;
if ShareOrPosition = 1 then
SetStopShare
else
SetStopPosition ;
if ProfitTargetAmt > 0 then
SetProfitTarget( ProfitTargetAmt ) ;
if StopLossAmt > 0 then
SetStopLoss( StopLossAmt ) ;
if BreakevenFloorAmt > 0 then
SetBreakeven( BreakevenFloorAmt ) ;
if DollarTrailingAmt > 0 then
SetDollarTrailing( DollarTrailingAmt ) ;
condition1 = PctTrailingFloorAmt > 0 and PctTrailingPct > 0 ;
if condition1 then
SetPercentTrailing( PctTrailingFloorAmt, PctTrailingPct ) ;
if ExitOnClose = true then
SetExitOnClose ;
Re: Avoiding multiple entries.
There's a keyword in EasyLanguage that may work here. I never used it though, so I don't know if it resets after each bar (which is what you'd presumably want, unless you just want one trade per day).
Code: Select all
once
- rrams
- Posts: 129
- Joined: 10 Feb 2011
- Location: USA
- Has thanked: 7 times
- Been thanked: 70 times
- Contact:
Re: Avoiding multiple entries.
Code: Select all
{ Keltner Channel bands appear above and below the market.
Prices that are within these bands are said to be normal prices.
A setup is established upon the breakout above the upper Keltner band.
Once the breakout has occurred, a buy stop order is placed at the high
of the bar on which the breakout occurred plus 1 point.
You can change the number of bars and the multiplier used to calculate
the Keltner Channel bands. }
inputs: Length(20), NumATRs(1.5);
vars: ATR(0), KCUp(0), Setup(false), BreakP(0);
ATR=AverageFC(Close, Length);
KCUp=NumATRs*AvgTrueRange(Length)+ATR;
if not Setup and Close crosses over KCUp then
begin
Setup=true;
BreakP=High+1 point;
end
else if Setup and (Close<ATR or High>=BreakP) then Setup=false;
if Setup then Buy("KltChLE") next bar BreakP stop;
- Vlada MultiCharts
- Posts: 293
- Joined: 22 Apr 2020
- Has thanked: 8 times
- Been thanked: 76 times
Re: Avoiding multiple entries.
Hello chilli,
I’m afraid your question is not rather explicit to advise anything precise.
Please take a look at the attached screenshot. You can see that the position is opened by an entry order for the first time, then it is closed by StopLoss and ProfitTarget. After that, the position is reopened when the code conditions are met.
MultiCharts strategy calculations go as follows: orders are generated all of the time except for the cases when the order generation conditions are not met. If you don’t want the orders to be generated, the following condition should be inserted:
In this case, if the condition is "false", orders will not be generated.
I’m afraid your question is not rather explicit to advise anything precise.
Please take a look at the attached screenshot. You can see that the position is opened by an entry order for the first time, then it is closed by StopLoss and ProfitTarget. After that, the position is reopened when the code conditions are met.
MultiCharts strategy calculations go as follows: orders are generated all of the time except for the cases when the order generation conditions are not met. If you don’t want the orders to be generated, the following condition should be inserted:
Code: Select all
if condition = true then
begin
Generate orders
end
- Attachments
-
- image.png
- (84.85 KiB) Not downloaded yet