請選擇 進入手機版 | 繼續訪問電腦版

COCO研究院

 找回密碼
 註冊
搜索
查看: 2618|回復: 3

布林通道語法請教

[複製鏈接]
發表於 16-9-8 22:06 | 顯示全部樓層 |閱讀模式
小弟是MC新手最近想寫一個布林通道的策略,但跑起來一直有問題,想請問下面語法哪裡有錯?另外,是否有更好建議可提供
Inputs:bollingerLengths(20),line1(2),line2(2),gaphigh(10),gapmid(5),stdths(10),stdthsloss(10),hm(1),hl(1),bm(1),bl(1);
Vars: upBand(0),dnBand(0),mid(0),std(0),innumber(0);

upBand = BollingerBand(Close,bollingerlengths,(20*0.1));  
dnBand = BollingerBand(Close,bollingerlengths,(20*(-0.1)));  
mid=(upband+dnband)*0.5; //設定布林通道上下中線
std=upBand-dnBand;

順勢進場
//in
if innumber=0 and std>std[1] and std[1]>std[2] and std[2]>std[3] then begin

if h >upband and marketposition=0 then buy("highbuy") next bar  at market;
if l <dnband and marketposition=0 then sellshort("highshort")   next bar at market; //過上線或下線進場
innumber=innumber+1;
end;
出場
//loss
if innumber=1 then begin
if l <mid and marketposition>0 then sell("highsell") next bar  at market;
if h>mid  and marketposition<0  then buytocover ("highcover") next bar at market; //回落至中線出場
innumber=innumber-1;
end;

逆勢進場
//in
if innumber=0 and std<=gapmid then begin
if l<dnband and marketposition=0 then buy("midbuy") next bar at market;
if h>upband and marketposition=0 then sellshort ("midshort") next bar at market;  //碰上下限反向操作
innumber=2;
end;
出場
//loss
if innumber=2 then begin
if l< mid and marketposition>0 then sell("midsell") next bar  at market;
if h> mid and marketposition<0  then buytocover("midcover") next bar at market; //回落至中線出場
innumber=innumber-2;
end;


發表於 16-9-9 19:59 來自手機 | 顯示全部樓層
2.要將K棒可能會同時跨在billing info 指標的兩條或三條線上,這會造成進出場訊號錯誤
回復 支持 1 反對 0

使用道具 舉報

發表於 16-9-10 14:03 | 顯示全部樓層
不要用innumber去計算部位,而且你這樣寫多空都混在一起,部位全記錯了

值接利用marketposition跟currentcontracts去判斷部位跟多空即可
回復 支持 1 反對 0

使用道具 舉報

發表於 16-9-9 19:55 來自手機 | 顯示全部樓層
1.變數 innumber 在判斷條件不成立時不會計數,會造成有倉位時無法出場
您需要登錄後才可以回帖 登錄 | 註冊

本版積分規則

手機版|Archiver|站長信箱|廣告洽詢|COCO研究院

GMT+8, 24-3-29 06:18

Powered by Discuz! X3.4

Copyright © 2001-2023, Tencent Cloud.

快速回復 返回頂部 返回列表
理財討論網站 | AI繪圖AI超擬真美女AI beauty AI Stable DiffusionAI正妹AI Lookbook