- 精华
- 0
- 在线时间
- 1 小时
- UID
- 277935
- 积分
- 2
- 帖子
- 1
- 阅读权限
- 10
- 注册时间
- 2019-4-16
- 最后登录
- 1970-1-1
- 精华
- 0
- UID
- 277935
- 积分
- 2
- 帖子
- 1
- 主题
- 1
- 阅读权限
- 10
- 注册时间
- 2019-4-16
- 最后登录
- 1970-1-1
|
Params
Numeric Length1(5);
Numeric Length2(20);
Numeric Lots(1);
Numeric ATRLength(20);
Numeric TrailStop(2);
Vars
NumericSeries MA1;
NumericSeries MA2;
NumericSeries ATRValue;
NumericSeries HiAfterEntry;
NumericSeries LoAfterEntry;
Numeric Stopline;
BoolSeries bLongStoped(false);
BoolSeries bShortStoped(false);
Begin
ATRValue = AvgTrueRange(ATRLength);
MA1 = AverageFC(Close,Length1);
MA2 = AverageFC(Close,Length2);
PlotNumeric("MA1",MA1);
PlotNumeric("MA2",MA2);
If (!bLongStoped and MarketPosition <> 1 and MA1[1] > MA2[1])
{
Buy(Lots,Open);
bShortStoped = false;
}
If (!bShortStoped and MarketPosition <> -1 and MA1[1] < MA2[1])
{
SellShort(lots,Open);
SellShort(lots,Open);
}
If (bLongStoped and MarketPosition <> 1 and High >= HiAfterEntry)
{
Buy(Lots, Max(Open, HiAfterEntry));
bShortStoped = false;
}
If (MarketPosition == 1 and BarsSinceEntry == 0) HiAfterEntry = High;
If (MarketPosition == 1 and BarsSinceEntry >= 1)
HiAfterEntry = Max(HiAfterEntry,High);
If (MarketPosition == -1 and BarsSinceEntry == 0) LoAfterEntry = Low;
If (MarketPosition == -1 and BarsSinceEntry >= 1)
LoAfterEntry = Min(LoAfterEntry,Low);
if (BarssinceEntry > 0 and MarketPosition == 1)
{
StopLine = HiAfterEntry[1] - TrailStop * ATRValue[1];
If (Low <= StopLine)
{
Sell(0, Min(Open, Stopline));
bLongStoped = true;
}
} Else If(BarsSinceEntry > 0 and MarketPosition == -1)
{
StopLine = LoAfterEntry[1] + TrailStop * ATRValue[1];
If(High >= StopLine)
{
BuyToCover(0, Max(Open, Stopline));
bShortStoped = true;
}
}
End
|
|