交易开拓者止损止盈
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
TB源码:
Params
Numeric Length1(10); //短均线周期
Numeric Length2(20); //长均线周期
Numeric InitialStop(20); //初始止损比例*1000
Numeric BreakEvenStop(30); //保本止损比例*1000
Numeric TrailingStop(50); //追踪止损比例*1000
{
//初始止损
StopLine = EntryPrice * (1+InitialStop/1000);
//达到保本止损条件,将止损位下移到保本的价位
If (LowerAfterEntry <= EntryPrice *(1-BreakEvenStop/1000))
StopLine = EntryPrice;
//止损触发
If(High >= StopLine)
{
MyPrice = StopLine;
If(Open > MyPrice) MyPrice = Open;
BuyToCover(Lots,MyPrice);
{
MyPrice = Loቤተ መጻሕፍቲ ባይዱerAfterEntry - MinPoint;
If(Open < MyPrice) MyPrice = Open;
SellShort(Lots,MyPrice);
bShortStoped = False;
LowerAfterEntry = MyPrice;
Commentary("SellShort ReEntry at "+text(MyPrice));
Commentary(" LAE="+text(LowerAfterEntry));
Commentary("bShortStoped="+iifstring(bShortStoped,"true","false"));
}
//空头再次入场,必须跌破前次出场前的低点
If(bShortStoped and MarketPosition==0 and condSell[1]==true and Low < LowerAfterEntry)
PlotNumeric("MA1",MA1);
PlotNumeric("MA2",MA2);
//计算是否出现了金叉死叉
condBuy = CrossOver(MA1,MA2);
condSell = CrossUnder(MA1,MA2);
//如果当前bar没有发生交叉,则将前一个Bar的交叉状态传递下去
{
bShortStoped = bShortStoped[1];
}
Commentary("bShortStoped="+IIFString(bShortStoped,"true","false"));
//传递或比较盈利峰值价
If(BarsSinceEntry >= 1)
{
LowerAfterEntry = Min(LowerAfterEntry[1],Low[1]);
If (MarketPosition!=-1 and condSell[1]==true and bShortStoped==false)
{
SellShort(lots,Open);
LowerAfterEntry = Open;
bShortStoped = false;
Commentary("SellShort Firsttime at "+text(Open));
Commentary(" LAE="+text(LowerAfterEntry));
Commentary("bShortStoped="+iifstring(bShortStoped,"true","false"));
Return; //再次入场,开仓bar不平仓
}
//止损部分
If(MarketPosition==-1) //持空
Numeric Lots(1); //头寸大小
Vars
NumericSeries MA1;
NumericSeries MA2;
BoolSeries condBuy(false); //做多条件
BoolSeries condSell(false); //做空条件
Numeric MinPoint;
Numeric MyPrice;
NumericSeries LowerAfterEntry; //空头盈利峰值价
BoolSeries bShortStoped(false); //当前均线空头趋势下是否有过一次进场
Numeric StopLine(0);
Begin
//把上一根bar的出场状况传递过来
if (BarStatus > 0)
If(BarType==0 && CurrentTime<=0.09 && high==low) return;
MinPoint = MinMove * PriceScale;
MA1 = AverageFC(Close,Length1);
MA2 = AverageFC(Close,Length2);
//追踪止损的价位低于保本止损价,止损价随盈利峰值价的下跌同步下移
If (StopLine > LowerAfterEntry*(1+TrailingStop/1000))
StopLine = LowerAfterEntry*(1+TrailingStop/1000);
Commentary("空头止损价:"+Text(StopLine));
if ( condBuy == false and condSell == false )
{
condBuy = condBuy[1];
condSell = condSell[1];
}
commentary("ctrue","false"));
Commentary("ctrue","false"));
//空头初次入场
}
Else
{
LowerAfterEntry = LowerAfterEntry[1];
}
Commentary("LowerAfterEntry="+Text(LowerAfterEntry));
//过滤集合竞价
If((BarType==1 or BarType==2) && date!=date[1] && high==low) return;
Params
Numeric Length1(10); //短均线周期
Numeric Length2(20); //长均线周期
Numeric InitialStop(20); //初始止损比例*1000
Numeric BreakEvenStop(30); //保本止损比例*1000
Numeric TrailingStop(50); //追踪止损比例*1000
{
//初始止损
StopLine = EntryPrice * (1+InitialStop/1000);
//达到保本止损条件,将止损位下移到保本的价位
If (LowerAfterEntry <= EntryPrice *(1-BreakEvenStop/1000))
StopLine = EntryPrice;
//止损触发
If(High >= StopLine)
{
MyPrice = StopLine;
If(Open > MyPrice) MyPrice = Open;
BuyToCover(Lots,MyPrice);
{
MyPrice = Loቤተ መጻሕፍቲ ባይዱerAfterEntry - MinPoint;
If(Open < MyPrice) MyPrice = Open;
SellShort(Lots,MyPrice);
bShortStoped = False;
LowerAfterEntry = MyPrice;
Commentary("SellShort ReEntry at "+text(MyPrice));
Commentary(" LAE="+text(LowerAfterEntry));
Commentary("bShortStoped="+iifstring(bShortStoped,"true","false"));
}
//空头再次入场,必须跌破前次出场前的低点
If(bShortStoped and MarketPosition==0 and condSell[1]==true and Low < LowerAfterEntry)
PlotNumeric("MA1",MA1);
PlotNumeric("MA2",MA2);
//计算是否出现了金叉死叉
condBuy = CrossOver(MA1,MA2);
condSell = CrossUnder(MA1,MA2);
//如果当前bar没有发生交叉,则将前一个Bar的交叉状态传递下去
{
bShortStoped = bShortStoped[1];
}
Commentary("bShortStoped="+IIFString(bShortStoped,"true","false"));
//传递或比较盈利峰值价
If(BarsSinceEntry >= 1)
{
LowerAfterEntry = Min(LowerAfterEntry[1],Low[1]);
If (MarketPosition!=-1 and condSell[1]==true and bShortStoped==false)
{
SellShort(lots,Open);
LowerAfterEntry = Open;
bShortStoped = false;
Commentary("SellShort Firsttime at "+text(Open));
Commentary(" LAE="+text(LowerAfterEntry));
Commentary("bShortStoped="+iifstring(bShortStoped,"true","false"));
Return; //再次入场,开仓bar不平仓
}
//止损部分
If(MarketPosition==-1) //持空
Numeric Lots(1); //头寸大小
Vars
NumericSeries MA1;
NumericSeries MA2;
BoolSeries condBuy(false); //做多条件
BoolSeries condSell(false); //做空条件
Numeric MinPoint;
Numeric MyPrice;
NumericSeries LowerAfterEntry; //空头盈利峰值价
BoolSeries bShortStoped(false); //当前均线空头趋势下是否有过一次进场
Numeric StopLine(0);
Begin
//把上一根bar的出场状况传递过来
if (BarStatus > 0)
If(BarType==0 && CurrentTime<=0.09 && high==low) return;
MinPoint = MinMove * PriceScale;
MA1 = AverageFC(Close,Length1);
MA2 = AverageFC(Close,Length2);
//追踪止损的价位低于保本止损价,止损价随盈利峰值价的下跌同步下移
If (StopLine > LowerAfterEntry*(1+TrailingStop/1000))
StopLine = LowerAfterEntry*(1+TrailingStop/1000);
Commentary("空头止损价:"+Text(StopLine));
if ( condBuy == false and condSell == false )
{
condBuy = condBuy[1];
condSell = condSell[1];
}
commentary("ctrue","false"));
Commentary("ctrue","false"));
//空头初次入场
}
Else
{
LowerAfterEntry = LowerAfterEntry[1];
}
Commentary("LowerAfterEntry="+Text(LowerAfterEntry));
//过滤集合竞价
If((BarType==1 or BarType==2) && date!=date[1] && high==low) return;