策略模擬OK,但上線後停損單常會被MC取消,請教各位大大
這是我的策略,用在30分K好幾次下了買單金到了停損價沒有賣出,一看停利單還在,但停損單被取消了,想請問高手原因??
// Created from 2023/10/17
// 30 min K ,
// QS_AVG_V00
// QS_AVG_V01 2023/10/21
inputs:
longon(0),
shorton(0),
longlen(38),
shortlen(38),
suplen( 114) ;
vars:
// AvgPrice(0);//Built-In Function Already
//shortlen(0),
stop_price(0),
stop_price_short(0),
MA1(0),
MA2(0),
MA3(0),
MA4(0),
MA5(0),
MA6(0),
MA_sup(0),
MA_short(0),
MA_long(0);
//shortlen = longlen;
MA1 = Average(C, 9);
MA2 = Average(C, 19);
MA3 = Average(C, 38);
MA4 = Average(C, 57);
MA5 = Average(C, 76);
MA6 = Average(C, 95);
MA_sup = Average(C, suplen );
MA_long = Average(C, longlen);
MA_short = Average(C, shortlen);
//MA6 = Average(C, 19*6);
condition1 = MA_long > MA_long;// Up Trend Status
condition2 = MA_short < MA_short;// Down Trend Status
condition3 = AvgPrice cross above MA_long; // Cross Above MA3 Timing
condition4 = AvgPrice cross below MA_short; // Cross Below MA3 Timing
condition5 = AvgPrice < MA_long; // Price Under Status
condition6 = AvgPrice > MA_short; // Price Higher Status
condition7 = C > MA_sup;//TRUE;//MA_sup > MA_sup;//MA6 > MA6; // Long Up Trend Status
condition8 = C < MA_sup;//TRUE;//MA_sup < MA_sup;//MA6 < MA6; // Long Down Trend Status
if longon = 1 then
begin
if condition1 and condition5 and condition3 and condition7then
begin
buy next bar market;
//buy next bar at highest(H , 3) stop;
//stop_price = lowest( L , 3);
end;
if marketposition=1 and barssinceentry=1 then stop_price = lowest( L , 3);
if marketposition > 0 then
begin
sell next bar at stop_price stop;
sell next bar at entryprice +300 limit;
end;
end;
// short
if shorton = 1 then
begin
if condition2 and condition6 and condition4 and condition8 then
begin
sellshort next bar market;
//buy next bar at highest(H , 3) stop;
stop_price_short = highest( H , 3);
end;
if marketposition < 0 then
begin
buytocover next bar at stop_price_short stop;
buytocover next bar at entryprice -300 limit;
end;
end;
if marketposition=1 and marketposition=0 then stop_price=99999 ;
if marketposition=-1 and marketposition=0 then stop_price_short=0 ;
//if marketposition>0 then sell next bar at entryprice* (1-N1/100) stop ;
//if marketposition<0 then buytocover next bar at entryprice* (1+N2/100) stop ;
// moving profit stop
{inputs: nProfit(100),nPercentage(10);
if marketposition <> 0 then begin
value1 = (maxpositionprofit / currentcontracts /bigpointvalue);
if value1 >= nProfit then begin
sell("BX-PercenTrailing") next bar avgentryprice + value1 - value1*nPercentage/100 stop;
buytocover("SX-PercentTrailing") next bar avgentryprice -value1 + value1*nPercentage/100 stop;
end;
end;
}
if (DAYofMonth(Date)>14 and DAYofMonth(Date)<22 and DAYofWeek(Date)=3) then setexitonclose;
我想簡化問題,假設我設一個停損價如下
SELLSHORT NEXT BAR AT STOP_PRICE STOP;
但我這個STOP_PRICE不會每次計算,可能只計算一次,
比如類似
IF (CONDITION1 = 1 ) THEN STOP_PRICE =XXX;
那下次這個STP_PRICE是否會在下個K棒到時因為沒合乎CONDOTION1 所以沒有計算STOP_PRICE,造成停損單失效?? marketposition 變為 0 時 .程式不會平倉
謝謝分享.謝謝分享.謝謝分享.謝謝分享.
頁:
[1]