Thursday 27 July 2017

Mtf เฉลี่ยเคลื่อนที่ กลยุทธ์


ตัวบ่งชี้ MTF MTM MTF MTM เคลื่อนไหวเฉลี่ยทุกประเภทในช่วงเวลาใด ๆ คุณสามารถติดตามค่าเฉลี่ยเคลื่อนที่ได้ทุกวันในแผนภูมิ 30 นาที ซึ่งจะช่วยให้คุณติดตามทุกอย่างได้ในแผนภูมิเดียว คุณจะมีพื้นที่มากขึ้นสำหรับคู่สกุลเงินอื่น ๆ ค่าเฉลี่ยเคลื่อนที่มีการใช้กันอย่างแพร่หลายในการซื้อขาย forex พวกเขาจะใช้ในการระบุทิศทางแนวโน้มเช่นเดียวกับการหาเขตรองรับความช่วยเหลือ MTF Moving Average MT4 Indicator 8211 ขึ้นอยู่กับค่าเฉลี่ยเคลื่อนที่คุณสามารถใช้เพื่อหยุดการขาดทุนหรือการซื้อขายตามปกติ ไต่ระดับขึ้นเหนือ 8211 จุดแนวโน้มลดลง tf 8211 ระยะเวลาแหล่งที่มาของระยะเวลา 8211 ระยะเวลาของวิธีการเลื่อน 8211 วิธีการเฉลี่ยชุดข้อมูลการเปลี่ยนแปลง 8211 shift ตามลำดับ MTF ระบบการซื้อขาย SuperTrend - กลยุทธ์การซื้อขาย Forex - แหล่งข้อมูล Forex - สัญญาณการซื้อขายอัตราแลกเปลี่ยนเทรดดิ้งฟรีและการคาดการณ์ FX 444MTF ระบบซื้อขาย SuperTrend MTF Supertrend indicator combo ระบบการซื้อขาย MTF Supertrend เป็นระบบเทรนด์ที่บริสุทธิ์ตามมาซึ่งเป็นกลยุทธ์แบบผสมผสานโดยใช้ตัวบ่งชี้ Supertrend และค่าเฉลี่ยเคลื่อนที่เป็นระยะ ๆ 5 เทมเพลตนี้มีการตั้งค่าสำหรับกรอบเวลา 15 นาที คู่สกุลเงิน: วิชาเอก, EURUSD, GBPUSD, AUDUSD, NZDUSD, USDCAD, USDJPY, GBPJPY MTF Supertrend (TF 60, CCI 60, ATR -1) ตัวบ่งชี้การขึ้นลง (HL 4 เป็นตัวบ่งชี้การเคลื่อนไหวของราคาและการทาสีใหม่) ค่าเฉลี่ยของระยะเวลาในการเคลื่อนที่เฉลี่ย 5 ช่วง (ราคามัธยฐาน) กฎสำหรับระบบการซื้อขาย MTF Supertrend SuperTrend MTF ในหน้าต่างย่อยสีเขียว SuperTrend ชัดเจนในเส้นกราฟสีเขียวขึ้นลงตัวบ่งชี้จุดสีเขียวหากเงื่อนไขเหล่านี้เห็นด้วยกับตำแหน่งที่ยาวเมื่อเข้าสู่ภาวะถดถอยบน 5EMA SuperTrend MTF ในบรรทัดหน้าต่างย่อยสีม่วง SuperTrend ชัดเจนในสีของเส้นกราฟสีแดงขึ้นลงตัวบ่งชี้จุดสีแดงถ้าเงื่อนไขเหล่านี้เห็นด้วยตำแหน่งการเข้าสู่ระบบสั้น ๆ เมื่อราคาย้อนกลับไปที่ 5EMA เงื่อนไขเดียวกัน แต่ใช้ Supertrend ในชาร์ท UP และ 5 Ema เริ่มต้นหยุดขาดทุนในการแกว่ง highlow ก่อนหน้านี้ กำไรเป้าหมาย 20-30 pips หรือทำกำไรได้ในระดับจุดหมุนวิธีการใช้ Moving Averages ใน Forex Trading กลยุทธ์แบบ Multi Time Frames แบบเรียบง่าย แต่มีประสิทธิภาพ Moving Averages (MAs) ใน Forex Trading เป็นกลยุทธ์การซื้อขายที่ง่ายและมีประสิทธิภาพมากที่สุด และถ้าคุณใช้ในกรอบเวลาแบบมัลติเฟรม (MTF) คุณจะมีการตั้งค่าความน่าจะสูงสุดเสมอ แต่ค่าเฉลี่ยเคลื่อนที่เป็นค่าเฉลี่ยเคลื่อนที่คืออะไร? เพราะขึ้นอยู่กับราคาที่ผ่านมา พิจารณาระยะเวลาหนึ่งของ MA ซึ่งหมายความว่าหลังจากที่ปิดแต่ละตำแหน่ง MA และค่าจะเปลี่ยนไป นี่คือเหตุผลว่าทำไม MA จึงถือเป็นตัวบ่งชี้ที่ปกคลุมด้วยวัตถุฉนวน (ทาสีเลเยอร์) ค่าเฉลี่ยเคลื่อนที่แบบขนาน (SMA) เทียบกับค่าเฉลี่ยเคลื่อนที่แบบเสวนา (EMA) มีหลายประเภทของ Moving Averages แต่ทั้งสองแบบนี้เป็นที่นิยมมากที่สุดคือ 1. Simple Moving Average (SMA) หมายถึงราคาเฉลี่ยทางคณิตศาสตร์ของช่วงเวลาทางประวัติศาสตร์บางช่วงเวลา โดยปกติจะใช้กับราคา 8220close8221 แต่มีตัวเลือกอื่น ๆ อีกมากมาย (เปิดสูงต่ำ ฯลฯ ) 2. สูตร Exponential Moving Average (EMA) ลดความล่าช้าโดยให้น้ำหนักมากขึ้นกับราคาล่าสุด โดยเฉพาะถ้าคุณใช้มูลค่ามหาศาลสำหรับ EMA ของคุณ I. e 200 EMA เมื่อวันที่ 8211 รายวันราคาล่าสุดมีน้ำหนักมากขึ้นในสูตร Moving Average ซึ่งสูงกว่าราคาที่เก่าแก่ที่สุด การเคลื่อนที่ของค่าเฉลี่ยเป็นตัวบ่งชี้ชี้ (ชี้นาฬิกา) เนื่องจากราคาในแผนภูมิถูกวาดจากซ้ายไปขวาเรามี 2 ทิศทางที่เป็นไปได้และ 1 สำหรับตลาดช่วง: 1. 82201-2 o8217clock8221 รั้นแนวโน้ม 2. ช่วง 828220 o8217clock8221 หรือ แฟลต MA 3. 82204-5 o8217clock8221 แนวโน้มการลดลง Exponential Moving Average (EMA) ของการซื้อขายแบบ Multi Time Frame (MTF) ในการซื้อขายเรานับการตั้งค่าความน่าจะเป็นสูงสุด ไม่มีใครสามารถคาดการณ์ราคาถัดไปได้ แต่ถ้าคุณจะพิจารณาทิศทางของกรอบเวลาที่สูงขึ้น (HTF) และวางรายการของคุณในกรอบเวลาที่ต่ำกว่า (LTF) ในทิศทางเดียวกันคุณจะมีโอกาสทางคณิตศาสตร์มากขึ้นเพื่อให้ถูกต้อง เพราะเช่นเดียวกับตัวบ่งชี้ที่ปกคลุมด้วยวัตถุฉนวนใด ๆ MA จะลดน้อยลงใน HTF วิธีการวางธุรกิจการค้าโดยใช้ EMA Well ขึ้นอยู่กับประเภทการค้าที่คุณเป็น ผู้ค้าส่วนใหญ่ชอบค้า Breakouts (BO) ดังนั้นจึงสั่ง BuySell Stop Orending Order ขณะที่บางแห่งรอการทดสอบ SupportResistance (SR) อีกครั้งดังนั้นพวกเขาจึงวางคำสั่งซื้อที่ จำกัด การค้างอยู่ โดยการวางการค้าเช่นนี้ Stop Loss (SL) โดยปกติจะอยู่ที่ระดับ SR ถัดไป หรือต่ำกว่าแนวรับสำหรับการซื้อขายระยะยาว (หรือสูงกว่าความต้านทานต่อการค้าระยะสั้น) ฉันใช้ระดับ Fibonacci Retracement 50 และ 61.8 สำหรับการวางคำสั่งซื้อที่รอดำเนินการของฉันไปในทิศทางที่ BO และฉันใช้เป็น Stop Loss (SL) ระดับ 100 แน่นอนโดยการวัดวงสวิงที่ยืนยัน EMA8217s BO สำหรับระดับ Take Profit (TP) ผู้ค้าส่วนใหญ่จะใช้สัญญาณตรงข้ามในรายการ TF (PA ข้ามกลับ 200 EMA) หรือระดับ SR ถัดไป แต่นี้ไม่ได้ให้อัตราส่วน 1: 3 เป็น R: R Ratio การใช้งาน crosingretest HTF8217s 200 EMA อาจทำงานได้ ฉันใช้ fibonacci retracement เพิ่มในล่าสุด counter แนวโน้ม. ดังนั้น TP ของฉันอาจเป็น 127.4, 161.8 และ 261.8 โดยมองหาอัตราส่วน 1: 3 เป็นอัตราส่วน R: R (RiskReward Ratio) ถ้า TP ของฉันไม่น้อยกว่า 3xSL ฉันจะลด TF ของฉันลงไปที่ H1 และทำการซื้อขายการสวิงครั้งต่อไปที่นั่น ด้วยวิธีนี้ฉันจะมีรายการที่ราบรื่นกว่าด้วย SL ขนาดเล็กขณะที่เก็บ HTF8217 ของฉันไว้ ดังนั้นรายการ TF ที่เล็กกว่าของฉันจะเป็นความพยายาม และฉันสามารถที่จะสูญเสียหลายรายการเช่นนี้จะทำให้เท่ากัน H48217s SL นี้จะให้ฉันในภายหลัง R: R มักจะมากกว่า 1: 5 หรือ 1: 8 หรือสูงกว่า หากคุณเป็น Trader Position คุณสามารถใช้วิธีนี้ได้ HTF8217s counter trend แต่สำหรับความคิดนี้ผมขอแนะนำให้คุณเปลี่ยน SL แรกของคุณอย่างน้อยหนึ่งครั้งในกำไร (เพื่อล็อคกำไรของคุณ) จากนั้นคุณสามารถปล่อยให้ตำแหน่งที่ทำกำไรได้ให้ทำงานจนกว่าจะมีการเรียกใช้ HTF8217s TP วิธีการหลีกเลี่ยง Breakouts เท็จทุกครั้งที่เครื่องมือเสียว่า highlow แรกต้องหักเกินไปเพื่อยืนยัน Breakout (BO) มิฉะนั้นเราจะต้องพิจารณาว่า BO เริ่มต้นเป็น BO8221 จำนวน 8220 ที่ทดสอบ MA8217s อีกครั้ง และหลังจากนั้น highlow จะกลายเป็น Ross Hook (Rh) หรือ Fractal ซึ่งต้องอิงตามทฤษฎีเหล่านี้ด้วยเช่นกันเพื่อพิจารณาการเปลี่ยนแปลงของแนวโน้ม ใน HTFs MA สอบซ่อมด้วย BO ผิดพลาด won8217t มักเปลี่ยน MA ชี้ ใน LTFs MA8217s BO อาจได้รับการยืนยันในตอนแรกด้วยการสร้าง highlow ใหม่ซึ่งอาจเป็นโมฆะในภายหลัง และหลังจากนั้นการดำเนินการราคา (PA) อาจดำเนินต่อไปตามทิศทาง HTF8217s แม้ว่า LTF8217s BO จะได้รับการยืนยัน แต่แรก กรณีศึกษา. ตั้งค่าตัวอย่างสำหรับ EMA ใน MTF เพียงเพื่อทำความเข้าใจกับกลยุทธ์การซื้อขายแบบง่ายๆที่มีประสิทธิภาพ แต่เพียงอย่างเดียวซึ่งคำนวณจากค่าเฉลี่ยเคลื่อนที่ที่เกิดขึ้นในกรอบเวลาแบบมัลติเฟรมฉันจะตั้งค่าให้คุณเพียงเล็กน้อย (สถานการณ์): นี่คือคู่ AUDJPY ในแผนภูมิรายสัปดาห์รายวันและแผนภูมิ H4 ขึ้นอยู่กับรัศมี 200 EMA ที่ชี้ขึ้นในทุก 3 แผนภูมิเราจะใช้ตำแหน่งที่ยาวเท่านั้น 8211 ยาว 821 รายต่อวัน (แม้จะมีการทดสอบใหม่ที่ 200 EMA EMA ยังคงรักษาการรั้น) 8211 H4 ยาว (แม้กระทั่งการทดสอบใหม่ที่ 200 EMA โดยมีการฝ่าฟันผิด ๆ EMA ยังชี้ให้เห็นรั้น) นี่คือคู่ AUDUSD ในวันที่ แผนภูมิรายสัปดาห์และรายวัน H4 ในกราฟรายสัปดาห์เรามี Price Action (PA) อยู่ที่ 200 EMA ดังนั้นแนวโน้มระยะยาวยังคงเป็นขาลง แต่ในแผนภูมิ H4 และ Daily PA อยู่เหนือ 200 EMA ดังนั้นเราจึงสามารถรอสักครู่บน H4 สำหรับ PA ที่จะไปด้านล่าง 200 EMA (bucking แนวโน้มรายสัปดาห์) และการค้าสั้น ในกรณีนี้หลังจากผ่านไปแล้ว 200 EMA จะต้องชี้ให้เราลดลงในช่วง H4 ด้วยเช่นกัน หรือเราอาจรอให้กราฟรายสัปดาห์ยืนยันทิศทางในระยะยาวได้ในเวลาต่อมา เราไปเหนือ 200 EMA บน H4 แล้วในแต่ละวัน ดังนั้นเราจึงสามารถสมมติ PA จะไปเหนือ 200 EMA ในสัปดาห์เช่นกัน 8211 วันสั้น (สั้น) 8211 วันยาว (แม้จะกลับมาทดสอบใหม่ที่ 200 EMA EMA ยังคงรักษาการรั้น) 8211 H4 ยาวนี่คือคู่ EURUSD ในแผนภูมิรายสัปดาห์รายวันและ H4 ขึ้นอยู่กับรัศมี 200 EMA ที่ชี้ขึ้นในทุก 3 แผนภูมิเราจะใช้ตำแหน่งที่ยาวเท่านั้น หากอยู่บนเส้น H4 จะไปต่ำกว่า 200 EMA เราจะหยุดการซื้อขายคู่นี้ หากในระยะต่อไป PA จะไปต่ำกว่า 200 EMA ในวันนี้ด้วยเช่นกันเราจะรอ H4 สำหรับ PA ที่จะวิ่งต่ำกว่า 200 EMA เช่นกันเพื่อให้ได้ตำแหน่งที่สั้นโดยคาดว่าอย่างน้อย 200 EMA รายสัปดาห์ ทดสอบใหม่ (สิ่งที่เราเห็นใน H4 ควรจะเห็นในวันต่อมาในและหลังจากนั้นในสัปดาห์ด้วย) 8211 เป็นวันหยุดยาว 8211 วันยาว (หลังจากมีแบนอยู่ที่ 200 EMA โดยมีส่วนแบ่งปันผลแล้วและสร้างโอกาสใหม่ในการรับผลประกอบการประจำสัปดาห์) 8211 H4 ยาว (แม้การทดสอบใหม่ที่ 200 EMA โดยมีการฝ่าฟันการสนับสนุนด้านเทคนิค EMA ยังคงอยู่ ชี้ไปที่รั้น) การเคลื่อนไหวค่าเฉลี่ยการซื้อขายในแบบหลายกรอบเวลาอาจเป็นกลยุทธ์ที่ทำกำไรได้มากเนื่องจากคุณจะค้าการตั้งค่าความน่าจะเป็นสูงสุดในทิศทางของเฟรมเวลาที่สูงขึ้น เมื่อใช้กับระบบการจัดการด้านเงินที่ดีและอัตราส่วน R: R อย่างน้อย 1: 3 คุณควรทำกำไรได้เสมอ และแน่นอนว่าเป็นข้อจำกัดความรับผิดชอบเราขอแนะนำให้คุณทดสอบกลยุทธ์นี้ในบัญชี DEMO เป็นเวลาไม่กี่เดือนติดต่อกันเพื่อดูว่าการทำงานนี้เหมาะสำหรับคุณหรือไม่ อย่างไรก็ตามหากคุณตัดสินใจในภายหลังเพื่อใช้ความคิดนี้กับบัญชีเงินจริงของคุณคุณควรเข้าใจว่าความเสี่ยงทั้งหมดที่เกี่ยวข้องจะเป็นของคุณ หวังว่านี่จะช่วยได้รหัสด้านล่างแสดงให้เห็นว่าฉันกำลังสร้างค่าเฉลี่ยเคลื่อนที่สำหรับใช้ในกลยุทธ์อย่างไร อย่างไรก็ตามค่าเฉลี่ยเคลื่อนที่นี้เป็นค่าเริ่มต้นเป็นกรอบเวลากลยุทธ์ สิ่งที่ฉันต้องการทำคือเปลี่ยนค่าเฉลี่ยเคลื่อนที่นี้ให้มีกรอบเวลาของตัวเองแยกจากส่วนที่ใช้สำหรับส่วนที่เหลือของกลยุทธ์ ฉันไม่มีความคิดที่จะทำเช่นนี้ แต่ไม่มีอะไรที่เป็นประโยชน์ฉันจะขอบคุณมากถ้ามีคนแสดงให้ฉันเห็นวิธีการดำเนินการนี้ด้วยโค้ดตัวอย่างด้านล่างนี้ nb โปรดรวมการเปลี่ยนแปลงใด ๆ ที่จำเป็นสำหรับการคำนวณครั้งแรก () strategy. parameters: addString (quotTrendMAMethodquot, quotTrendMAMethodquot, quotquot, quotMVAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotMVAquot, quotquot, quotMVAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotEMAquot, quotquot, quotEMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotWootquot, quotquot, quotWilderquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotLWMAquot, quotquot, quotLWMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotSineWMAquot, quotquot, quotSineWMAquot) strategy. parameters: ยุทธศาสตร์ addStringAlternative (quotTrendMAMethodquot, quotTriMAquot, quotquot, quotTriMAquot) พารามิเตอร์: addStringAlternative (quotTrendMAMethodquot, quotLSMAquot, quotquot, quotLSMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotSMquaquot, quotquot, quotSMMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotHMAquot, quotquot, quotHMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotZeroLagEMAquot, quotquot, quotZeroLagEMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotDEMAquot, quotquot, quotDEMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotT3quot, quotquot, quotT3quot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotITrendquot, quotquot, quotITrendquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotMedianquot, quotquot, quotMedianquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotGeoMeanquot, quotquot, quotGeoMeanquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotREMAquot, quotquot, quotREMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotILRSquot, quotquot, quotILRSquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotIE2quot, quotquot, quotIE2quot) strategy. parameters: addStringAlternativ E (quotTrendMAMethodquot, quotTriMAgenquot, quotquot, quotTriMAgenquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotJSmoothquot, quotquot, quotJSmoothquot) strategy. parameters: addInteger (quotTrendMAPeriodquot, quotTrendMAPeriodquot, quotquot 200) strategy. parameters: addString (quotTypequot, quotPrice Typequot, quotquot , quotCquot) strategy. parameters: addStringAlternative (quotTypequot, quotOPENquot, quotquot, quotOquot) strategy. parameters: addStringAlternative (quotTypequot, quotHIGHquot, quotquot, quotHquot) strategy. parameters: addStringAlternative (quotTypequot, quotLOWquot, quotquot, quotLquot) strategy. parameters: addStringAlternative (quotTypequot, quotCLOSEquot, quotquot, quotCquot) strategy. parameters: addStringAlternative (quotTypequot, quotMEDIANquot, quotquot, quotMquot) strategy. parameters: addStringAlternative (quotTypequot, quotTYPICALquot, quotquot, quotTquot) strategy. parameters: addStringAlternative (quotTypequot, quotWEIGHTEDquot, quotquot, quotWquot ) strate gSymmetric: addGroup (quotPricequot) strategy. parameters: addString (quotPTquot, quotPrice Typequot, quotquot, quotBidquot) strategy. parameters: addStringAlternative (quotPTquot, quotBidquot, quotquot, quotBidquot) strategy. parameters: addStringAlternative (quotPTquot, quotAskquot, quotquot, quotAskquot ) strateg. parameters: addGroup (quotTimeFramequot) strategy. parameters: addString (quotTFquot, quotTime Framequot, quotquot, quotm5quot) strategy. parameters: setFlag (quotTFquot, core. FLAGPERIODS) สิ้นสุด local gSource - สตรีมท้องถิ่น TrendMAMethod local TrendMAPeriod local TrendMA local P1 TrendMAMethodinstance. parameters. TrendMAMethod TrendMAPeriodinstance. parameters. TrendMAPetiodModeRecordInstance. parameters. Type gSource ExtSubscribe (1, nil, instance. parameters. TF, instance. parameters. Type quotBidquot, quotbarquot) ถ้า Type1 quotOquot จากนั้น P1 gSource. open elseif Type1 quotH จากนั้น P1 gSource. high elseif Type1 quotLquot แล้ว P1 gSource. low elseif Type1 quotMquot แล้ว P1 gSource. median elseif Type1 quotTquot แล้ว P1 gSource. typical elseif Type1 quotWquot แล้ว P1 gSource. weighted else P1 gSource. close end TrendMA core. indicators: สร้าง (quotAVERAGESquot, P1, TrendMAMethod, TrendMAPeriod, false) - และรับดัชนีที่เก่าแก่ที่สุดของแถบที่เราสามารถทำได้ ทำงานที่ math. max แรก (TrendMA. DATA:first () ฯลฯ ) end function ExtUpdate (id, source, period) - ถ้าเรามีแถบเพียงพอในประวัติที่จะทำงานถ้าช่วง gt แรก 1 แล้วตอนนี้ฉันสามารถใช้ MA สมัครสมาชิกอีกระยะเวลาหนึ่งรหัส: เลือก gBTFSource ExtSubscribe ทั้งหมด (BTFID, nil, instance. parameters. BTF, instance. parameters. Type quotBidquot, quotbarquot) และใช้ในตัวบ่งชี้แทน gSource Code: เลือกทั้งหมด p1 gBTFSource. open เพื่อให้ได้ดัชนีของค่าแรกที่คุณต้องใช้เพื่อกำหนดดัชนีของช่วงเวลาหลักไปยังดัชนีของกรอบเวลาที่ใหญ่กว่าเช่นนั้น: รหัส: เลือก TrendMA. DATA แรกก่อนหน้านี้ทั้งหมด () local btfPeriod core. findDate (gBTFSource, gSource: date (period), true) ถ้า btfPeriod gt แรก 1 แล้ว Ive ได้รวมการแก้ไขปัญหาเหล่านี้ไว้ที่นี่: Code: เลือกฟังก์ชันทั้งหมด Init () strategy. parameters: addString (quotTrendMAMethodquot, quotTrendMAMethodquot, quotquot, quotMVAquot ยุทธวิธี: addStringAlternative (quotTrendMAMethodquot, quotMVAquot, quotquot, quotMVAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotEMAquot, quotquot, quotEMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotWilderquot, quotquot, quotWilderquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot , quotLWMAquot, quotquot, quotLWMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotSineWMAquot, quotquot, quotSineWMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotTriMAquot, quotquot, quotTriMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotLSMAquot, quotquot, quotLSMAquot) กลยุทธ์.param พารา: addStringAlternative (quotTrendMAMethodquot, quotSMMAquot, quotquot, quotSMMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotHMAquot, quotquot, quotHMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotZeroLagEMAquot, quotquot, quotZeroLagEMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotDEMAquot, quotquot, quotDEMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotT3quot, quotquot, quotT3quot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotITrendquot, quotquot, quotITrendquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotMedianquot, quotquot, quotMedianquot) strategy. parameters: (คำสั่ง quotTrendMAMethodquot, quotGeoMeanquot, quotquot, quotGeoMountquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotREMAquot, quotquot, quotREMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotILRSquot , quotquot, quotILRSquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotIE2quot, quotquot, quotIE2quot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotTriMAgenquot, quotquot, quotTriMAgenquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotJSmoothquot, quotquot, quotJSmoothquot) strategy. parameters : addInteger (quotTrendMAPeriodquot, quotTrendMAPeriodquot, quotquot 200) strategy. parameters: addString (quotTypequot, quotPrice Typequot, quotquot, quotCquot) strategy. parameters: addStringAlternative (quotTypequot, quotOPENquot, quotquot, quotOquot) strategy. parameters: addStringAlternative (quotTypequot, quotHIGHquot, quot; quotquot, quotHquot) strategy. parameters: addStringAlternative (quotTypequot, quotLOTquot, quotquot, quotLquot) strategy. parameters: addStringAlternative (quotTypequot, quotCLOSEququ, quotquot, quotCquot) strategy. parameters: addStringAlternative (quotTypequot, quotMEDIANquot, quotquot, quotMquot) strategy. parameters: addStrin gArternative (quotTypequot, quotTYPICALquot, quotquot, quotTquot) strategy. parameters: addStringAlternative (quotTypequot, quotWEIGHTedquot, quotquot, quotWquot) strategy. parameters: addGroup (quotPricequot) strategy. parameters: addString (quotPTquot, quotPrice Typequot, quotquot, quotBidquot) strategy. parameters : addStringAlternative (quotPTquot, quotBidquot, quotquot, quotBidquot) strategy. parameters: addStringAlternative (quotPTquot, quotAskquot, quotquot, quotAskquot) strategy. parameters: addGroup (quotTimeFramequot) strategy. parameters: addString (quotTFquot, quotTime Framequot, quotquot, quotm5quot) ยุทธศาสตร์ พารามิเตอร์: setFlag (quotTFquot, core. FLAGPERIODS) strategy. parameters: addString (quotBTFquot, ระยะเวลาของกรอบคำพูด, quotquot, quotH1quot) strategy. parameters: setFlag (quotBTFquot, core. FLAGPERIODS) สิ้นสุด local gSource - สตรีมท้องถิ่น gBTFSource - สตรีมภายใน TrendMAMethod local TrendMAPeriod local TrendMA local P1 ท้องถิ่น MAINTFID 1 local BTFID 2 TrendMAMethodinstance. parameters. TrendMA วิธีการ TrendMAPeriodinstance. parameters. TrendMAPeriod Typeinstance. parameters ประเภท gSource ExtSubscribe (MAINTFID, nil, instance. parameters. TF, instance. parameters. Type quotBidquot, quotbarquot) gBTFSource ExtSubscribe (BTFID, nil, instance. parameters. BTF, instance. parameters พิมพ์ quotBidquot, quotbarquot) ถ้า Type1 quotOquot แล้ว P1 gBTFSource. open elseif Type1 quotH จากนั้น P1 gBTFSource. high elseif Type1 quotLquot จากนั้น P1 gBTFSource. low elseif Type1 quotMquot จากนั้น P1 gBTFSource. median elseif Type1 quotTquot จากนั้น P1 gBTFSource. typical elseif Type1 quotWquot แล้ว P1 gBTFSource. weighted else P1 gBTFSource. close end TrendMA core. indicators: สร้าง (quotAVERAGESquot, P1, TrendMAMethod, TrendMAPeriod, false) - และรับดัชนีที่เก่าแก่ที่สุดของแถบที่เราสามารถทำงานได้ที่ฟังก์ชันแรกของ TrendMA. DATA :first () ExtUpdate (id, source, period) ถ้า id MAINTFID และ gBTFSource: size () gt 0 แล้ว TrendMA: update (core. UpdateLast) btfPeriod core. findDate ภายในเครื่อง (gBTFSource, gSource: date (period), t rue) - ถ้าเรามีบาร์เพียงพอในประวัติศาสตร์ที่จะทำงานถ้า btfPeriod gt แรกที่ 1 แล้ว - ตอนนี้ฉันสามารถใช้สิ้นสิ้นสิ้น MA มีเพียงสามกีฬาคือการสู้วัวกระทิงแข่งรถและการปีนเขาส่วนที่เหลือทั้งหมดเป็นเพียงเกม . (c) Ernest Hemingway สวัสดี Victor. Tereschenko, ขอบคุณ Victor มากที่ได้รับความช่วยเหลือที่ดี แต่ฉันยังคงติดอยู่ดังนี้: - รหัสที่สมบูรณ์อยู่ด้านล่างผมวางสัญญาณบาง (Test Points) เพื่อติดตามความคืบหน้าผ่านตรรกะ และพบว่ารหัสล้มเหลวในบรรทัด: 284 ถ้า btfPeriod gt แรก 1 แล้วค่าเปิดออกมาเป็นดังนี้: - EURUSD LONNY02SIGNAL, EURUSD, cci20, m1, ทั้ง 2 TP0 - เริ่มต้น: btfPeriod (-1) gt แรก (199) 1 08252011 10:08:00 1.44073 ปัญหาคือชัด btfPeriod ที่ -1 แสดง Ive ทำ blooper ที่ไหนสักแห่งมากที่สุดคุณจะสามารถมองเห็นปัญหาขอบคุณมาก Peter Newton รหัส: เลือกทั้งหมด - Intemplce กลยุทธ์เพื่อ โปรแกรมประยุกต์โฮสต์ (ตัวอย่าง Marketscope) - ฟังก์ชันถูกเรียกครั้งหนึ่งเมื่อแอ็พพลิเคชันโฮสต์เริ่มโหลดกลยุทธ์ (กลยุทธ์ quotation) - คำอธิบาย (ยุทธศาสตร์การเรียกเก็บเงิน quotLonNY02 กลยุทธ์) - คำอธิบาย (กลยุทธ์การกำหนดค่า quotLonNY02) - ค่าพารามิเตอร์เฉลี่ยที่รวดเร็วและช้าเคลื่อนไหวพารามิเตอร์: addGroup (quotMain Controlsquot) strategy. parameters: addString (quotTFquot, quotStrategy Time Framequot, quotquot, quotm5quot ) strategy. parameters: setFlag (quotTFquot, core. FLAGPERIODS) strategy. parameters: addString (quotALLOWEDSIDEquot, quotAllowed sidequot, ด้านที่กำหนดไว้สำหรับการซื้อขายหรือการส่งสัญญาณสามารถเป็น Buy, Sell หรือ Bothquot, quotBotquot) strategy. parameters: addStringAlternative (quotALLOWEDSIDEquot, quotBothquot , quotquot, quotBotquot) strategy. parameters: addStringAlternative (quotALLOWEDSIDEquot, quotUpquot, quotquot, quotUpquot) strategy. parameters: addStringAlternative (quotALLOWEDSIDEquot, quotDnquot, quotquot, quotDnquot) strategy. parameters: addBoolean (quotSquot, quotSetup แจ้งให้ทราบล่วงหน้า, quotquot, true) กลยุทธ์ พารามิเตอร์: addBoolean (quotTquot, quotTrigger Alertquot, quotquot, true) strategy. parameters: addBoolean ( quotCquot, quotConfirmed Trigger Alertquot, quotquot, false) strategy. parameters: addGroup (quotAlertsquot) strategy. parameters: addBoolean (quotShowAlertquot, quotShowAlertquot, quotquot, true) strategy. parameters: addBoolean (quotPlaySoundquot, quotPlay Soundquot, quotquot, true) strategy. parameters : addFile (quotSoundFilequot, quotSound Filequot, quotquot, quotquot) strategy. parameters: setFlag (quotSoundFilequot, core. FLAGSOUND) strategy. parameters: addBoolean (quotRecurrentSoundquot, Soundquot ฉบับปัจจุบัน, quotquot, true) strategy. parameters: addBoolean (quotSendEmailquot, quotSend Emailquot, quotquot, false) strategy. parameters: addString (quotEmailquot, quotEmailquot, quotquot, quotquot) strategy. parameters: setFlag (quotEmailquot, core. FLAGEMAIL) strategy. parameters: addGroup (quotCCI Parameterquot) strategy. parameters: addInteger (quotCCIPquot, quotCCI periodquot, quotquot, 20, 2, 200) strategy. parameters: addGroup (ช่วงเวลาที่กำหนดโดยผู้บังคับบัญชา MA Parameterquot) strategy. parameters: addBoolean (quotBTFMAFl agquot, quotBigger เวลาเทรนด์กรอบ MA onquot, quotquot จริง) strategy. parameters: addString (quotBTFTrendMAMethodquot, quotBTFTrendMAMethodquot, quotquot, quotMVAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotMVAquot, quotquot, quotMVAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotEMAquot , quotquot, quotEMAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotWilderquot, quotquot, quotWilderquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotLWMAquot, quotquot, quotLWMAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotSineWMAquot, quotquot, quotSineWMAquot) strategy. parameters : addStringAlternative (quotBTFTrendMAMethodquot, quotTriMAquot, quotquot, quotTriMAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotLSMAquot, quotquot, quotLSMAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotSMMAquot, quotquot , quotSMMAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotHMAquot, quotquot, quotHMAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotZeroLagEMAquot, quotquot, quotZeroLagEMAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotDEMAquot, quotquot, quotDEMAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotT3quot, quotquot, quotT3quot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotITrendquot, quotquot, quotITrendquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotMedianquot, quotquot, quotMedianquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotGeoMeanquot, quotquot, quotGeoMeanquot ) rules. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotREMAquot, quotquot, quotREMAquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotILRSquot, quotquot, quotILRSquot) strategy. parameters : addStringAlternative (quotBTFTrendMAMethodquot, quotIE2quot, quotquot, quotIE2quot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotTriMAgenquot, quotquot, quotTriMAgenquot) strategy. parameters: addStringAlternative (quotBTFTrendMAMethodquot, quotJSmoothquot, quotquot, quotJSmoothquot) strategy. parameters: addString (quotBTFTypequot, quotBTFPrice Typequot, quotquot, quotCquot) strategy. parameters: addStringAlternative (quotBTFTypequot, quotOPENquot, quotquot, quotOquot) strategy. parameters: addStringAlternative (quotBTFTypequot, quotHighquot, quotquot, quotHquot) strategy. parameters: addStringAlternative (quotBTFTypequot, quotLOWquot, quotquot, quotLquot) strategy. parameters: addStringAlternative (quotBTFTypequot, quotCLOSEquot, quotquot, quotCquot) strategy. parameters: addStringAlternative (quotBTFTypequot, quotMEDIANquot, quotquot, quotMquot) strategy. parameters: addStringAlternative (quotBTFTypequot, quotTYPICALquot, quotquot, quotTquot) strategy. parameters: addStringAlternativ (quotBTFTypequot, quotWEIGHTEDquot, quotquot, quotWquot) strategy. parameters: addInteger (quotBTFTrendMAPeriodquot, quotBTFTrendMAPeriodquot, quotquot, 200) strategy. parameters: addString (quotBTFquot, quotBigger เวลา Framequot, quotquot, quotm30quot) strategy. parameters: setFlag (quotBTFquot, core FLAGPERIODS) strategy. parameters: addGroup (กรอบเวลาข้อคิดเห็น Time Framework MA Parameterquot) ยุทธศาสตร์พารามิเตอร์: addBoolean (quotStrategyMAFlagquot, quotStrategy เทรนด์ MA onQuot, quotquot, true) strategy. parameters: addString (quotTrendMAMethodquot, quotTrendMAMethodquot, quotquot, quotMVAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotMVAquot, quotquot, quotMVAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotEMAquot, quotquot, quotEMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotWilderquot, quotquot, quotWilderquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotLWMAquot, quotquot, quotLWMAquot ) strategy. para เมตร: addStringAlternative (quotTrendMAMethodquot, quotSineWMAquot, quotquot, quotSineWMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotTriMAquot, quotquot, quotTriMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotLSMAquot, quotquot, quotLSMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotSMMAquot, quotquot, quotSMMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotHMAquot, quotquot, quotHMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotZeroLagEMAquot, quotquot, quotZeroLagEMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotDEMAquot, quotquot, quotDEMAquot) strategy. parameters: พารามิเตอร์ที่ใช้ร่วมกัน: addStringAlternative (quotTrendMAMethodquot, quotT3quot, quotquot, quotT3quot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotITrendquot, quotquot, quotITrendquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotMedianquo T, quotquot, quotMedianquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotGeoMeanquot, quotquot, quotGeoMeanquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotREMAquot, quotquot, quotREMAquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotILRSquot, quotquot, quotILRSquot) กลยุทธ์ พารามิเตอร์: addStringAlternative (quotTrendMAMethodquot, quotIE2quot, quotquot, quotIE2quot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotTriMAgenquot, quotquot, quotTriMAgenquot) strategy. parameters: addStringAlternative (quotTrendMAMethodquot, quotJSmoothquot, quotquot, quotJSmoothquot) strategy. parameters: addString (quotTypequot, quotPrice Typequot , quotquot, quotCquot) strategy. parameters: addStringAlternative (quotTypequot, quotOPENquot, quotquot, quotOquot) strategy. parameters: addStringAlternative (quotTypequot, quotHIGHquot, quotquot, quotHquot) strategy. parameters: addStringAlternative (quotTypequot, quotLOWquot, quotquot , quotLquot) strategy. parameters: addStringAlternative (quotTypequot, quotCLOSEquot, quotquot, quotCquot) strategy. parameters: addStringAlternative (quotTypequot, quotMEDIANquot, quotquot, quotMquot) strategy. parameters: addStringAlternative (quotTypequot, quotTYPICALquot, quotquot, quotTquot) strategy. parameters: addStringAlternative (quotTypequot, quotWEIGHTEDquot, quotquot, quotWquot) strategy. parameters: addInteger (quotTrendMAPeriodquot, quotTrendMAPeriodquot, quotquot, 200) strategy. parameters: addGroup (quotLevelsquot) strategy. parameters: addInteger (quotobquot, quotOverbought Levelquot, quotquot, 100) strategy. parameters: addInteger (quotOSquot, quot Oververs Levelquot, quotquot, -100) strategy. parameters: addInteger (quotOBCquot, quotOverbought ยืนยัน Levelquot, quotquot, 150) strategy. parameters: addInteger (quotOSCquot, quot; ยืนยันยืนยันระดับ, quotquot, -150) - ราคา พารามิเตอร์การสมัครสมาชิก (ราคาเสนอหรือราคาถาม, กรอบเวลา) กลยุทธ์: พารามิเตอร์ addGroup (quotPricequot) พารามิเตอร์: addString (quotPTquot, quotPrice Typequot, quotquot, quotBidquot) strategy. parameters: addStringAlternative (quotPTquot, quotBidquot, quotquot, quotBidquot) strategy. parameters: addStringAlternative (quotPTquot, quotAskquot, quotquot, quotAskquot) - ตัวแปรส่วนกลางที่อยู่ในระบบ BAR nil - - ประวัติราคาที่เราสมัครเป็นสมาชิกในท้องถิ่นก่อน - ดัชนีช่วงเวลาที่เก่าแก่ที่สุดซึ่งเราสามารถตรวจสอบได้ว่าค่าเฉลี่ยเคลื่อนที่ได้ถูกข้ามไปที่ OB, OS, OBC, OSC local CCI local Top, gBTFSource ด้านล่างของท้องถิ่น - ท้องถิ่น BTFTrendMAMethod BTFTrendMAPeriod ท้องถิ่น ท้องถิ่น BTFTrendMA ท้องถิ่น gSource - สตรีมท้องถิ่น TrendMAMethod ท้องถิ่น TrendMAPeriod ท้องถิ่น TrendMA ท้องถิ่น upArrow ไม่มีท้องถิ่น downArrow ไม่มีท้องถิ่น MAINTFID 1 ท้องถิ่น BTFID 2 ท้องถิ่น BTFP1 ท้องถิ่น BTFType ท้องถิ่น SoundFile ไม่มีท้องถิ่น RecurrentSound false local ALLOWEDSIDE Local S - ตั้งค่าท้องถิ่น T - ทริกเกอร์ท้องถิ่น CT - - ยืนยันการเรียกค้น LocalBack ท้องถิ่น ShowAlert local Email local SendEmail local ฟังก์ชัน BaseSize เตรียม () - จัดเตรียม d ทั้งหมด ATA - ฟังก์ชันนี้เรียกว่าครั้งเดียวเมื่อกลยุทธ์กำลังจะเริ่มต้น - ตรวจสอบค่าเฉลี่ยที่เคลื่อนที่ได้ OBinstance. parameters. OB OS instance. parameters. OS OBC instance. parameters. OBC OSC instance. parameters. OSC CCIP instance. parameters. CCIP Sinstance. parameters. S Tinstance. parameters. TTcstStance. parameters. CT --downArrow instance:createTextOutput (quotUpquot, quotUpquot, quotWingdings 3quot, 20, core. HCenter, core. VTop, instance. parameters. Bottom, 0) --upArrow instance:createTextOutput (quotDownquot, quotDownquot, quotWingdings 3quot, 20, core. HCenter, core. VBottom, instance. parameters. Top, 0) quott1quot, quotThe strategy cannot be applied on ticks. quot) -- name the indicator local name profile:id(). quot, quot. instance. bid:name(). quot, cciquot. CCIP. quot, quot. instance. parameters. TF. quot, quot. ALLOWEDSIDE. quot quot instance:name(name) -- setup the signal. pay attention, we pass quotShowAlertquot (value initially taken from the instance. parameters. ShowAlert) -- here, so, we dont check whether alerts are requested anymore. -- and finally subscribe for the ticks of the instrument the user initially chosen to run the strategy for to -- have our strategy activated once. BAR ExtSubscribe(1, nil, instance. parameters. TF, true, quotbarquot) -- create indicators CCI core. indicators:create(quotCCIquot, BAR, CCIP) BTFTrendMAMethodinstance. parameters. BTFTrendMAMethod BTFTrendMAPeriodinstance. parameters. BTFTrendMAPeriod BTFTypeinstance. parameters. BTFType TrendMAMethodinstance. parameters. TrendMAMethod TrendMAPeriodinstance. parameters. TrendMAPeriod Typeinstance. parameters. Type gSource ExtSubscribe(MAINTFID, nil, instance. parameters. TF, instance. parameters. Type quotBidquot, quotbarquot) gBTFSource ExtSubscribe(BTFID, nil, instance. parameters. BTF, instance. parameters. BTFType quotBidquot, quotbarquot) if BTFType quotOquot then BTFP1 gBTFSource. open elseif BTFType quotHquot then BTFP1 gBTFSource. high elseif BTFType quotLquot then BTFP1 gBTFSource. low elseif BTFType quotMquot then BTFP1 gBTFSource. median elseif BTFType quotTquot then BTFP1 gBTFSource. typical elseif BTFType quotWquot then BTFP1 gBTFSource. weighted else BTFP1 gBTFSource. close end if Type quotOquot then P1 gSource. open elseif Type quotHquot then P1 gSource. high elseif Type quotLquot then P1 gSource. low elseif Type quotMquot then P1 gSource. median elseif Type quotTquot then P1 gSource. typical elseif Type quotWquot then P1 gSource. weighted else P1 gSource. close end BTFTrendMA core. indicators:create(quotAVERAGESquot, BTFP1, BTFTrendMAMethod, BTFTrendMAPeriod, false) TrendMA core. indicators:create(quotAVERAGESquot, P1, TrendMAMethod, TrendMAPeriod, false) -- and get the oldest index of the bar we can work at first math. max(CCI. DATA:first(), TrendMA. DATA:first(), BTFTrendMA. DATA:first()) end -- the function is called every time when any subscribed price is changed. For tick subscribtions the function is called -- for every tick, for the bar subscribtions the function is called when the candle is closed (in other words, when -- the first tick of the next candle appears). function ExtUpdate(id, source, period) if id 1 then -- on the user chosen subscription (can be either tick or bar subscribtion). -- update indicators CCI:update(core. UpdateLast) TrendMA:update(core. UpdateLast) -- if we have enough bars in the history to work if id MAINTFID and gBTFSource:size() gt 0 then TrendMA:update(core. UpdateLast) local btfPeriod core. findDate(gBTFSource, gSource:date(period), true) -- if we have enough bars in the history to work Signal (quotTP0 - START: btfPeriod(quot. tostring(btfPeriod). quot) gt first(quot. tostring(first). quot) 1quot ) if btfPeriod gt first 1 then Signal (quotTP0a - quot. quotbtfPeriod gt first 1quot) -- This bit added for signalling only if BTFMAFlag then if gBTFSource. close91period93 lt BTFTrendMA. DATA91period93 then Signal (quotTP1 - BTFtrend Downquot) BTFtrendDir quotDownquot elseif gBTFSource. close91period93 lt BTFTrendMA. DATA91period93 then Signal (quotTP2 - BTFtrend Upquot) BTFtrendDir quotUpquot end else BTFdir quotOffquot Signal (quotTP3 - BTFtrend Offquot) end if MAFlag then if gSource. close91period93 lt TrendMA. DATA91period93 then Signal (quotTP4 - trend Downquot) trendDdir quotDownquot elseif gBTFSource. close91period93 lt BTFTrendMA. DATA91period93 then Signal (quotTP5 - trend Upquot) trendDdir quotUpquot end else trendDdir quotOffquot Signal (quotTP6 - trend Offquot) end if S and core. crossesOver(CCI. DATA, OB, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then Signal ( quotSell Setup: Crossing above OverBoughtquot) elseif S and core. crossesUnder(CCI. DATA, OS, period) and (BTFtrendDir quotUpquot or BTFtrendDir quotOffquot) and (trendDir quotUpquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then Signal (quotBuy Setup: Crossing Below OverSoldquot) end if T and core. crossesOver(CCI. DATA, OS, period) and (BTFtrendDir quotUpquot or BTFtrendDir quotOffquot) and (trendDir quotUpquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWE DSIDE quotUpquot) then Signal (quotBuy Trigger: Crossing above OverSoldquot) elseif T and core. crossesUnder(CCI. DATA, OB, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then Signal (quotSell Trigger: Confirmed Crossing below OverBoughtquot) end if core. crossesOver(CCI. DATA, OBC, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then TOP true end if core. crossesUnder(CCI. DATA, OSC, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then BOTTOM true end if CT and core. crossesOver(CCI. DATA, OS, period) and (BTFtrendDir quotUpquot or BTFtrendDir quotOffquot) and (trendDir quotUpquot or trendDir quotOffquot) and BOTTOM and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then BOTTOM false Signal (quotBuy Trigger: Confirmed Crossing above OverSoldquot) elseif CT and core. crossesUnder(CCI. DATA, OB, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and TOP and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then TOP false Signal (quotSell Trigger: Confirmed Crossing below OverBoughtquot) end -- end of confirmation trigger signalling end end end end -- eof function ExtUpdate function Initialization() AllowMultiple instance. parameters. AllowMultiple ALLOWEDSIDE instance. parameters. ALLOWEDSIDE --local S instance. parameters. S --local T instance. parameters. T --local CT instance. parameters. CT local PlaySound instance. parameters. PlaySound if PlaySound then SoundFile instance. parameters. SoundFile else SoundFile nil end assert(not(PlaySound) or (PlaySound and SoundFile quotquot), quotSound file must be chosenquot) ShowAlert instance. parameters. ShowAlert RecurrentSound instance. parameters. RecurrentSound SendEmail instance. parameters. SendEmail if SendEmail then Email instance. parameters. Email else Email nil end assert(not(SendEmail) or (SendEmail and Email quotquot), quotE-mail address must be specifiedquot) end function Signal (Label) if ShowAlert then terminal:alertMessage(instance. bid:instrument(), instance. bid91NOW93, Label, instance. bid:date(NOW)) end nil then terminal:alertSound(SoundFile, RecurrentSound) end nil then terminal:alertEmail(Email, Label, profile:id(). quot(quot. instance. bid:instrument(). quot)quot. instance. bid91NOW93..quot, quot. Label..quot, quot. instance. bid:date(NOW)) end end You have sent id into subscribe: BAR ExtSubscribe(1. ) When update is called with id 1, the period is valid for the BAR source only. gBTFSource has different timeframe and the period with id 1 is not valid to it. You should use converted period (btfPeriod) to access gBTFSourceBTFTrendMA values. Code: Select all gBTFSource. close91btfPeriod93 lt BTFTrendMA. DATA91btfPeriod93 instead of Code: Select all gBTFSource. close91period93 lt BTFTrendMA. DATA91period93 first value should be quotsplittedquot into two: Code: Select all first math. max(CCI. DATA:first(), TrendMA. DATA:first()) btfFirst BTFTrendMA. DATA:first() . if period gt first then . -- and if btfPeriod gt btfFirst then And Ive made a misprint over here: Code: Select all --local btfPeriod core. findDate(gBTFSource, BAR:date(period), true) local btfPeriod core. findDate(gBTFSource, BAR:date(period), false) Corrected code: Code: Select all -- Intoduce the strategy to the host application (for example, Marketscope). -- The function is called once when the host application initially loads the strategy. function Init() strategy:name(quotLonNY02Signalquot) strategy:description(quotLonNY02 Signalling Strategyquot) -- Fast and slow moving average parameters strategy. parameters:addGroup(quotMain Controlsquot) strategy. parameters:addString(quotTFquot, quotStrategy Time Framequot, quotquot, quotm5quot) strategy. parameters:setFlag(quotTFquot, core. FLAGPERIODS) strategy. parameters:addString(quotALLOWEDSIDEquot, quotAllowed sidequot, quotAllowed side for trading or signaling, can be Sell, Buy or Bothquot, quotBothquot) strategy. parameters:addStringAlternative(quotALLOWEDSIDEquot, quotBothquot, quotquot, quotBothquot) strategy. parameters:addStringAlternative(quotALLOWEDSIDEquot, quotUpquot, quotquot, quotUpquot) strategy. parameters:addStringAlternative(quotALLOWEDSIDEquot, quotDnquot, quotquot, quotDnquot) strategy. parameters:addBoolean(quotSquot, quotSetup Alertquot, quotquot, true) strategy. parameters:addBoolean(quotTquot, quotTrigger Alertquot, quotquot, true) strategy. parameters:addBoolean( quotCTquot, quotConfirmed Trigger Alertquot, quotquot, false) strategy. parameters:addGroup(quotAlertsquot) strategy. parameters:addBoolean(quotShowAlertquot, quotShowAlertquot, quotquot, true) strategy. parameters:addBoolean(quotPlaySoundquot, quotPlay Soundquot, quotquot, true) strategy. parameters:addFile(quotSoundFilequot, quotSound Filequot, quotquot, quotquot) strategy. parameters:setFlag(quotSoundFilequot, core. FLAGSOUND) strategy. parameters:addBoolean(quotRecurrentSoundquot, quotRecurrent Soundquot, quotquot, true) strategy. parameters:addBoolean(quotSendEmailquot, quotSend Emailquot, quotquot, false) strategy. parameters:addString(quotEmailquot, quotEmailquot, quotquot, quotquot) strategy. parameters:setFlag(quotEmailquot, core. FLAGEMAIL) strategy. parameters:addGroup(quotCCI Parameterquot) strategy. parameters:addInteger(quotCCIPquot, quotCCI periodquot, quotquot, 20, 2, 200) strategy. parameters:addGroup(quotBigger Time Frame MA Parameterquot) strategy. parameters:addBoolean(quotBTFMAFl agquot, quotBigger Time Frame MA Trend onquot, quotquot, true) strategy. parameters:addString(quotBTFTrendMAMethodquot, quotBTFTrendMAMethodquot, quotquot, quotMVAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotMVAquot, quotquot, quotMVAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotEMAquot, quotquot, quotEMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotWilderquot, quotquot, quotWilderquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotLWMAquot, quotquot, quotLWMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotSineWMAquot, quotquot, quotSineWMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotTriMAquot, quotquot, quotTriMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotLSMAquot, quotquot, quotLSMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotSMMAquot, quotquot , quotSMMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotHMAquot, quotquot, quotHMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotZeroLagEMAquot, quotquot, quotZeroLagEMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotDEMAquot, quotquot, quotDEMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotT3quot, quotquot, quotT3quot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotITrendquot, quotquot, quotITrendquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotMedianquot, quotquot, quotMedianquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotGeoMeanquot, quotquot, quotGeoMeanquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotREMAquot, quotquot, quotREMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotILRSquot, quotquot, quotILRSquot) strategy. parameters :addStringAlternative(quotBTFTrendMAMethodquot, quotIE2quot, quotquot, quotIE2quot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotTriMAgenquot, quotquot, quotTriMAgenquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotJSmoothquot, quotquot, quotJSmoothquot) strategy. parameters:addString(quotBTFTypequot, quotBTFPrice Typequot, quotquot, quotCquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotOPENquot, quotquot, quotOquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotHIGHquot, quotquot, quotHquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotLOWquot, quotquot, quotLquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotCLOSEquot, quotquot, quotCquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotMEDIANquot, quotquot, quotMquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotTYPICALquot, quotquot, quotTquot) strategy. parameters:addStringAlternativ e(quotBTFTypequot, quotWEIGHTEDquot, quotquot, quotWquot) strategy. parameters:addInteger(quotBTFTrendMAPeriodquot, quotBTFTrendMAPeriodquot, quotquot, 200) strategy. parameters:addString(quotBTFquot, quotBigger Time Framequot, quotquot, quotm30quot) strategy. parameters:setFlag(quotBTFquot, core. FLAGPERIODS) strategy. parameters:addGroup(quotStrategy Time Frame MA Parameterquot) strategy. parameters:addBoolean(quotStrategyMAFlagquot, quotStrategy MA Trend onquot, quotquot, true) strategy. parameters:addString(quotTrendMAMethodquot, quotTrendMAMethodquot, quotquot, quotMVAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotMVAquot, quotquot, quotMVAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotEMAquot, quotquot, quotEMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotWilderquot, quotquot, quotWilderquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotLWMAquot, quotquot, quotLWMAquot) strategy. para meters:addStringAlternative(quotTrendMAMethodquot, quotSineWMAquot, quotquot, quotSineWMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotTriMAquot, quotquot, quotTriMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotLSMAquot, quotquot, quotLSMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotSMMAquot, quotquot, quotSMMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotHMAquot, quotquot, quotHMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotZeroLagEMAquot, quotquot, quotZeroLagEMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotDEMAquot, quotquot, quotDEMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotT3quot, quotquot, quotT3quot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotITrendquot, quotquot, quotITrendquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotMedianquo t, quotquot, quotMedianquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotGeoMeanquot, quotquot, quotGeoMeanquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotREMAquot, quotquot, quotREMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotILRSquot, quotquot, quotILRSquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotIE2quot, quotquot, quotIE2quot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotTriMAgenquot, quotquot, quotTriMAgenquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotJSmoothquot, quotquot, quotJSmoothquot) strategy. parameters:addString(quotTypequot, quotPrice Typequot, quotquot, quotCquot) strategy. parameters:addStringAlternative(quotTypequot, quotOPENquot, quotquot, quotOquot) strategy. parameters:addStringAlternative(quotTypequot, quotHIGHquot, quotquot, quotHquot) strategy. parameters:addStringAlternative(quotTypequot, quotLOWquot, quotquot , quotLquot) strategy. parameters:addStringAlternative(quotTypequot, quotCLOSEquot, quotquot, quotCquot) strategy. parameters:addStringAlternative(quotTypequot, quotMEDIANquot, quotquot, quotMquot) strategy. parameters:addStringAlternative(quotTypequot, quotTYPICALquot, quotquot, quotTquot) strategy. parameters:addStringAlternative(quotTypequot, quotWEIGHTEDquot, quotquot, quotWquot) strategy. parameters:addInteger(quotTrendMAPeriodquot, quotTrendMAPeriodquot, quotquot, 200) strategy. parameters:addGroup(quotLevelsquot) strategy. parameters:addInteger(quotOBquot, quotOverbought Levelquot, quotquot, 100) strategy. parameters:addInteger(quotOSquot, quot Oversold Levelquot, quotquot, -100) strategy. parameters:addInteger(quotOBCquot, quotOverbought Confirmation Levelquot, quotquot, 150) strategy. parameters:addInteger(quotOSCquot, quot Oversold Confirmation Levelquot, quotquot, -150) -- Price subscription parameters (bid or ask price, time frame) strategy. parameters:addGroup(quotPricequot) strategy. parameters:addString(quotPTquot, quotPrice Typequot, quotquot, quotBidquot) strategy. parameters:addStringAlternative(quotPTquot, quotBidquot, quotquot, quotBidquot) strategy. parameters:addStringAlternative(quotPTquot, quotAskquot, quotquot, quotAskquot) -- The global variables local BAR nil -- the price history we subscribed for local first -- the index of the oldest period where we can check whether moving averages has been crossed local btfFirst local OB, OS, OBC, OSC local CCI local Top, Bottom local gBTFSource -- streams local BTFTrendMAMethod local BTFTrendMAPeriod local BTFTrendMA local TrendMAMethod local TrendMAPeriod local TrendMA local upArrow nil local downArrow nil local STRATTFID 1 local BTFID 2 local BTFP1 local BTFType local SoundFile nil local RecurrentSound false local ALLOWEDSIDE local S -- Setup local T -- Trigger local CT -- Confirmed Trigger local lookBack local ShowAlert local Email local SendEmail local BaseSize function Prepare() -- Prepare all the data. -- The function is called once when the strategy is about to be started. -- check moving average parameters OBinstance. parameters. OB OS instance. parameters. OS OBC instance. parameters. OBC OSC instance. parameters. OSC CCIP instance. parameters. CCIP Sinstance. parameters. S Tinstance. parameters. T CTinstance. parameters. CT --downArrow instance:createTextOutput (quotUpquot, quotUpquot, quotWingdings 3quot, 20, core. HCenter, core. VTop, instance. parameters. Bottom, 0) --upArrow instance:createTextOutput (quotDownquot, quotDownquot, quotWingdings 3quot, 20, core. HCenter, core. VBottom, instance. parameters. Top, 0) quott1quot, quotThe strategy cannot be applied on ticks. quot) -- name the indicator local name profile:id(). quot, quot. instance. bid:name(). quot, cciquot. CCIP. quot, quot. instance. parameters. TF. quot, quot. ALLOWEDSIDE. quot quot instance:name(name) -- setup the signal. pay attention, we pass quotShowAlertquot (value initially taken from the instance. parameters. ShowAlert) -- here, so, we dont check whether alerts are requested anymore. -- and finally subscribe for the ticks of the instrument the user initially chosen to run the strategy for to -- have our strategy activated once. BAR ExtSubscribe(STRATTFID, nil, instance. parameters. TF, true, quotbarquot) -- create indicators CCI core. indicators:create(quotCCIquot, BAR, CCIP) BTFTrendMAMethodinstance. parameters. BTFTrendMAMethod BTFTrendMAPeriodinstance. parameters. BTFTrendMAPeriod BTFTypeinstance. parameters. BTFType TrendMAMethodinstance. parameters. TrendMAMethod TrendMAPeriodinstance. parameters. TrendMAPeriod Typeinstance. parameters. Type gBTFSource ExtSubscribe(BTFID, nil, instance. parameters. BTF, instance. parameters. BTFType quotBidquot, quotbarquot) if BTFType quotOquot then BTFP1 gBTFSource. open elseif BTFType quotHquot then BTFP1 gBTFSource. high elseif BTFType quotLquot then BTFP1 gBTFSource. low elseif BTFType quotMquot then BTFP1 gBTFSource. median elseif BTFType quotTquot then BTFP1 gBTFSource. typical elseif BTFType quotWquot then BTFP1 gBTFSource. weighted else BTFP1 gBTFSource. close end if Type quotOquot then P1 BAR. open elseif Type quotHquot then P1 BAR. high elseif Type quotLquot then P1 BAR. low elseif Type quotMquot then P1 BAR. median elseif Type quotTquot then P1 BAR. typical elseif Type quotWquot then P1 BAR. weighted else P1 BAR. close end BTFTrendMA core. indicators:create(quotAVERAGESquot, BTFP1, BTFTrendMAMethod, BTFTrendMAPeriod, false) TrendMA core. indicators:create(quotAVERAGESquot, P1, TrendMAMethod, TrendMAPeriod, false) -- and get the oldest index of the bar we can work at first math. max(CCI. DATA:first(), TrendMA. DATA:first()) btfFirst BTFTrendMA. DATA:first() end -- the function is called every time when any subscribed price is changed. For tick subscribtions the function is called -- for every tick, for the bar subscribtions the function is called when the candle is closed (in other words, when -- the first tick of the next candle appears). function ExtUpdate(id, source, period) if id STRATTFID and period gt first then -- on the user chosen subscription (can be either tick or bar subscribtion). -- update indicators CCI:update(core. UpdateLast) TrendMA:update(core. UpdateLast) -- if we have enough bars in the history to work if gBTFSource:size() gt 0 then local btfPeriod core. findDate(gBTFSource, BAR:date(period), false) -- if we have enough bars in the history to work Signal (quotTP0 - START: btfPeriod(quot. tostring(btfPeriod). quot) gt first(quot. tostring(first). quot)quot ) if btfPeriod gt btfFirst then Signal (quotTP0a - quot. quotbtfPeriod gt btfFirstquot) -- This bit added for signalling only if BTFMAFlag then if gBTFSource. close91btfPeriod93 lt BTFTrendMA. DATA91btfPeriod93 then Signal (quotTP1 - BTFtrend Downquot) BTFtrendDir quotDownquot elseif gBTFSource. close91btfPeriod93 lt BTFTrendMA. DATA91btfPeriod93 then Signal (quotTP2 - BTFtrend Upquot) BTFtrendDir quotUpquot end else BTFdir quotOffquot Signal (quotTP3 - BTFtrend Offquot) end if MAFlag then if BAR. close91period93 lt TrendMA. DATA91period93 then Signal (quotTP4 - trend Downquot) trendDdir quotDownquot el seif gBTFSource. close91btfPeriod93 lt BTFTrendMA. DATA91btfPeriod93 then Signal (quotTP5 - trend Upquot) trendDdir quotUpquot end else trendDdir quotOffquot Signal (quotTP6 - trend Offquot) end if S and core. crossesOver(CCI. DATA, OB, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then Signal ( quotSell Setup: Crossing above OverBoughtquot) elseif S and core. crossesUnder(CCI. DATA, OS, period) and (BTFtrendDir quotUpquot or BTFtrendDir quotOffquot) and (trendDir quotUpquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then Signal (quotBuy Setup: Crossing Below OverSoldquot) end if T and core. crossesOver(CCI. DATA, OS, period) and (BTFtrendDir quotUpquot or BTFtrendDir quotOffquot) and (trendDir quotUpquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then Signal (quotBuy Trigger: Crossing above OverSoldquot) elseif T and core. crossesUnder(CCI. DATA, OB, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then Signal (quotSell Trigger: Confirmed Crossing below OverBoughtquot) end if core. crossesOver(CCI. DATA, OBC, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then TOP true end if core. crossesUnder(CCI. DATA, OSC, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then BOTTOM true end if CT and core. crossesOver(CCI. DATA, OS, period) and (BTFtrendDir quotUpquot or BTFtrendDir quotOffquot) and (trendDir quotUpquot or trendDir quotOffquot) and BOTTOM and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then BOTTOM false Signal (quotBuy Trigger: Confirmed Crossing above OverSoldquot) elseif CT and core. crossesUnder(CCI. DATA, OB, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and TOP and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then TOP false Signal (quotSell Trigger: Confirmed Crossing below OverBoughtquot) end -- end of confirmation trigger signalling end end end end -- eof function ExtUpdate function Initialization() AllowMultiple instance. parameters. AllowMultiple ALLOWEDSIDE instance. parameters. ALLOWEDSIDE --local S instance. parameters. S --local T instance. parameters. T --local CT instance. parameters. CT local PlaySound instance. parameters. PlaySound if PlaySound then SoundFile instance. parameters. SoundFile else SoundFile nil end assert(not(PlaySound) or (PlaySound and SoundFile quotquot), quotSound file must be chosenquot) ShowAlert instance. parameters. ShowAlert RecurrentSound instance. parameters. RecurrentSound SendEmail instance. parameters. SendEmail if SendEmail then Email instance. parameters. Email else Email nil end assert(not(SendEmail) or (SendEmail and Email quotquot), quotE-mail address must be specifiedquot) end function Signal (Label) if ShowAlert then terminal:alertMessage(instance. bid:instrument(), instance. bid91NOW93, Label, instance. bid:date(NOW)) end nil then terminal:alertSound(SoundFile, RecurrentSound) end nil then terminal:alertEmail(Email, Label, profile:id(). quot(quot. instance. bid:instrument(). quot)quot. instance. bid91NOW93..quot, quot. Label..quot, quot. instance. bid:date(NOW)) end end There are only three sports: bullfighting, motor racing, and mountaineering all the rest are merely games. (c) Ernest Hemingway Hi Victor, Ive been correcting some of my typose too. This is getting really close now but problems still persist, this is now with line 295 as follows if gBTFSource. closebtfPeriod lt BTFTrendMA. DATAbtfPeriod then. the error is quotindex out of rangequot the values are as follows:- gBTFSource. close299 (1.44306) lt BTFTrendMA. DATA299 ( ) (btfFirst 199) I separated the two sides out into 2 lines as follows:- -- This works ok local y gBTFSource. closebtfPeriod -- this one gives ERROR INDEX OUT OF RANGE (does this line look right to you) local x BTFTrendMA. DATAbtfPeriod BTFTrendMA is created as follows: BTFTrendMA core. indicators:create(quotAVERAGESquot, BTFP1, BTFTrendMAMethod, BTFTrendMAPeriod, false) Is there something wrong with this line if not Im Now out of ideas to track this further Full code here Code: Select all -- Intoduce the strategy to the host application (for example, Marketscope). -- The function is called once when the host application initially loads the strategy. function Init() strategy:name(quotLonNYBTFsignalquot) strategy:description(quotLonNY Bigger Time Frame Signalling Strategyquot) -- Fast and slow moving average parameters strategy. parameters:addGroup(quotMain Controlsquot) strategy. parameters:addString(quotTFquot, quotStrategy Time Framequot, quotquot, quotm5quot) strategy. parameters:setFlag(quotTFquot, core. FLAGPERIODS) strategy. parameters:addString(quotALLOWEDSIDEquot, quotAllowed sidequot, quotAllowed side for trading or signaling, can be Sell, Buy or Bothquot, quotBothquot) strategy. parameters:addStringAlternative(quotALLOWEDSIDEquot, quotBothquot, quotquot, quotBothquot) strategy. parameters:addStringAlternative(quotALLOWEDSIDEquot, quotUpquot, quotquot, quotUpquot) strategy. parameters:addStringAlternative(quotALLOWEDSIDEquot, quotDnquot, quotquot, quotDnquot) strategy. parameters:addBoolean(quotSquot, quotSetup Alertquot, quotquot, false) strategy. parameters:addBoolean(quotTquot, quotTrigger Alertquot, quotquot, true) strategy. param eters:addBoolean(quotCTquot, quotConfirmed Trigger Alertquot, quotquot, false) strategy. parameters:addGroup(quotAlertsquot) strategy. parameters:addBoolean(quotShowAlertquot, quotShowAlertquot, quotquot, true) strategy. parameters:addBoolean(quotPlaySoundquot, quotPlay Soundquot, quotquot, true) strategy. parameters:addFile(quotSoundFilequot, quotSound Filequot, quotquot, quotquot) strategy. parameters:setFlag(quotSoundFilequot, core. FLAGSOUND) strategy. parameters:addBoolean(quotRecurrentSoundquot, quotRecurrent Soundquot, quotquot, true) strategy. parameters:addBoolean(quotSendEmailquot, quotSend Emailquot, quotquot, false) strategy. parameters:addString(quotEmailquot, quotEmailquot, quotquot, quotquot) strategy. parameters:setFlag(quotEmailquot, core. FLAGEMAIL) strategy. parameters:addGroup(quotCCI Parameterquot) strategy. parameters:addInteger(quotCCIPquot, quotCCI periodquot, quotquot, 20, 2, 200) strategy. parameters:addGroup(quotBigger Time Frame MA Parameterquot) strategy. parameters:addBo olean(quotBTFMAFlagquot, quotBigger Time Frame MA Trend onquot, quotquot, true) strategy. parameters:addString(quotBTFTrendMAMethodquot, quotBTFTrendMAMethodquot, quotquot, quotMVAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotMVAquot, quotquot, quotMVAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotEMAquot, quotquot, quotEMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotWilderquot, quotquot, quotWilderquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotLWMAquot, quotquot, quotLWMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotSineWMAquot, quotquot, quotSineWMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotTriMAquot, quotquot, quotTriMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotLSMAquot, quotquot, quotLSMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotS MMAquot, quotquot, quotSMMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotHMAquot, quotquot, quotHMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotZeroLagEMAquot, quotquot, quotZeroLagEMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotDEMAquot, quotquot, quotDEMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotT3quot, quotquot, quotT3quot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotITrendquot, quotquot, quotITrendquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotMedianquot, quotquot, quotMedianquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotGeoMeanquot, quotquot, quotGeoMeanquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotREMAquot, quotquot, quotREMAquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotILRSquot, quotquot, quotILRSquot) st rategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotIE2quot, quotquot, quotIE2quot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotTriMAgenquot, quotquot, quotTriMAgenquot) strategy. parameters:addStringAlternative(quotBTFTrendMAMethodquot, quotJSmoothquot, quotquot, quotJSmoothquot) strategy. parameters:addString(quotBTFTypequot, quotBTFPrice Typequot, quotquot, quotCquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotOPENquot, quotquot, quotOquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotHIGHquot, quotquot, quotHquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotLOWquot, quotquot, quotLquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotCLOSEquot, quotquot, quotCquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotMEDIANquot, quotquot, quotMquot) strategy. parameters:addStringAlternative(quotBTFTypequot, quotTYPICALquot, quotquot, quotTquot) strategy. parameters:ad dStringAlternative(quotBTFTypequot, quotWEIGHTEDquot, quotquot, quotWquot) strategy. parameters:addInteger(quotBTFTrendMAPeriodquot, quotBTFTrendMAPeriodquot, quotquot, 200) strategy. parameters:addString(quotBTFquot, quotBigger Time Framequot, quotquot, quotm30quot) strategy. parameters:setFlag(quotBTFquot, core. FLAGPERIODS) strategy. parameters:addGroup(quotStrategy Time Frame MA Parameterquot) strategy. parameters:addBoolean(quotStrategyMAFlagquot, quotStrategy MA Trend onquot, quotquot, true) strategy. parameters:addString(quotTrendMAMethodquot, quotTrendMAMethodquot, quotquot, quotMVAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotMVAquot, quotquot, quotMVAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotEMAquot, quotquot, quotEMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotWilderquot, quotquot, quotWilderquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotLWMAquot, quotquot, quotLWMAqu ot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotSineWMAquot, quotquot, quotSineWMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotTriMAquot, quotquot, quotTriMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotLSMAquot, quotquot, quotLSMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotSMMAquot, quotquot, quotSMMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotHMAquot, quotquot, quotHMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotZeroLagEMAquot, quotquot, quotZeroLagEMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotDEMAquot, quotquot, quotDEMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotT3quot, quotquot, quotT3quot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotITrendquot, quotquot, quotITrendquot) strategy. parameters:addStringAlternative(quotTrendMAMethodqu ot, quotMedianquot, quotquot, quotMedianquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotGeoMeanquot, quotquot, quotGeoMeanquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotREMAquot, quotquot, quotREMAquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotILRSquot, quotquot, quotILRSquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotIE2quot, quotquot, quotIE2quot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotTriMAgenquot, quotquot, quotTriMAgenquot) strategy. parameters:addStringAlternative(quotTrendMAMethodquot, quotJSmoothquot, quotquot, quotJSmoothquot) strategy. parameters:addString(quotTypequot, quotPrice Typequot, quotquot, quotCquot) strategy. parameters:addStringAlternative(quotTypequot, quotOPENquot, quotquot, quotOquot) strategy. parameters:addStringAlternative(quotTypequot, quotHIGHquot, quotquot, quotHquot) strategy. parameters:addStringAlternative(quotTypequot, quot LOWquot, quotquot, quotLquot) strategy. parameters:addStringAlternative(quotTypequot, quotCLOSEquot, quotquot, quotCquot) strategy. parameters:addStringAlternative(quotTypequot, quotMEDIANquot, quotquot, quotMquot) strategy. parameters:addStringAlternative(quotTypequot, quotTYPICALquot, quotquot, quotTquot) strategy. parameters:addStringAlternative(quotTypequot, quotWEIGHTEDquot, quotquot, quotWquot) strategy. parameters:addInteger(quotTrendMAPeriodquot, quotTrendMAPeriodquot, quotquot, 200) strategy. parameters:addGroup(quotLevelsquot) strategy. parameters:addInteger(quotOBquot, quotOverbought Levelquot, quotquot, 100) strategy. parameters:addInteger(quotOSquot, quot Oversold Levelquot, quotquot, -100) strategy. parameters:addInteger(quotOBCquot, quotOverbought Confirmation Levelquot, quotquot, 150) strategy. parameters:addInteger(quotOSCquot, quot Oversold Confirmation Levelquot, quotquot, -150) -- Price subscription parameters (bid or ask price, time frame) strategy. parameters:addGroup(quotPri cequot) strategy. parameters:addString(quotPTquot, quotPrice Typequot, quotquot, quotBidquot) strategy. parameters:addStringAlternative(quotPTquot, quotBidquot, quotquot, quotBidquot) strategy. parameters:addStringAlternative(quotPTquot, quotAskquot, quotquot, quotAskquot) -- The global variables local BAR nil -- the price history we subscribed for local first -- the index of the oldest period where we can check whether moving averages has been crossed local btfFirst local OB, OS, OBC, OSC local CCI local Top, Bottom local gBTFSource -- streams local BTFTrendMAMethod local BTFTrendMAPeriod local BTFTrendMA local BTFtrendDir local TrendMAMethod local TrendMAPeriod local TrendMA local trendDir local STRATTFID 1 local BTFID 2 local BTFP1 local BTFType local SoundFile nil local RecurrentSound false local ALLOWEDSIDE local S -- Setup local T -- Trigger local CT -- Confirmed Trigger local lookBack local ShowAlert local Email local SendEmail local BaseSize function Prepare() -- Prepare all the data. -- The function is called once when the strategy is about to be started. -- check moving average parameters OBinstance. parameters. OB OS instance. parameters. OS OBC instance. parameters. OBC OSC instance. parameters. OSC CCIP instance. parameters. CCIP Sinstance. parameters. S Tinstance. parameters. T CTinstance. parameters. CT quott1quot, quotThe strategy cannot be applied on ticks. quot) -- name the indicator local name profile:id(). quot, quot. instance. bid:name(). quot, cciquot. CCIP. quot, quot. instance. parameters. TF. quot, quot. ALLOWEDSIDE. quot quot instance:name(name) -- setup the signal. pay attention, we pass quotShowAlertquot (value initially taken from the instance. parameters. ShowAlert) -- here, so, we don-t check whether alerts are requested anymore. -- and finally subscribe for the ticks of the instrument the user initially chosen to run the strategy for to -- have our strategy activated once. BAR ExtSubscribe(STRATTFID, nil, instance. parameters. TF, true, quotbarquot) -- create indicators CCI core. indicators:create(quotCCIquot, BAR, CCIP) BTFTrendMAMethodinstance. parameters. BTFTrendMAMethod BTFTrendMAPeriodinstance. parameters. BTFTrendMAPeriod BTFTypeinstance. parameters. BTFType BTFMAFlag instance. parameters. BTFMAFlag TrendMAMethodinstance. parameters. TrendMAMethod TrendMAPeriodinstance. parameters. TrendMAPeriod Typeinstance. parameters. Type MAFlag instance. parameters. MAFlag gBTFSource ExtSubscribe(BTFID, nil, instance. parameters. BTF, instance. parameters. BTFType quotBidquot, quotbarquot) if BTFType quotOquot then BTFP1 gBTFSource. open elseif BTFType quotHquot then BTFP1 gBTFSource. high elseif BTFType quotLquot then BTFP1 gBTFSource. low elseif BTFType quotMquot then BTFP1 gBTFSource. median elseif BTFType quotTquot then BTFP1 gBTFSource. typical elseif BTFType quotWquot then BTFP1 gBTFSource. weighted else BTFP1 gBTFSource. close end if Type quotOquot then P1 BAR. open elseif Type quotHquot then P1 BAR. high elseif Type quotLquot then P1 BAR. low elseif Type quotMquot then P1 BAR. median elseif Type quotTquot then P1 BAR. typical elseif Type quotWquot then P1 BAR. weighted else P1 BAR. close end BTFTrendMA core. indicators:create(quotAVERAGESquot, BTFP1, BTFTrendMAMethod, BTFTrendMAPeriod, false) TrendMA core. indicators:create(quotAVERAGESquot, P1, TrendMAMethod, TrendMAPeriod, false) -- and get the oldest index of the bar we can work at first math. max(CCI. DATA:first(), TrendMA. DATA:first()) btfFirst BTFTrendMA. DATA:first() end -- the function is called every time when any subscribed price is changed. For tick subscribtions the function is called -- for every tick, for the bar subscribtions the function is called when the candle is closed (in other words, when -- the first tick of the next candle appears). function ExtUpdate(id, source, period) if id STRATTFID and period gt first then -- on the user chosen subscription (can be either tick or bar subscribtion). -- update indicators CCI:update(core. UpdateLast) TrendMA:update(core. UpdateLast) -- if we have enough bars in the history to work if gBTFSource:size() gt 0 then local btfPeriod core. findDate(gBTFSource, BAR:date(period), false) -- if we have enough bars in the history to work if btfPeriod gt btfFirst then -- This works ok local y gBTFSource. close91btfPeriod93 -- this one gives ERROR INDEX OUT OF RANGE local x BTFTrendMA. DATA91btfPeriod93 -- This bit added for signalling only if BTFMAFlag true then Signal(quotgBTFSource. close91quot. tostring(btfPeriod). quot93 (quot. tostring(gBTFSource. close91btfPeriod93). quot) lt BTFTrendMA. DATA91quot. tostring(btfPeriod). quot93 ( ) (btfFirst quot. tostring(btfFirst)) if gBTFSource. close91btfPeriod93 lt BTFTrendMA. DATA91btfPeriod93 then --Signal (quotTP1 - BTFtrend Downquot) BTFtrendDir quotDownquot elseif gBTFSource. close91btfPeriod93 lt BTFTrendMA. DATA91btfPeriod93 then --Signal (quotTP2 - BTFtrend Upquot) BTFtrendDir quotUpquot end el se BTFdir quotOffquot --Signal (quotTP3 - BTFtrend Offquot) end if MAFlag then if BAR. close91period93 lt TrendMA. DATA91period93 then -- Signal (quotTP4 - trend Downquot) trendDdir quotDownquot elseif gBTFSource. close91btfPeriod93 lt BTFTrendMA. DATA91btfPeriod93 then -- Signal (quotTP5 - trend Upquot) trendDdir quotUpquot end else trendDdir quotOffquot --Signal (quotTP6 - trend Offquot) end if S and core. crossesOver(CCI. DATA, OB, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then Signal ( quotSell Setup: Crossing above OverBoughtquot) elseif S and core. crossesUnder(CCI. DATA, OS, period) and (BTFtrendDir quotUpquot or BTFtrendDir quotOffquot) and (trendDir quotUpquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then Signal (quotBuy Setup: Crossing Below OverSoldquot) end if T and core. crossesOver(CCI. DATA , OS, period) and (BTFtrendDir quotUpquot or BTFtrendDir quotOffquot) and (trendDir quotUpquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then Signal (quotBuy Trigger: Crossing above OverSoldquot) elseif T and core. crossesUnder(CCI. DATA, OB, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then Signal (quotSell Trigger: Confirmed Crossing below OverBoughtquot) end if core. crossesOver(CCI. DATA, OBC, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then TOP true end if core. crossesUnder(CCI. DATA, OSC, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then BOTTOM true end if CT and core. crossesOver(CCI. DATA, OS, period) and (BTFtrendDir quotUpquot or BTFtrendDir quotOffquot) and (trendDir quotUpquot or trendDir quotOffquot) and BOTTOM and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotUpquot) then BOTTOM false Signal (quotBuy Trigger: Confirmed Crossing above OverSoldquot) elseif CT and core. crossesUnder(CCI. DATA, OB, period) and (BTFtrendDir quotDownquot or BTFtrendDir quotOffquot) and (trendDir quotDownquot or trendDir quotOffquot) and TOP and (ALLOWEDSIDE quotBothquot or ALLOWEDSIDE quotDnquot) then TOP false Signal (quotSell Trigger: Confirmed Crossing below OverBoughtquot) end -- end of confirmation trigger signalling end end end end -- eof function ExtUpdate function Initialization() AllowMultiple instance. parameters. AllowMultiple ALLOWEDSIDE instance. parameters. ALLOWEDSIDE --local S instance. parameters. S --local T instance. parameters. T --local CT instance. parameters. CT local PlaySound instance. parameters. PlaySo und if PlaySound then SoundFile instance. parameters. SoundFile else SoundFile nil end assert(not(PlaySound) or (PlaySound and SoundFile quotquot), quotSound file must be chosenquot) ShowAlert instance. parameters. ShowAlert RecurrentSound instance. parameters. RecurrentSound SendEmail instance. parameters. SendEmail if SendEmail then Email instance. parameters. Email else Email nil end assert(not(SendEmail) or (SendEmail and Email quotquot), quotE-mail address must be specifiedquot) end function Signal (Label) if ShowAlert then terminal:alertMessage(instance. bid:instrument(), instance. bid91NOW93, Label, instance. bid:date(NOW)) end nil then terminal:alertSound(SoundFile, RecurrentSound) end nil then terminal:alertEmail(Email, Label, profile:id(). quot(quot. instance. bid:instrument(). quot)quot. instance. bid91NOW93..quot, quot. Label..quot, quot. instance. bid:date(NOW)) end end

No comments:

Post a Comment