# Has work been done on PID controllers for optimal trading?

Commonly, stochastic control is the basis for optimal trading (either in execution or market-making). Has any research been done (or why not, if none) as to PID controllers for these applications?

Check the code below for basic logic. You may need to improvise it (may be).Just a quick and dirty work. In case it works, reshare. Enjoy !!

How PID controller works - a crash (fast fast) course ?

• PID controller works on Error to minimise error !! Wow, that is mouthful. Error(e) = SetPoint (SP) - ProcessValue (PV). This is the most basic thing.
• Now there are three terms in PID controller equation which are actually multipliers
1. kp - this dictates how much the output change with each unit change if error (repeat error).
1. Kd - Tricky part starts from here. Kd is a multiple also but it is multiple of rate of change of error i.e. how much error is changing wrt time -3. Ki - Ki is also multiple but it is multiple of a term which has past memory of error i.e. Ki multiples summation of error.

Now you see...Kp dicatats how much you output changes wrt to difference between setpoint and actual value i.e. proprotional part , Kd dicatact how the rate of change of error affect the output, ki dictate how much error is minimised. Suppose Setpoint and output becomes same then error is zeror, there is no rate of change of error and summation of error is also zero.

 //@version=5 indicator("PID Controller", overlay=false) // Input Variables lookback = input.int(title="Lookback Period", defval=20, minval=1) kp = input.float(title="Kp", defval=0.1, minval=0) kd = input.float(title="Kd", defval=0.1, minval=0) ki = input.float(title="Ki", defval=0.1, minval=0) price_src = input(close, title="Price Source") // Variables var float error = 0.0 var float error_sum = 0.0 var float error_diff = 0.0 var float pid = 0.0 // Arrays var float[] pid_array = array.new_float(0) // Loop for i = 0 to 10 // Calculate error and PID error := price_src - ta.sma(price_src, lookback) error_sum := error_sum + error error_diff := error - nz(error[1]) pid := kperror + kierror_sum + kd*error_diff // Add PID value to array array.push(pid_array, pid) // Wait for next bar //bar_wait(0) // Calculate average PID value var pid_sum = 0.0 for i = 0 to array.size(pid_array)-1 pid_sum := pid_sum + array.get(pid_array, i) var float pid_avg = pid_sum / array.size(pid_array) // Plotting plot(pid_avg, color=color.green, linewidth=1, title="PID") 
• This is just a general implementation of PID (available in any Control book) it has nothing to do with trading or marketmaking, which was the subject of the question. And the question asked for research results, of which AFAIK there are not any published for these applications. Commented Apr 19, 2023 at 7:14