5. Given a convex 2019-gon, where no three diagonals intersect at a single point, the intersection of two diagonals inside the 2019-gon is called a "knot". If two knots lie on the same diagonal, they are called "adjacent"; if a closed path is formed by connecting adjacent knots, and any three consecutive knots do not lie on the same diagonal, then this closed path is called a "loop". Find the maximum number of colored knots such that no loop is formed by the colored knots (i.e., only colored knots are included in the loop).
5. Consider a more general problem, replacing 2019 with a positive integer $n (n \geqslant 4)$.

Below is the proof: In a convex $n$-gon where no three diagonals have a common point, the maximum number of colored intersections such that no colored cycle exists is $\frac{n(n-3)}{2}-1$.

First, prove that the number of colored intersections must be less than $\frac{n(n-3)}{2}$.
Proof by contradiction.
Assume the number of colored intersections is not less than $\frac{n(n-3)}{2}$. Consider a planar graph where the vertices correspond to the diagonals of the polygon, and the edges correspond to the colored intersections. Since the number of diagonals in a convex $n$-gon is $\frac{n(n-3)}{2}$, the number of edges in this planar graph is at least the number of vertices. Therefore, the graph contains a cycle. It is easy to see that the cycles in the graph correspond one-to-one with the colored cycles in the polygon. Thus, there exists a colored cycle, which is a contradiction.

Next, find a way to color $\frac{n(n-3)}{2}-1$ intersections such that no colored cycle exists. Use induction.
When $n=4$, the conclusion is obvious.
Assume the conclusion holds for a convex $n$-gon, i.e., for any convex $n$-gon, there exists a way to color $\frac{n(n-3)}{2}-1$ intersections such that no colored cycle exists.
Now consider a convex $(n+1)$-gon $A_{1} A_{2} \cdots A_{n+1}$.
For the $n$-gon $A_{1} A_{2} \cdots A_{n}$, by the induction hypothesis, $\frac{n(n-3)}{2}-1$ intersections have been colored. Adding the vertex $A_{n+1}$, the edge $A_{1} A_{n}$ in the $n$-gon $A_{1} A_{2} \cdots A_{n}$ is transformed into a diagonal in the convex $(n+1)$-gon $A_{1} A_{2} \cdots A_{n+1}$, and $n-2$ additional diagonals $A_{n+1} A_{i} (i=2,3, \cdots, n-1)$ are added. Thus, the diagonal $A_{1} A_{n}$ contains exactly $n-2$ intersections (corresponding to the added diagonals), and all of them are colored.

Finally, color one intersection on a diagonal passing through $A_{n+1}$ that is not on $A_{1} A_{n}$, for example, the intersection of $A_{n+1} A_{2}$ and $A_{1} A_{3}$ (due to the convexity of the polygon, this intersection is inside the $(n+1)$-gon, so it is an "intersection"). In total, there are
$$
\frac{n(n-3)}{2}-1+(n-1)=\frac{(n+1)(n-2)}{2}-1
$$
colored intersections. Among the newly colored $n-1$ points, adjacent intersections only appear on the diagonals $A_{1} A_{n}$ or $A_{n+1} A_{2}$. Additionally, each diagonal passing through $A_{n+1}$ contains one colored intersection, meaning no adjacent colored intersections appear on these diagonals.

It is easy to see that if a colored cycle exists, since the colored intersections in $A_{1} A_{2} \cdots A_{n}$ do not form a cycle, at least two diagonals passing through $A_{n+1}$ must have colored intersections not on $A_{1} A_{n}$, which is a contradiction. Therefore, no colored cycle exists.

In summary, the maximum number of colored intersections in a 2019-gon is
$$
\frac{2019(2019-3)}{2}-1=2035151.
$$