Params
Numeric length1(30);//Ma参数
Numeric length3(100);//止盈参数
Numeric length4(50);//止损参数
Numeric lots(1);//交易量
Vars
Series<Numeric> Ma;//
Series<Bool> Condition;
Numeric MinPoint;//一个最小变动单位,也就是一跳
Series<Numeric> My_Entryprice;//开仓价格
Numeric TakeProfitSet(length3);//止盈设置
Numeric StopLossSet(length4);//止损设置
Numeric TakeProfitPrice;//止盈价格
Numeric StopLossPrice;//止损价格
Events
OnBar(ArrayRef<Integer> indexs)
{
MinPoint = MinMove * PriceScale;
Ma = AverageFC (Close,length1);
PlotNumeric ("Ma", Ma);
Condition = Close[1] > Ma And Close[2] < Ma And Close[3] < Ma And Close[4] < Ma;
If (MarketPosition != 1 And Condition)//如果开仓条件满足
{
Buy(lots,Open);//开盘价买入多单
My_Entryprice = Open;
TakeProfitPrice = My_Entryprice + TakeProfitSet * MinPoint;
StopLossPrice = My_Entryprice - StopLossSet * MinPoint;
Commentary("止盈价格=" + Text(TakeProfitPrice));
Commentary("止损价格=" + Text(StopLossPrice));
Commentary("距离入场=" + Text(BarsSinceEntry));
}
If (MarketPosition == 1 And Low <= StopLossPrice And BarsSinceEntry >= 1 )
{
Sell(lots,StopLossPrice);
Commentary("止损出场");
}Else If(MarketPosition == 1 And High >= TakeProfitPrice And BarsSinceEntry >= 1)
{
Sell(lots,TakeProfitPrice);
Commentary("止盈出场");
}
}
Numeric TakeProfitPrice;//止盈价格
Numeric StopLossPrice;//止损价格
换成
Series<Numeric> TakeProfitPrice;//止盈价格
Series<Numeric> StopLossPrice;//止损价格