Reply

SQX’s new method? SL/PT based on fixed pips or ATR value.

5 replies

eastpeace

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

Visit profile

5 years ago #240480

In the TS code, I found the SL/PT calculation is different between SQX and SQ 3.8.

SQX style:

if(MarketPosition > 0) then begin
If BarsSinceEntry = 0 then begin
LongSL = 0;
LongTrailingStop = 0;
end;
LongSLPlaced = false;
// StopLoss
LongSL = EntryPrice – 450.0 * tickSize;
LongSL = SQ_CorrectMinMaxSLPT(LongSL, MinimumSLPT, MaximumSLPT, true);

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

// ProfitTarget
PT = EntryPrice + 955.0 * tickSize;
PT = SQ_CorrectMinMaxSLPT(PT, MinimumSLPT, MaximumSLPT, false);
Sell(“LongPT”) next bar at PT limit;

SQ 3.8 style

{
Tradestation Strategy of 25_03_2017Strategy 1.3073

Generated by StrategyQuant version 3.8.1
Generated at Wed Apr 17 08:20:00 GMT 2019

Tested on SHEF_RB, H1, 27.03.2009 – 03.03.2017
}

inputs:

//——————————————————————
// Strategy Options
MaxTradesPerDay(10),
ExitOnClose(false),
LimitSignalsToRange(false),
TimeRangeFrom(0900),
TimeRangeTo(1455),

//——————————————————————
// Money Management Parameters
// MoneyManagementType:
//  0 – fixed size (from TradeSize)
//  1 – risk fixed % of account equity
//  2 – risk fixed amount in $
//——————————————————————
CapitalSize(10000),
MoneyManagementType(0),
TradeSize(1.0),
SizeRounding(0),
RiskPerTrade(0), // in % or in $, depending on MM type
MaxTradeSize(0);

vars:
tickSize(MinMove/PriceScale),
PriceLevel(0), NumberOfShares(0),
LongSL(0),LongPT(0),
ShortSL(0),ShortPT(0),
SLSize(0),
LongEntryCondition(false),ShortEntryCondition(false),
LongExitCondition(false),ShortExitCondition(false);

// ——————————————
// ENTRY RULES
// ——————————————
if(LimitSignalsToRange = false or (Time >= TimeRangeFrom and Time < TimeRangeTo)) then begin

// Long ——–
if(MaxTradesPerDay = 0 or EntriesToday(Date) < MaxTradesPerDay) then begin
LongEntryCondition = (High[18] < Open[1]);
if(LongEntryCondition = true) then begin
SLSize = Round2Fraction((5.88 * AvgTrueRange(109)[0]));
NumberOfShares = SQ_MoneyManagement(CapitalSize, SLSize, MoneyManagementType, TradeSize, SizeRounding, RiskPerTrade, MaxTradeSize);

Buy(“LongMarket”) NumberOfShares shares next bar at market;
end;
end;

// Short ——–
if(MaxTradesPerDay = 0 or EntriesToday(Date) < MaxTradesPerDay) then begin
ShortEntryCondition = (Low[18] > Open[1]);
if(ShortEntryCondition = true) then begin
SLSize = Round2Fraction((5.88 * AvgTrueRange(109)[0]));
NumberOfShares = SQ_MoneyManagement(CapitalSize, SLSize, MoneyManagementType, TradeSize, SizeRounding, RiskPerTrade, MaxTradeSize);
SellShort(“ShortMarket”) NumberOfShares shares next bar at market;
end;
end;
end;

// ——————————————
// MANAGE TRADE & EXIT RULES
// ——————————————

// Long ——–
if(MarketPosition > 0) then begin
If BarsSinceEntry = 0 then begin
LongPT = 0;
LongSL = Round2Fraction(EntryPrice – (5.88 * AvgTrueRange(109)[0]));
end;

 

// Profit trailing
PriceLevel = Round2Fraction((3.23 * AvgTrueRange(126)[0]));
if(PriceLevel > 0) then begin
PriceLevel = Close – PriceLevel;
if(LongSL = 0 or LongSL < PriceLevel) then
LongSL = PriceLevel;
end;

if(LongPT > 0) then
Sell(“LongPT”) next bar at LongPT limit;
if(LongSL > 0) then
Sell(“LongSL”) next bar at LongSL stop;
end;

// Short ——–
if(MarketPosition < 0) then begin
If BarsSinceEntry = 0 then begin
ShortPT = 0;
ShortSL = Round2Fraction(EntryPrice + (5.88 * AvgTrueRange(109)[0]));
end;

 

// Profit trailing
PriceLevel = Round2Fraction((3.23 * AvgTrueRange(126)[0]));
if(PriceLevel > 0) then begin
PriceLevel = Close + PriceLevel;
if(ShortSL = 0 or ShortSL > PriceLevel) then
ShortSL = PriceLevel;
end;

if(ShortPT > 0) then
BuyToCover(“ShortPT”) next bar at ShortPT limit;
if(ShortSL > 0) then
BuyToCover(“ShortSL”) next bar at ShortSL stop;
end;

if(ExitOnClose) then
SetExitOnClose;

 

It’s OK when strategy using fixed pips. They have same effort.

But when we use ATR’s SL and PT setting, The two method didn’t do the same thing.

In SQX’s style, the SL and PT value would be changed bar by bar, because the ATR is not the fixed one.

I don’t like this new method, and is this a bug?

 

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

5 years ago #240493

Hello,

there have been modifications done to TS code compared to SQ3. If you have issues with a strategy SL/PL when ATR is used please attach it into our roadmap so developers can check it https://roadmap.strategyquant.com/projects/sq4/tasks

0

eastpeace

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

Visit profile

4 years ago #242341

Hello, Tomas,

Here is the post in the task of roadmap. Would you please check it? I think it’s a basic and important issue.

 

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

0

tomas262

Administrator, sq-ultimate, 2 replies.

Visit profile

4 years ago #242343

Thanks, developers will check the issue and resolve as soon as possible

0

Mark Fric

Administrator, sq-ultimate, 2 replies.

Visit profile

4 years ago #242377

I understand your point, but it is like this on purpose and it is because of money management.

 

See, if you have MM to risk for example 5% of your account balance, it is computed from Stop Loss. So that you’ll lose only 5% when your SL is hit.

This is why we need SL to be computed at the time when trade is placed, and it cannot be dynamically recomputed every bar.

 

 

 

Mark
StrategyQuant architect

0

eastpeace

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

Visit profile

4 years ago #242408

You are right, Mark. I agree with you in the first half.

And in the TS/MC code now , the SL level and PT target is truly changed every bar when it hold position. You can print the SL/PT value in MC .  Please checked it again.

With Stop entry order, we know the entry price firstly.   A little trouble when using Market order. In bar by bar mode of MC, it can’t compute the SL/PT with ATR at the same time of entry.

We can assume that the entry price is the close of   previous signal bar.

 

if marketpostion<>0  then begin

print(“date: “,date,”,mp=”,marketposition,”,entryprice=”,entryprice,”,atr=”,SQ_ATR(20)[1],”,sl=”,LongSL);

end

0

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