MultiCharts 停損追蹤守線交易程式
把 以前 日盛HTS的一支 簡單的 建新倉、停損、停利、布林通道、守線、追蹤折頭..等等功能的程式移轉給 MC 經過測試 一切正常顯示 倉位的 進出
MC 編寫自訂函數時,要過濾 輸入參數=0 的 狀況,以免 計算產生 除以0 或 出現 例外異常 的信息。
暫時不把 程式包 上傳,先看看 是否有需要?
我多在 搞破壞,一些業內,粉恨~~~~
真歹勢~~~ MC還不會用,現在正在學VBA
資格太淺不能下載來參考............. 把 以前 日盛HTS的一支 簡單的 建新倉、停損、停利、布林通道、守線、追蹤折頭..等等功能的程式
移轉給 MC...
trading144 發表於 10-10-18 08:06 PM http://www.coco-in.net/images/common/back.gif
就放上來吧,業內不用管它吧
雖然我沒用MC 不過我還是很期待 T大的程式可以讓我參考 這是屬於 MC 的 封包,要使用 MC 才能導入
假若要 文字檔,比較難搞。
每種介面語法略有不同,又沒有 圖形去比對信號,比較難瞭解程式信號的效果。
再看看吧! 有時間在弄出來 TXT檔 Inputs: InitialStop(21),Profit(89),BreakEven(21),MinDist(13)
,Trade(34),car(3),StopLine(34),StopCar(3),Band(89),ref(1)
,Line(144),Turn(21),Stpadjust(4),Cnt(1),Factor(1),DayTrade(0),output(0);
Vars:BuyLimit(0),SellLimit(0),isStop(0),isBand(0),TheEnd(0)
,isBuy(0),isSell(0),ProfitHit(0),BandHit(0)
,lastB(0),lastS(0),isLong(0),isShort(0),isTrace2(0)
,Bprice(0),Sprice(0),BandH(0),BandL(0),isTrace(0)
,Blost(0),Slost(0),PP(0),HitProfit(0),isTrade2(0)
,Bcost(0),Scost(0),isTurned(0),LineH2(0),LineL2(0),LineH1(0),LineL1(0)
,Turn1(0),Turn2(0),balance(0),Blost1(0),Slost1(0),Dist(0),Hit(0)
,nColor( green ), nCurrentContracts(0);
Dist=MinDist+Stpadjust*2; //Dist=6+4*2
if Band>0 then begin
Value3 = StdDev((High+Low)/2, Band); //Band = 89
BandH = AverageFC((High+Low)/2, Band) + 2.5 * Value3;
BandL = AverageFC((High+Low)/2, Band) - 2.5 * Value3;
end;
if Line>0 and Turn>0 then begin
Value1=AverageFC((High+Low)/2, Turn);
Value2=AverageFC((High+Low)/2, Line);
Value21=AverageFC((High+Low)/2, Turn);
Value22=AverageFC((High+Low)/2, Line);
LineH1=AverageFC(High, Line);
LineH2=AverageFC(High, Line);
LineL1=AverageFC(Low, Line);
LineL2=AverageFC(Low, Line);
Turn1=AverageFC((High+Low)/2, Turn); // Turn = 21
Turn2=AverageFC((High+Low)/2, Turn);
end;
if Turn2>=LineL2 andTurn1<LineL1 and Line<>0 then begin
isTurned=2;
end;
if Turn2<=LineH2 andTurn1>LineH1 and Line<>0 then begin
isTurned=1;
end;
if StopLine>0 then begin
Value12=AverageFC(Low, StopLine); // StopLine = 34
Value11=AverageFC(High, StopLine);
end;
HitProfit=Profit;
balance=absvalue( CurrentContracts );
if CurrentContracts = 0 then begin
isLong=0;
isTrace=1;
isShort=0;
Hit=0;
Slost=0;
Scost=0;
Blost=0;
Bcost=0;
end;
if time>=84500 then begin
isTrace2=0;
end;
if StopLine>0 and StopCar=1 then isStop=Stopped(StopLine,ref) else isStop=0;
if StopLine>0 and StopCar>1 then isStop=Stopped2(StopLine,StopCar,ref) else isStop=0;
if Trade>0 and car>0 then isTrade2=Crossed(Trade,car,ref) else isTrade2=0;
if isTrace=1 and isLong=0 and isShort=0 and (time<132500 or DayTrade=0) then begin
if isTrade2=1 and (isTurned=1 or Value2=0)
and (Close>Value12 or Value12=0) then begin
buy("bb") Cnt contracts next bar at market;
isLong=1;
isShort=0;
ProfitHit=0;
BandHit=0;
Sprice=0;
Bcost=Close;
Bprice=Close+IntPortion(HitProfit/1);
Blost=Close - InitialStop;
PP=Close;
//Return;
end;
if isTrade2=2 and (isTurned=2 or Value2=0)
and (Close<Value11 or Value11=0) then begin
SellShort("ss") Cnt contracts next bar at market;
isLong=0;
isShort=1;
ProfitHit=0;
BandHit=0;
Bprice=0;
Scost=Close;
Sprice=Close-IntPortion(HitProfit/1);
Slost=Close + InitialStop;
PP=Close;
//Return;
end;
end;
if isLong = 1 then begin
balance=absvalue( CurrentContracts );
if InitialStop > 0 and Blost=0 and Bcost=0 then begin
Blost=EntryPrice(0) - InitialStop ;
Bcost=EntryPrice(0);
end;
if Blost<Bcost and EntryTime(0)=time then begin
//exitlong("XL0") all contracts this bar at Blost-Stpadjust*2 stop;
sell("XL0") all contracts next bar at Blost-Stpadjust*2 stop;
end;
if Blost<Bcost and EntryTime(0)<time then begin
//exitlong("XL1") all contracts this bar at Blost stop;
sell("XL1") all contracts next bar at Blost stop;
end;
if Blost<Bcost and EntryTime(0)<time and Close<Blost then begin
//exitlong("XL") all contracts next bar at market;
sell("XL") all contracts next bar at market;
end;
if BreakEven > 0 and High-Bcost>BreakEvenand Blost<Bcost and EntryTime(0)<time then begin
Blost=Bcost+1;
Blost1=Bcost+1;
end;
if MinDist > 0 and High-Blost>Distand Blost>Bcost and EntryTime(0)<time
and (balance=Cnt or ProfitHit=1 or Hit=1) then begin
Blost=High-Dist;
Blost1=High-MinDist;
//exitlong("TL0") Round(Cnt/2,0) contracts this bar at Blost stop;
sell("TL0") Round(Cnt/2,0) contracts next bar at Blost stop;
end;
if MinDist > 0 and High-Blost<Dist and High<=Blost1 and Blost>Bcost
and EntryTime(0)<time then begin
//exitlong("TL1") Round(Cnt/2,0) contracts this bar at Blost stop;
sell("TL1") Round(Cnt/2,0) contracts next bar at Blost stop;
end;
if MinDist > 0 and High-Blost<Dist and High>Blost1 and Blost>Bcost
and EntryTime(0)<time then begin
//exitlong("TL2") Round(Cnt/2,0) contracts this bar at Blost1-Stpadjust stop;
sell("TL2") Round(Cnt/2,0) contracts next bar at Blost1-Stpadjust stop;
end;
if MinDist > 0 and High-Blost<Dist and High>Blost1 and Blost>Bcost
and EntryTime(0)<time and Close<Blost1 then begin
//exitlong("TL") Round(Cnt/2,0) contracts next bar at market;
sell("TL") Round(Cnt/2,0) contracts next bar at market;
end;
if High > Bprice and HitProfit > 0 and ProfitHit = 0 then begin
//exitlong("EL")Round(Cnt/2,0) contracts total next bar at Market;
sell("EL")Round(Cnt/2,0) contracts total next bar at Market;
ProfitHit = 1;
isTrace2=1;
Bprice=Bprice+IntPortion(HitProfit*Factor);
PP=Close;
end;
if High > Bprice and HitProfit > 0 and ProfitHit = 1 then begin
//exitlong("EL1")Round(Cnt/2,0) contracts total next bar at Market;
sell("EL1")Round(Cnt/2,0) contracts total next bar at Market;
ProfitHit = 2;
PP=Close;
end;
if isStop = 2 then begin//and Close > Bcost then
//exitlong("XL2") all contracts next bar at market;
sell("XL2") all contracts next bar at market;
isLong=0;isTrace=1; isShort=0;
PP=Close;
end;
if High > BandH and Band > 0 and BandHit = 0 and ProfitHit = 1 then begin
//exitlong("top") Round(balance/2,0) contract total next bar at market;
sell("top") Round(balance/2,0) contract total next bar at market;
BandHit = 1;
PP=Close;
end;
if Turn2>=LineL2 andTurn1<LineL1 and Line<>0 then begin
//exitlong("EL3") Round(balance/2,0) contracts next bar at market;
sell("EL3") Round(balance/2,0) contracts next bar at market;
PP=Close;
Hit=1;
end;
end;
if isShort = 1 then begin
balance=absvalue( CurrentContracts );
if InitialStop > 0 and Slost=0 and Scost=0 then begin
Slost=EntryPrice(0) + InitialStop ;
Scost=EntryPrice(0);
end;
if Slost>Scost and EntryTime(0)=time then begin
//exitshort("XS0") all contracts this bar at Slost+Stpadjust*2 stop;
BuytoCover("XS0") all contracts next bar at Slost+Stpadjust*2 stop;
end;
if Slost>Scost and EntryTime(0)<time then begin
//exitshort("XS1") all contracts this bar at Slost stop;
BuytoCover("XS1") all contracts next bar at Slost stop;
end;
if Slost>Scost and EntryTime(0)<time and Close>Slost then begin
//exitshort("XS") all contracts next bar at market;
BuytoCover("XS") all contracts next bar at market;
end;
if BreakEven > 0 and Scost-Low>BreakEven and Slost>Scost and EntryTime(0)<time then begin
Slost=Scost-1 ;
Slost1=Scost-1 ;
end;
if MinDist > 0 and Slost-Low>Dist and Slost<Scost and EntryTime(0)<time
and (balance=Cnt or ProfitHit=1 or Hit=1) then begin
Slost=Low+Dist ;
Slost1=Low+MinDist;
//exitshort("TS0") Round(Cnt/2,0) contracts this bar at Slost stop;
BuytoCover("TS0") Round(Cnt/2,0) contracts next bar at Slost stop;
end;
if MinDist > 0 and Slost-Low<Dist and Low>=Slost1 and Slost<Scost
and EntryTime(0)<time then begin
//exitshort("TS1") Round(Cnt/2,0) contracts this bar at Slost stop;
BuytoCover("TS1") Round(Cnt/2,0) contracts next bar at Slost stop;
end;
if MinDist > 0 and Slost-Low<Dist and Low<Slost1 and Slost<Scost
and EntryTime(0)<time then begin
//exitshort("TS2") Round(Cnt/2,0) contracts this bar at Slost1+Stpadjust stop;
BuytoCover("TS2") Round(Cnt/2,0) contracts next bar at Slost1+Stpadjust stop;
end;
if MinDist > 0 and Slost-Low<Dist and Low<Slost1and Slost<Scost
and EntryTime(0)<time and Close>Slost1 then begin
//exitshort("TS") Round(Cnt/2,0) contracts next bar at market;
BuytoCover("TS") Round(Cnt/2,0) contracts next bar at market;
end;
if Low < Sprice and HitProfit > 0 and ProfitHit = 0 then begin
//exitshort("ES") Round(Cnt/2,0) contracts total next bar at Market;
BuytoCover("ES") Round(Cnt/2,0) contracts total next bar at Market;
ProfitHit = 1;
isTrace2=1;
Sprice=Sprice-IntPortion(HitProfit*Factor);
PP=Close;
end;
if Low < Sprice and HitProfit > 0 and ProfitHit = 1 then begin
//exitshort("ES1") Round(Cnt/2,0) contracts total next bar at Market;
BuytoCover("ES1") Round(Cnt/2,0) contracts total next bar at Market;
ProfitHit = 2;
PP=Close;
end;
if isStop = 1 then begin//and Close < Scost then
//exitshort("XS2") all contracts next bar at market;
BuytoCover("XS2") all contracts next bar at market;
isShort=0;isTrace=1; isLong=0;
PP=Close;
end;
if Low < BandL and Band > 0 and BandHit = 0 and ProfitHit = 1 then begin
//exitshort("bot") Round(balance/2,0) contract total next bar at market;
BuytoCover("bot") Round(balance/2,0) contract total next bar at market;
BandHit = 1;
PP=Close;
end;
if Turn2<=LineH2 andTurn1>LineH1 and Line<>0 then begin
//exitshort("ES3") Round(balance/2,0) contracts next bar at market;
BuytoCover("ES3") Round(balance/2,0) contracts next bar at market;
PP=Close;
Hit=1;
end;
end;
//if Date=1090819 or Date=1090916 or Date=1091021 or Date=1091118 or Date=1091216 then//Last Trading Day
// TheEnd=132500else TheEnd=134000
//end if
if time>=TheEnd and DayTrade=1 then begin
if CurrentContracts > 0 then begin
//exitlong("end1") all contracts next bar at market;
sell("end1") all contracts next bar at market;
PP=Close;
end;
if CurrentContracts < 0 then begin
//exitshort("end2") all contracts next bar at market;
buytocover("end2") all contracts next bar at market;
PP=Close;
end;
end;
if date=lastcalcdate and time=lastcalctime and output>0 then begin
FileDelete( "R:\CurrentH"+numtostr(output,0)+".txt" );
//if currentcontracts=0 then begin
// fileappend("R:\CurrentH"+numtostr(output,0)+".txt",cdate(date)+" "+ctime(time)+","+
// numtostr(currentcontracts,0)+","+numtostr(ExitPrice(0),0));
//end;
//if currentcontracts!=0 then begin
// fileappend("R:\CurrentH"+numtostr(output,0)+".txt",cdate(date)+" "+ctime(time)+","+
// numtostr(currentcontracts,0)+","+numtostr(PP,0));
//end;
end; Inputs: Length(Numeric),ref(Numeric);
Variables:MAH1(0),MAL1(0),MAH2(0),MAL2(0),CAR1(0),CAR2(0),cur(0),nlast(0);
if Length>0 then begin
MAH1=AverageFC(High, Length);
MAL1=AverageFC(Low, Length);
CAR1=AverageFC((High+Low)/2, 1);
CAR2=AverageFC((High+Low)/2, 1);
MAH2=AverageFC(High, Length);
MAL2=AverageFC(Low, Length);
if CAR2 <= MAH2 and CAR1 > MAH1 then begin
cur=1;
end;
if CAR2 >= MAL2 and CAR1 < MAL1 then begin
cur=2;
end;
if cur <> nlast then begin
nlast=cur;
Stopped=nlast;
end
else begin
Stopped=0;
end;
end
elsebegin
Stopped=0;
end; // Cross MA as Stopped2
Inputs: Length(Numeric),car(Numeric),ref(Numeric);
Variables:MAH1(0),MAL1(0),MAH2(0),MAL2(0),CAR1(0),CAR2(0),cur(0),nlast(0),
MA1(0),MA2(0);
if Length>0 and car>0 then begin
MAH1=AverageFC(High, Length);
MAL1=AverageFC(Low, Length);
CAR1=AverageFC((High+Low)/2, car);
CAR2=AverageFC((High+Low)/2, car);
MAH2=AverageFC(High, Length);
MAL2=AverageFC(Low, Length);
if CAR2 < MAL2 and CAR1 > MAL1 and cur=2 then begin
nlast=0;
cur=0;
//return;
end;
if CAR2 > MAH2 and CAR1 < MAH1 and cur=1 then begin
nlast=0;
cur=0;
//return;
end;
if CAR2 <= MAH2 and CAR1 > MAH1 then begin //UPCROSS
cur=1;
end;
if CAR2 >= MAL2 and CAR1 < MAL1 then begin //DOWNCROSS
cur=2;
end;
if cur <> nlast then begin
nlast=cur;
Stopped2=nlast;
end
else begin
Stopped2=0;
end;
end
elsebegin
Stopped2=0;
end; Inputs: Length(Numeric),car(Numeric),ref(Numeric);
Variables:MAH1(0),MAL1(0),MAH2(0),MAL2(0),CAR1(0),CAR2(0),cur(0),nlast(0);
if Length>0 and car>0 then begin
MAH1=AverageFC(High, Length);
MAL1=AverageFC(Low, Length);
CAR1=AverageFC((High+Low)/2, car);
CAR2=AverageFC((High+Low)/2, car);
MAH2=AverageFC(High, Length);
MAL2=AverageFC(Low, Length);
if CAR2 <= MAH2 and CAR1 > MAH1 then begin
cur=1;
end;
if CAR2 >= MAL2 and CAR1 < MAL1 then begin
cur=2;
end;
if cur <> nlast then begin
nlast=cur;
Crossed=nlast;
end
else begin
Crossed=0;
end;
end
elsebegin
Crossed=0;
end; 嘿嘿!原來可以 直接貼喔!
省事!
大家 加減參考啦!
阿! 福氣啦!!! 呼宜企啦!
殘殘 豆干 切8角。 感謝分享!!
下載來學習學習!!
有問題再來請教!! trading144 大真是文思泉湧,沒點基礎還真無法改
謝啦 感謝喔
趕快來研究 trading144大 能分享hts寫好的程式嗎 謝謝 回復 14# 052756
這一位仁兄,你碼幫幫忙。
那個 倉位進出 那一行 有 被 // 的就是 HTS 的 語法。
其他 多港款。
關於 時間 的數字表示 則 需要 多2個0,例如:1340--->134000