Here's one way.
Cut a 2x6 pine board long enough to fit on top of the bedrails and cross the bed as close to the stacks as would be safe. Make this board flush with the outside of the bed.
Cut a 2x6 pine board long enough to cross the bed on the floor of the bed under the other 2x6 that's on top of the bedrails. Make this board a tight fit between the walls of the bed.
Cut two 2x6 pine boards long enough to fit between the two 2x6s that cross the bed. Put one on each side of the bed.
Assemble that frame, using big 3.25" deck screws, and make it hell for strong so it won't tend to bend out of shape. You may need to pre-drill the screw holes to prevent the pine from coming apart.
Use a hole saw and drill a hole in the center of the top 2x6, where you want the flag staff to go through the top board and into the bottom board. Drill that same size hole in the center of the bottom 2x6. Make those holes almost exactly the right size so the flag staff will go though but not flop around in the holes.
Hold the top board to the pickup bedrails with 4 C-clamps. With 4 clamps, you can stop the forward and backward twisting of the frame - caused by the wind jerking on the flag.
Cut 2x4 pieces to fit between the bottom 2x6 and the front of the bed. When the pickup is moving, the flag will try to push the bottom board towards the front of the bed. So don't let it. Somehow attach those 2x4s to the 2x6 bottom board.
Insert the flag staff in the pre-cut holes.
When you have it right, then remove all the wood, and sand, prime and paint the wood to make it purrty. After the paint dries real good, reinstall the frame, clamp it down really good, and head to the parade. After you get ready to show off, then add the flag.
<font class="small">Code:</font><hr /><pre>
______
| |
| flag |
|______|
|
|
| top rail 2x6
-------------|-------------
| | |
| | |
| | |
-----------|-----------
bottom rail 2x6
</pre><hr />