Reply

SL and PT with atr for MultiCharts

2 replies

eastpeace

Customer, bbp_participant, community, sq-ultimate, 305 replies.

Visit profile

4 years ago #254805

Hello, Mark,

Although this issue has been closed with fixed status. I want to discuss the SL and PT with ATR for Multicharts again.

https://roadmap.strategyquant.com/tasks/sq4_5100

MC’s code is like this now.

———-
if(MarketPosition > 0) then begin
LongSLPlaced = false;
If BarsSinceEntry = 0 then begin
IntLongSL = 0;
IntLongTS = 0;
end;
// StopLoss
IntLongSL = Round2Fraction(EntryPrice – (StopLossCoef * SQ_ATR(20)[1]));
IntLongSL = SQ_CorrectMinMaxSLPT(IntLongSL, MinimumSL, MaximumSL, true);
….
————-

In the current code, since the ATR value will change every bar after entry. SL, PT and RR Ratio will also change, although this change is not too large. But it is also harmful.

Assuming that it hold a long postion, if the volatility decreases and the market  declines slowly, the stop loss will be enlarged.

 

Most strategy in MC runs by bar, update the signals and actions after the bar is closed. So when the stop entry order is triggered, it uses the previous ATR value (signal bar), not the current bar’s  (entry bar) .

So it not a problem for MM caculation. It can and should use the fixed ATR value. In the Mc’s code. it looks like this,

if(MarketPosition > 0) then begin
LongSLPlaced = false;
If BarsSinceEntry = 0 then begin
IntLongSL = entryprice – AtrSLmulti * ATRvalue[1] ;
IntLongPT = entryprice + AtrPTmulti * ATRvalue[1] ;
end;

 

That will be completely consistent with the ATR value used by the MM calculation when the entry condition is true.
This has nothing to do with global variables. It works well in MC. And I find that  code  generated by other software, it also set the SL in the if code block (BarsSinceEntry = 0)

 

Please reconsider this approach, thanks.

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

4 years ago #254893

Hello,

currently it has to be that the way it is. Meaning the SL needs to be modified according to the ATR value. In future we could modify this but now in respect of how TS works we rather keep it operating this way

0

eastpeace

Customer, bbp_participant, community, sq-ultimate, 305 replies.

Visit profile

4 years ago #254939

Another reason for the need to adjust the implementation of the initial stop loss and profit.

The strategy use indicator levels as stop loss.  The initial stop loss would become  a trailing stop loss or the indicator condition for exit.

This will weaken the effect of the exit rules(indicators condition for exit)  or the trailing stop method, or cause logical confusion.

 

//————————
// Orders Exits (SL, PT, Trailing) for Rule: Long entry
//————————
if(MarketPosition > 0) then begin
LongSLPlaced = false;
If BarsSinceEntry = 0 then begin
IntLongSL = 0;
IntLongTS = 0;
end;
// StopLoss
IntLongSL = Round2Fraction(SQ_EMA(High, EMAPeriod2)[3]);
IntLongSL = SQ_CorrectMinMaxSLPT(IntLongSL, MinimumSL, MaximumSL, true);
Sell(“LongSL”) next bar at IntLongSL stop;
LongSLPlaced = true;

 

As shown in the figure, if the initial stop loss runs in the correct logic, the middle stop loss should not happen.

 

When I modify the codes in MC. The strategy runs logically.  The trailing stop module will play the role it should play.

 

if(MarketPosition > 0) then begin

LongSLPlaced = false;

If BarsSinceEntry = 0 then begin
//IntLongSL = 0;
IntLongSL = Round2Fraction(SQ_EMA(High, EMAPeriod2)[3]);
IntLongSL = SQ_CorrectMinMaxSLPT(IntLongSL, MinimumSL, MaximumSL, true);

IntLongTS = 0;
end;

// StopLoss
//IntLongSL = Round2Fraction(SQ_EMA(High, EMAPeriod2)[3]);
//IntLongSL = SQ_CorrectMinMaxSLPT(IntLongSL, MinimumSL, MaximumSL, true);

Sell(“LongSL”) next bar at IntLongSL stop;
LongSLPlaced = true;

 

 

Attachments:
You must be logged in to view attached files.

0

Viewing 2 replies - 1 through 2 (of 2 total)