Intraday drawdown circuit breaker?
Posted: Mar 19 2020
by ZaphodB
Good afternoon,
I'm working on a strategy that day trades only one instrument. Several trades per day. I want the strategy to stop trading for the day if a certain drawdown is reached and I want to be able to backtest it. I'm familiar with MaxIDdrawdown, however, that doesn't reset each day. If one day trips the circuit breaker then the breaker is forever tripped and the strategy will no longer trade, negating my backtest results. I don't want to re-invent the wheel but my search for a solution has been fruitless. Does a good/simple solution already exist for this? Thank you
Zaphod
Re: Intraday drawdown circuit breaker?
Posted: May 01 2020
by Svetlana MultiCharts
Hello Zaphod,
Here is a code example as an option for you:
Code: Select all
once cleardebug;
[IntrabarOrderGeneration = true]
Input: drowdown(500);// positive value
inputs: LECondition( C > O ) ;
inputs: SECondition( C < O ) ;
var: intrabarpersist trade_on(true);
var: intrabarpersist maxEQ(0);
var: intrabarpersist DD(0);
var: intrabarpersist EQ(0);
var: intrabarpersist maxDD(0);
var: intrabarpersist sbremain(0);
once EQ = i_OpenEquity;
once maxEQ = EQ;
EQ = i_OpenEquity;
if (maxEQ < EQ) then
begin
maxEQ = EQ;
end;
DD = maxEQ - EQ;
if (maxDD < DD) then
begin
maxDD = DD;
end;
//GVSetNamedDouble("drow_down", maxDD);
if (maxDD >= drowdown) then begin
trade_on = false;
maxEQ = EQ;
maxDD = 0;
sell (" close drow down (sell) ") next bar at market;
buytocover (" close drow down (buy) ") next bar at market;
sbremain = 1;
end;
if sbremain > 0 and sessionlastbar = true and barstatus(1) = 2 then
begin
sbremain = sbremain - 1;
if (sbremain = 0) then
begin
trade_on = true;
end;
end;
if trade_on then
begin
if LECondition then
begin
Buy ( "LE" ) next bar at market;
end;
if SECondition then
begin
Sell Short ( "SE" ) next bar at market ;
end;
end;
if sessionlastbar and barstatus(1) = 2 then
begin
maxEQ = EQ;
maxDD = 0;
end;
Re: Intraday drawdown circuit breaker?
Posted: May 22 2020
by ZaphodB
Hello Zaphod,
Here is a code example as an option for you:
Code: Select all
once cleardebug;
[IntrabarOrderGeneration = true]
Input: drowdown(500);// positive value
inputs: LECondition( C > O ) ;
inputs: SECondition( C < O ) ;
var: intrabarpersist trade_on(true);
var: intrabarpersist maxEQ(0);
var: intrabarpersist DD(0);
var: intrabarpersist EQ(0);
var: intrabarpersist maxDD(0);
var: intrabarpersist sbremain(0);
once EQ = i_OpenEquity;
once maxEQ = EQ;
EQ = i_OpenEquity;
if (maxEQ < EQ) then
begin
maxEQ = EQ;
end;
DD = maxEQ - EQ;
if (maxDD < DD) then
begin
maxDD = DD;
end;
//GVSetNamedDouble("drow_down", maxDD);
if (maxDD >= drowdown) then begin
trade_on = false;
maxEQ = EQ;
maxDD = 0;
sell (" close drow down (sell) ") next bar at market;
buytocover (" close drow down (buy) ") next bar at market;
sbremain = 1;
end;
if sbremain > 0 and sessionlastbar = true and barstatus(1) = 2 then
begin
sbremain = sbremain - 1;
if (sbremain = 0) then
begin
trade_on = true;
end;
end;
if trade_on then
begin
if LECondition then
begin
Buy ( "LE" ) next bar at market;
end;
if SECondition then
begin
Sell Short ( "SE" ) next bar at market ;
end;
end;
if sessionlastbar and barstatus(1) = 2 then
begin
maxEQ = EQ;
maxDD = 0;
end;
Thank you for that, I hadn't checked back here in a while, it looked like I wasn't going to get an answer to this.. but thank you. Will this code work if intrabar order generation is turned off? I think IBOG would mess with the rest of my code..