首页 > > 详细

代做公式选股、指标公式代做、代写股票选股公式、开拓者左右互博 日内随机交易策略源码



开拓者左右互博 日内随机交易策略源码
//------------------------------------------------------------------------
// 简称: LeftRightTrading
// 名称: LeftRightTrading
// 类别: 公式应用
// 类型: 用户应用
//------------------------------------------------------------------------
Params
Bool bInitStatus(False);
Numeric InitMyRealMP(0);
Numeric InitPreMyRealMP(0);
Numeric FirstGrid(5);
Numeric TotalGrids(10);
Numeric GridInterval(5);
Numeric WinGrid(5);
Numeric EveryLots(1);
Numeric OffSet(1);

Numeric StyleChangeGrid(3);
Bool ProgramTest(False);
//是否测试 True 是 False 实盘

Vars
NumericSeries MidLine;
Numeric MinPoint;
Numeric AskLine;
Numeric BidLine;
Numeric RealMidLine;
Numeric MyRealMP(0);
Numeric TmpGridIndex;
Numeric qcbz;
Bool TradeTime;
Numeric TmpLots;
Numeric PreRealMidLine;
Numeric PreMyRealMP;
Numeric MyBuyPosition;
Numeric MySellPosition;
Numeric EndTime;
Bool bJudgeTime;

Numeric ExitOnCloseMins(14.58);

//Debug
String FilePath;

Begin
If((Weekday()!=5)(Weekday()!=6)(Weekday()!=7)){EndTime=0.151500;
ExitOnCloseMins=15.13;
}
If(Weekday()==5){EndTime=0.150000;
ExitOnCloseMins=14.58;
}
If(!ProgramTest)TradeTime=(Q_LastTime>=0.091500 And CurrentTime>0.091500 And CurrentTime0.130000 And CurrentTime0.091500 And CurrentTime0.130000 And CurrentTime0)MyRealMP=A_BuyPosition;
//Else If(A_SellPosition>0)MyRealMP=-1*A_SellPosition;
//Else MyRealMP=InitMyRealMP;
MyRealMP=InitMyRealMP;
PreMyRealMP=InitPreMyRealMP;

}

If((Weekday()!=5)(Weekday()!=6)(Weekday()!=7))
bJudgeTime=(Time==0.091500 Or Time==0.092500 Or Time==0.093500 Or Time==0.094500 Or Time==0.095500 Or Time==0.100500 Or Time==0.101500 Or Time==0.102500 Or Time==0.103500 Or Time==0.104500 Or Time==0.105500 Or Time==0.110500 Or Time==0.111500 Or Time==0.112500 Or Time==0.130000Or Time==0.131000Or Time==0.132000Or Time==0.133000 Or Time==0.134000 Or Time==0.135000 Or Time==0.140000 Or Time==0.141000 Or Time==0.142000 Or Time==0.14300 Or Time==0.144000 Or Time==0.145000 Or Time==0.150000 Or Time==0.151000);
If(Weekday()==5)
bJudgeTime=(Time==0.091500 Or Time==0.092500 Or Time==0.093500 Or Time==0.094500 Or Time==0.095500 Or Time==0.100500 Or Time==0.101500 Or Time==0.102500 Or Time==0.103500 Or Time==0.104500 Or Time==0.105500 Or Time==0.110500 Or Time==0.111500 Or Time==0.112500 Or Time==0.130000Or Time==0.131000Or Time==0.132000Or Time==0.133000 Or Time==0.134000 Or Time==0.135000 Or Time==0.140000 Or Time==0.141000 Or Time==0.142000 Or Time==0.14300 Or Time==0.144000 Or Time==0.145000);
If(bJudgeTime)
{
MidLine=Open;
PreRealMidLine=MidLine[1];
}
Else
{
MidLine=MidLine[1];
}
RealMidLine=MidLine;
MinPoint=MinMove*PriceScale;
If(!ProgramTest)AskLine=Q_AskPrice;
Else AskLine=High;
If(!ProgramTest)BidLine=Q_BidPrice;
Else BidLine=Low;
If(!ProgramTest)MyBuyPosition=A_BuyPosition;
If(!ProgramTest)MySellPosition=A_SellPosition;


If(BarStatus==2 A_AccountID!="" TradeTime)
{
If(Q_AskPrice0 And MyRealMP>0 And A_SellProfitLoss>0)
{
TmpLots=MySellPosition;
A_SendOrder(Enum_Buy,Enum_Exit,TmpLots,Q_AskPrice+OffSet*MinPoint);
If(PreMyRealMP>0)MyRealMP=MyRealMP+PreMyRealMP-IntPart(TmpLots/EveryLots);
Else If (PreMyRealMP0)MyRealMP=MyRealMP-IntPart(TmpLots/EveryLots);
MySellPosition=MySellPosition-TmpLots;
}
If(MyBuyPosition>0 And MyRealMP0)
{
TmpLots=MyBuyPosition;
A_SendOrder(Enum_Sell,Enum_Exit,TmpLots,Q_BidPrice-OffSet*MinPoint);
If(PreMyRealMP=0)MyRealMP=MyRealMP+IntPart(TmpLots/EveryLots);
MyBuyPosition=MyBuyPosition-TmpLots;
} //
If(MySellPosition>0 And PreMyRealMP>0)
{
TmpLots=Min(MySellPosition,PreMyRealMP*EveryLots);
A_SendOrder(Enum_Buy,Enum_Exit,TmpLots,Q_AskPrice+OffSet*MinPoint);
MyRealMP=MyRealMP+PreMyRealMP-IntPart(TmpLots/EveryLots);
MySellPosition=MySellPosition-TmpLots;
}
If(MyBuyPosition>0 And PreMyRealMP0 And PreMyRealMP>0)
{
TmpGridIndex=Abs(BidLine-PreRealMidLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex1="+Text(TmpGridIndex));
If(TmpGridIndex>=StyleChangeGrid+1 And AskLine>PreRealMidLine+FirstGrid*MinPoint)
{
TmpLots=Min(MySellPosition,PreMyRealMP*EveryLots);
A_SendOrder(Enum_Buy,Enum_Exit,TmpLots,Q_AskPrice+OffSet*MinPoint);
PreMyRealMP=PreMyRealMP-IntPart(TmpLots/EveryLots);
}
TmpGridIndex=Abs(PreRealMidLine-AskLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex2="+Text(TmpGridIndex));
If(TmpGridIndex0 And PreMyRealMPPreRealMidLine+FirstGrid*MinPoint)
{
TmpLots=Min(MyBuyPosition,-1*PreMyRealMP*EveryLots);
A_SendOrder(Enum_Sell,Enum_Exit,TmpLots,Q_BidPrice-OffSet*MinPoint);
PreMyRealMP=PreMyRealMP+IntPart(TmpLots/EveryLots);
}
TmpGridIndex=Abs(PreRealMidLine-AskLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex4="+Text(TmpGridIndex));
If(TmpGridIndex>=StyleChangeGrid And BidLine0 And AskLine>PreRealMidLine-FirstGrid*MinPoint And MySellPosition>0 )
{
TmpGridIndex=Abs(AskLine-PreRealMidLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex5="+Text(TmpGridIndex));
If(TmpGridIndex0 )
{
TmpGridIndex=Abs(PreMyRealMP-BidLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex6="+Text(TmpGridIndex));
If(-1*TmpGridIndex>=PreMyRealMP+1 And TmpGridIndexPreRealMidLine+FirstGrid*MinPoint And MyBuyPosition>0 )
{
TmpGridIndex=Abs(BidLine-MinPoint-PreRealMidLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex7="+Text(TmpGridIndex));
If(TmpGridIndex=StyleChangeGrid)
{
PreMyRealMP=PreMyRealMP+1;
A_SendOrder(Enum_Sell,Enum_Exit,EveryLots,Q_BidPrice-OffSet*MinPoint);
}
}
Else If(PreMyRealMP>0 And AskLine0 )
{
TmpGridIndex=Abs(PreMyRealMP-AskLine+MinPoint)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex8="+Text(TmpGridIndex));
If(TmpGridIndex>=PreMyRealMP-1 And TmpGridIndex>=StyleChangeGrid)
{
PreMyRealMP=PreMyRealMP-1;
A_SendOrder(Enum_Buy,Enum_Exit,EveryLots,Q_AskPrice+OffSet*MinPoint);
}
}

If(MySellPosition>0 And MyRealMP>0)
{
TmpGridIndex=Abs(BidLine-RealMidLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex9="+Text(TmpGridIndex));
If(TmpGridIndex>=StyleChangeGrid+1 And AskLine>RealMidLine+FirstGrid*MinPoint)
{
TmpLots=Min(MySellPosition,MyRealMP*EveryLots);
A_SendOrder(Enum_Buy,Enum_Exit,TmpLots,Q_AskPrice+OffSet*MinPoint);
MyRealMP=MyRealMP-IntPart(TmpLots/EveryLots);
}
TmpGridIndex=Abs(RealMidLine-AskLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex10="+Text(TmpGridIndex));
If(TmpGridIndex0 And MyRealMPRealMidLine+FirstGrid*MinPoint)
{
TmpLots=Min(MyBuyPosition,-1*MyRealMP*EveryLots);
A_SendOrder(Enum_Sell,Enum_Exit,TmpLots,Q_BidPrice-OffSet*MinPoint);
MyRealMP=MyRealMP+IntPart(TmpLots/EveryLots);
}
TmpGridIndex=Abs(RealMidLine-AskLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex12="+Text(TmpGridIndex));
If(TmpGridIndex>=StyleChangeGrid+1 And BidLine0 And AskLine>RealMidLine-FirstGrid*MinPoint And MySellPosition>0)
{
TmpGridIndex=Abs(AskLine-RealMidLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex13="+Text(TmpGridIndex));
If(TmpGridIndex0)
{
TmpGridIndex=Abs(RealMidLine-BidLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex14="+Text(TmpGridIndex));
If(-1*TmpGridIndex>=MyRealMP+1 And TmpGridIndex0 And AskLine0)
{
TmpGridIndex=Abs(RealMidLine-AskLine+MinPoint)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex15="+Text(TmpGridIndex));
If(TmpGridIndex=StyleChangeGrid)
{
MyRealMP=MyRealMP-1;
A_SendOrder(Enum_Buy,Enum_Exit,TmpLots,Q_AskPrice+OffSet*MinPoint);
MyRealMP=MyRealMP-IntPart(TmpLots/EveryLots);
}
}
Else If(MyRealMPRealMidLine+FirstGrid*MinPoint And MyBuyPosition>0)
{
TmpGridIndex=Abs(BidLine-MinPoint-RealMidLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex16="+Text(TmpGridIndex));
If(TmpGridIndex=StyleChangeGrid)
{
MyRealMP=MyRealMP+1;
A_SendOrder(Enum_Sell,Enum_Exit,TmpLots,Q_BidPrice-OffSet*MinPoint);
}
}

//**********************************************************
//FileAppend(FilePath,"Excute***!"+", MyRealMP="+Text(MyRealMP)+", BidLine="+Text(BidLine)+", RealMidLine="+Text(RealMidLine)+", FirstGrid="+Text(FirstGrid)+", MinPoint="+Text(MinPoint)+", AskLine="+Text(AskLine)+", TmpGridIndex="+Text(TmpGridIndex));
If(MyRealMP>=0 And BidLine>=RealMidLine+FirstGrid*MinPoint)
{
TmpGridIndex=Abs(BidLine-RealMidLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex17="+Text(TmpGridIndex)+"MyRealMP="+Text(MyRealMP)+"TotalGrids="+Text(TotalGrids)+"StyleChangeGrid="+Text(StyleChangeGrid));
If(TmpGridIndex>=MyRealMP+1 And MyRealMP0)
{
FileAppend(FilePath, "TmpGridIndex18="+Text(TmpGridIndex)+"MyRealMP="+Text(MyRealMP)+"TotalGrids="+Text(TotalGrids)+"StyleChangeGrid="+Text(StyleChangeGrid));
TmpGridIndex=Abs(RealMidLine-AskLine)/(GridInterval*MinPoint);
If(TmpGridIndex>=-1*MyRealMP+1 And -1*MyRealMPRealMidLine+FirstGrid*MinPoint)
{
TmpGridIndex=Abs(BidLine-RealMidLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex19="+Text(TmpGridIndex)+"MyRealMP="+Text(MyRealMP)+"TotalGrids="+Text(TotalGrids)+"StyleChangeGrid="+Text(StyleChangeGrid));
If(TmpGridIndex>=-1*MyRealMP+1 And -1*MyRealMP=StyleChangeGrid)
{
MyRealMP=MyRealMP-1;
A_SendOrder(Enum_Buy,Enum_Entry,TmpLots,Q_AskPrice+OffSet*MinPoint);
MyRealMP=MyRealMP-IntPart(TmpLots/EveryLots);
}
}
Else If(MyRealMP>=0 And AskLine0)
{
TmpGridIndex=Abs(RealMidLine-AskLine)/(GridInterval*MinPoint);
FileAppend(FilePath,"TmpGridIndex20="+Text(TmpGridIndex)+"MyRealMP="+Text(MyRealMP)+"TotalGrids="+Text(TotalGrids)+"StyleChangeGrid="+Text(StyleChangeGrid));
If(TmpGridIndex>=MyRealMP+1 And MyRealMP=StyleChangeGrid+1)
{
MyRealMP=MyRealMP+1;
A_SendOrder(Enum_Sell,Enum_Entry,TmpLots,Q_BidPrice-OffSet*MinPoint);
}
}
//****************************************************************

}
Else If(CurrentTime>ExitOnCloseMins/100)
{
If(MySellPosition>0)
{
A_SendOrder(Enum_Buy,Enum_Exit,MySellPosition, Q_AskPrice+OffSet*MinPoint);
}
Else If(MyBuyPosition>0)
{
A_SendOrder(Enum_Sell,Enum_Exit,MyBuyPosition, Q_BidPrice-OffSet*MinPoint);
}
MyRealMP=0;
PreMyRealMP=0;
}
}
//Else FileAppend(FilePath,"Not Trading Time.***");

SetGlobalVar(0,MyRealMP);
SetGlobalVar(1,qcbz);
SetGlobalVar(2,PreRealMidLine);
SetGlobalVar(3,PreMyRealMP);
Commentary("本时段中线="+Text(RealMidLine));
Commentary("上时段中线="+Text(PreRealMidLine));
Commentary("本时段仓位="+Text(MyRealMP*EveryLots));
Commentary("上时段留仓="+Text(PreMyRealMP*EveryLots));
Commentary("当前时间="+TimeToString(CurrentTime));
Commentary("清仓标志="+Text(qcbz));

}
End

 

联系我们 - QQ: 88652583
© 2014 www.93stock.com
代写选股公式网!
声明:警惕假冒分子冒充本站提供证券咨询服务,选股公式网为非证券咨询机构,本站不提供有关股评、投资分析报告、股市预测,证券咨询等服务。本站仅提供股票、期货、黄金、外汇的软件技术交流与分享。本站文章为互联网文章,其仅供参考,并不构成投资建议。