OPEN-SOURCE SCRIPT
Double Top/Bottom Screener with Distance.

Thank you for providing the error messages! There are two issues to address based on your input:
Error: "Value with NA type cannot be assigned to a variable that was defined without type keyword"
This occurs because in Pine Script, when a variable like distanceToNearest is used without an explicit type declaration (e.g., var float distanceToNearest), assigning na directly to it can cause a type mismatch error if the variable’s type isn’t pre-defined. The fix is to either declare distanceToNearest with a type (e.g., var float) or ensure the assignment aligns with Pine Script’s typing rules.
Warning: "Version 5 of Pine Script® is outdated. We recommend using the current version, which is 6. (PINE_VERSION_OUTDATED)"
TradingView has updated to Pine Script version 6, which includes new features and improvements. While version 5 still works, upgrading to version 6 is recommended for better compatibility and future support. The transition is mostly seamless, but we’ll need to adjust the script accordingly.
Error: "Value with NA type cannot be assigned to a variable that was defined without type keyword"
This occurs because in Pine Script, when a variable like distanceToNearest is used without an explicit type declaration (e.g., var float distanceToNearest), assigning na directly to it can cause a type mismatch error if the variable’s type isn’t pre-defined. The fix is to either declare distanceToNearest with a type (e.g., var float) or ensure the assignment aligns with Pine Script’s typing rules.
Warning: "Version 5 of Pine Script® is outdated. We recommend using the current version, which is 6. (PINE_VERSION_OUTDATED)"
TradingView has updated to Pine Script version 6, which includes new features and improvements. While version 5 still works, upgrading to version 6 is recommended for better compatibility and future support. The transition is mostly seamless, but we’ll need to adjust the script accordingly.
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้มันเป็นโอเพ่นซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันการทำงานของสคริปต์ได้ ขอแสดงความชื่นชมผู้เขียน! แม้ว่าคุณจะสามารถใช้งานได้ฟรี แต่อย่าลืมว่าการเผยแพร่โค้ดซ้ำนั้นจะต้องเป็นไปตามกฎระเบียบการใช้งานของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้มันเป็นโอเพ่นซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันการทำงานของสคริปต์ได้ ขอแสดงความชื่นชมผู้เขียน! แม้ว่าคุณจะสามารถใช้งานได้ฟรี แต่อย่าลืมว่าการเผยแพร่โค้ดซ้ำนั้นจะต้องเป็นไปตามกฎระเบียบการใช้งานของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมที่ ข้อกำหนดการใช้งาน