<<The code wants to shortly to duplicate the phenomenon, it decrease the range between entry and stop. But it's same on my larger real case>>
MC version: Multichart64 version 8.8 Release(Build 8967)
System:Windows 64 bit professional
CPU: i7-4770K (I had tried on the other i7-3820QM)
RAM: 32GB
HDD: 256 GB SSD RAID
abbreviation: ChartPosition= Position at chart / BrokerPosition= Position on Broker /BarEntry=BarsSinceEntry(0) or BarsSinceEntry(1)/ BarExit=BarsSinceExit
Code: Select all
//Program Purpose:
// 1.Duplicate the order out of control at stop order filled but MC generate/filled another entry order immediately
// 2.Duplicate the malfunction at "cross over" and "highest"
//Resolution: 1 tick
//Instrumnet: any, but pick a wide range vibration instrument can shortly test time
[IntrabarOrderGeneration = False];
Input:Xprice(0);
var:Stp(0),RecStp(True),TmpStp(0),CntDn(0),CntUp(1),NEntry(""),StartTrade(False),Xprice1(0);
once Xprice1=Xprice;
if getappinfo(aiStrategyAuto)=1 and getappinfo(aiRealTimeCalc)=1 then begin
if StartTrade then begin
// Stp=highest(high,Stp);
if high>=Stp[1] then Stp=high else Stp=Stp[1]; //it always got the wrong value while using function-highest in 1 tick resolution
if RecStp then begin
if low cross under Stp-3*(MinMove/PriceScale) then begin
TmpStp=Stp;
RecStp=False;
CntDn=CntDn+1;
print(DateToString(DateToJulian(Date))," ",TimeToString(ELTimeToDateTime(Time)),"/bar #", maxbarsback+currentbar:8:0,"/ChartPosition:",MarketPosition:1:1,"/BrokerPosition:",MarketPosition_at_Broker:1:1,"/close:",close,"/StartTrade:",StartTrade,"/RecStp:",RecStp,"/Xprice1:",Xprice1,"/Stp:",Stp,"/TmpStp:",TmpStp,"/Entry Order:",NEntry:1:1,"/CntUp:",CntUp:1:1,"/CntDn:",CntDn:1:1,"/BarEntry:",Barssinceentry(0):1:1,"/BarEntry:",Barssinceentry(1):1:1,"/BarExit:",barssinceexit(1):1:1,"+44444+");
end;
end else begin
if high>TmpStp then begin //if using "high cross over TmpStp" then it won't go into to caculate CntUp sometimes. "cross" has issue in 1 tick resolution.
RecStp=True;
CntUp=CntUp+1;
print(DateToString(DateToJulian(Date))," ",TimeToString(ELTimeToDateTime(Time)),"/bar #", maxbarsback+currentbar:8:0,"/ChartPosition:",MarketPosition:1:1,"/BrokerPosition:",MarketPosition_at_Broker:1:1,"/close:",close,"/StartTrade:",StartTrade,"/RecStp:",RecStp,"/Xprice1:",Xprice1,"/Stp:",Stp,"/TmpStp:",TmpStp,"/Entry Order:",NEntry:1:1,"/CntUp:",CntUp:1:1,"/CntDn:",CntDn:1:1,"/BarEntry:",Barssinceentry(0):1:1,"/BarEntry:",Barssinceentry(1):1:1,"/BarExit:",barssinceexit(1):1:1,"+555555+");
end;
end;
// below is key for screen the stop order and next entry, but no matter how you control the next entry oder it generated/filled coming along with the stop order "sometimes"
//11111111111111111111111111111111
// if CntDn=CntUp then begin
// NEntry="S"+NumToStr(CntDn,0);
// sellshort(NEntry) 1 contract next bar at Stp-4(MinMove/PriceScale) limit;
// end;
//11111111111111111111111111111111
//222222222222222222222222222222222222222222222222 //Another method to screen out duplicate order
if CntDn=CntUp and (barssinceexit(1)>10 or totaltrades=0) then begin
NEntry="S"+NumToStr(CntDn,0);
sellshort(NEntry) 1 contract next bar at Stp-2*(MinMove/PriceScale) limit;
print(DateToString(DateToJulian(Date))," ",TimeToString(ELTimeToDateTime(Time)),"/bar #", maxbarsback+currentbar:8:0,"/ChartPosition:",MarketPosition:1:1,"/BrokerPosition:",MarketPosition_at_Broker:1:1,"/close:",close,"/StartTrade:",StartTrade,"/RecStp:",RecStp,"/Xprice1:",Xprice1,"/Stp:",Stp,"/TmpStp:",TmpStp,"/Entry Order:",NEntry:1:1,"/CntUp:",CntUp:1:1,"/CntDn:",CntDn:1:1,"/BarEntry:",Barssinceentry(0):1:1,"/BarEntry:",Barssinceentry(1):1:1,"/BarExit:",barssinceexit(1):1:1,"+3333+");
end;
//222222222222222222222222222222222222222222222222
//333333333333333333333333333333333333333333333333333 //Another method to screen out duplicate order
// if CntDn=CntUp and (PosTradeExitBar(1,0)>10 or totaltrades=0) then begin
// NEntry="S"+NumToStr(CntDn,0);
// sellshort(NEntry) 1 contract next bar at Stp-4(MinMove/PriceScale) limit;
// end;
//333333333333333333333333333333333333333333333333333
end else if high cross over Xprice1 then begin
StartTrade=True;
print(DateToString(DateToJulian(Date))," ",TimeToString(ELTimeToDateTime(Time)),"/bar #", maxbarsback+currentbar:8:0,"/ChartPosition:",MarketPosition:1:1,"/BrokerPosition:",MarketPosition_at_Broker:1:1,"/close:",close,"/StartTrade:",StartTrade,"/RecStp:",RecStp,"/Xprice1:",Xprice1,"/Stp:",Stp,"/TmpStp:",TmpStp,"/Entry Order:",NEntry:1:1,"/CntUp:",CntUp:1:1,"/CntDn:",CntDn:1:1,"/BarEntry:",Barssinceentry(0):1:1,"/BarEntry:",Barssinceentry(1):1:1,"/BarExit:",barssinceexit(1):1:1,"+222+");
end;
buytocover(NEntry+"X") all contract next bar at TmpStp+(MinMove/PriceScale) stop TmpStp+10*(MinMove/PriceScale) limit; //STOP order!!!!
buytocover(NEntry+"O") all contract next bar at TmpStp-25*(MinMove/PriceScale) limit; //Take Profit!!!
if low cross under TmpStp-30*(MinMove/PriceScale) then begin
Xprice1=high+10*(MinMove/PriceScale); //for repeat test
StartTrade=False; CntDn=0; Stp=0; CntUp=1; RecStp=True; NEntry="";
end;
print(DateToString(DateToJulian(Date))," ",TimeToString(ELTimeToDateTime(Time)),"/bar #", maxbarsback+currentbar:8:0,"/ChartPosition:",MarketPosition:1:1,"/BrokerPosition:",MarketPosition_at_Broker:1:1,"/close:",close,"/StartTrade:",StartTrade,"/RecStp:",RecStp,"/Xprice1:",Xprice1,"/Stp:",Stp,"/TmpStp:",TmpStp,"/Entry Order:",NEntry:1:1,"/CntUp:",CntUp:1:1,"/CntDn:",CntDn:1:1,"/BarEntry:",Barssinceentry(0):1:1,"/BarEntry:",Barssinceentry(1):1:1,"/BarExit:",barssinceexit(1):1:1,"+11+");
end;
2014/6/12 06:28:00/bar # 16924/ChartPosition:-1.0/BrokerPosition:-1.0/close: 106.15/StartTrade:TRUE/RecStp:FALSE/Xprice1: 106.13/Stp: 106.15/TmpStp: 106.15/Entry Order:S1/CntUp:1.0/CntDn:1.0/BarEntry:63.0/BarEntry:4202.0/BarExit:1739.0+3333+
2014/6/12 06:28:00/bar # 16924/ChartPosition:-1.0/BrokerPosition:-1.0/close: 106.15/StartTrade:TRUE/RecStp:FALSE/Xprice1: 106.13/Stp: 106.15/TmpStp: 106.15/Entry Order:S1/CntUp:1.0/CntDn:1.0/BarEntry:63.0/BarEntry:4202.0/BarExit:1739.0+11+
2014/6/12 06:28:00/bar # 16925/ChartPosition:-1.0/BrokerPosition:-1.0/close: 106.15/StartTrade:TRUE/RecStp:FALSE/Xprice1: 106.13/Stp: 106.15/TmpStp: 106.15/Entry Order:S1/CntUp:1.0/CntDn:1.0/BarEntry:64.0/BarEntry:4203.0/BarExit:1740.0+3333+
2014/6/12 06:28:00/bar # 16925/ChartPosition:-1.0/BrokerPosition:-1.0/close: 106.15/StartTrade:TRUE/RecStp:FALSE/Xprice1: 106.13/Stp: 106.15/TmpStp: 106.15/Entry Order:S1/CntUp:1.0/CntDn:1.0/BarEntry:64.0/BarEntry:4203.0/BarExit:1740.0+11+
2014/6/12 06:28:00/bar # 16926/ChartPosition:-1.0/BrokerPosition:-1.0/close: 106.15/StartTrade:TRUE/RecStp:FALSE/Xprice1: 106.13/Stp: 106.15/TmpStp: 106.15/Entry Order:S1/CntUp:1.0/CntDn:1.0/BarEntry:65.0/BarEntry:4204.0/BarExit:1741.0+3333+
2014/6/12 06:28:00/bar # 16926/ChartPosition:-1.0/BrokerPosition:-1.0/close: 106.15/StartTrade:TRUE/RecStp:FALSE/Xprice1: 106.13/Stp: 106.15/TmpStp: 106.15/Entry Order:S1/CntUp:1.0/CntDn:1.0/BarEntry:65.0/BarEntry:4204.0/BarExit:1741.0+11+
2014/6/12 06:28:00/bar # 16927/ChartPosition:-1.0/BrokerPosition:-1.0/close: 106.16/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:0.0/BarEntry:66.0/BarExit:0.0+555555+
2014/6/12 06:28:00/bar # 16927/ChartPosition:-1.0/BrokerPosition:-1.0/close: 106.16/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:0.0/BarEntry:66.0/BarExit:0.0+11+
2014/6/12 06:28:00/bar # 16927/ChartPosition:-1.0/BrokerPosition:-1.0/close: 106.16/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:0.0/BarEntry:66.0/BarExit:0.0+11+
2014/6/12 06:28:00/bar # 16928/ChartPosition:-1.0/BrokerPosition:0.0/close: 106.14/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:1.0/BarEntry:67.0/BarExit:1.0+11+
2014/6/12 06:28:00/bar # 16929/ChartPosition:-1.0/BrokerPosition:0.0/close: 106.15/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:2.0/BarEntry:68.0/BarExit:2.0+11+
2014/6/12 06:29:00/bar # 16930/ChartPosition:-1.0/BrokerPosition:0.0/close: 106.15/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:3.0/BarEntry:69.0/BarExit:3.0+11+
2014/6/12 06:29:00/bar # 16931/ChartPosition:-1.0/BrokerPosition:0.0/close: 106.15/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:4.0/BarEntry:70.0/BarExit:4.0+11+
2014/6/12 06:29:00/bar # 16932/ChartPosition:-1.0/BrokerPosition:0.0/close: 106.15/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:5.0/BarEntry:71.0/BarExit:5.0+11+
2014/6/12 06:29:00/bar # 16933/ChartPosition:-1.0/BrokerPosition:0.0/close: 106.15/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:6.0/BarEntry:72.0/BarExit:6.0+11+
2014/6/12 06:29:00/bar # 16934/ChartPosition:-1.0/BrokerPosition:0.0/close: 106.15/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:7.0/BarEntry:73.0/BarExit:7.0+11+
2014/6/12 06:29:00/bar # 16935/ChartPosition:-1.0/BrokerPosition:0.0/close: 106.15/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:8.0/BarEntry:74.0/BarExit:8.0+11+
2014/6/12 06:29:00/bar # 16936/ChartPosition:-1.0/BrokerPosition:0.0/close: 106.15/StartTrade:TRUE/RecStp:TRUE/Xprice1: 106.13/Stp: 106.16/TmpStp: 106.15/Entry Order:S1/CntUp:2.0/CntDn:1.0/BarEntry:9.0/BarEntry:75.0/BarExit:9.0+11+