Систему Dual Thrust придумал Mike Chalek. Это переворотная система, которая всегда в рынке, то в короткой позиции, то в длинной. Она очень хорошо захватывает безоткатные тренды различной продолжительности и никогда не пропустит их. Также она адаптивна к волатильности. Основное значение в этой системе придается цене открытия бара и от него уже ведется отсчет. То есть, до начала сессии ордер выставить невозможно, так как сначала надо узнать цену открытия сессии, если игра ведется на дневках. Если внутри дня, то надо дождаться открытия нового бара.
Сам автор системы ведет статистику на своем сайте и ведет торговлю по системе для платных подписчиков.
http://www.tradefutures.com
Результаты, если верить автору, на картинке. Это для большого портфеля фьючерсов. На верхней картинке результаты для каждого фьючерса по отдельности, а на нижней общая эквити.
Код системы в открытом виде разошелся по всему свету -- все знают условия, но мало кто может играть по ним. Правильно говорят, что сколько человек играют по одной системе столько будет разных результатов и у каждого он будет свой. Для данного случая этот тезис очень подходит. Это универсальная система, она годится для любого рынка, но под каждый ее надо адаптировать, так как она очень чувствительна к любому изменению характера графика. Не всем подходит и то обстоятельство что нельзя заранее выставить ордер -- надо ждать открытия сессии и уже после него рассчитывать уровни расстановки ордеров. А если еще инструментов играется много и каждый рассчитывать, то это вообще, большая нагрузка на организм, которую долго не выдержать.
Это код системы для Omega TradeStation 2000i
Inputs: K1(.5),K2(.5),Mday(1),Nday(1);
Vars: BuyRange(0), SellRange(0);
Vars: BuyTrig(0),SellTrig(0);
Vars: HH(0),LL(0),HC(0),LC(0);
If CurrentBar > 1 Then Begin
HH = Highest(High,Mday);
HC = Highest(Close,Mday);
LL = Lowest(Low,Mday);
LC = Lowest(Close,Mday);
If (HH - LC) >= (HC - LL) Then Begin
SellRange = HH - LC;
End Else Begin
SellRange = HC - LL;
End;
HH = Highest(High,Nday);
HC = Highest(Close,Nday);
LL = Lowest(Low,Nday);
LC = Lowest(Close,Nday);
If (HH - LC) >= (HC - LL) Then Begin
BuyRange = HH - LC;
End Else Begin
BuyRange = HC - LL;
End;
BuyTrig = K1*BuyRange;
SellTrig = K2*SellRange;
If MarketPosition = 0 Then Begin
Buy at Open of next bar + BuyTrig Stop;
Sell at Open of next bar - SellTrig Stop;
End;
If MarketPosition = -1 Then Begin
Buy at Open of next bar + Buytrig Stop;
End;
If MarketPosition = 1 Then Begin
Sell at Open of next bar - SellTrig Stop;
End;
End;
В системе есть четыре параметра для оптимизации. При желании можно использовать только два, если есть убеждение что для лонгов и шортов должны быть одинаковые условия. Если верите что лонги отличаются от шортов, то лучше для оптимизации использовать все четыре параметра.
Код для WealthLab4:
Код для Metatrader
Код для Amibroker
Код для TradeStation
Код для WealthLab 6
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
StrategyParameter MDayPar;
StrategyParameter NDayPar;
StrategyParameter K1Par;
StrategyParameter K2Par;
public MyStrategy()
{
MDayPar=CreateParameter("MDay", 5,1,10,1);
K1Par=CreateParameter("K1", 5,1,10,1);
NDayPar=CreateParameter("NDay", 5,1,10,1);
K2Par=CreateParameter("K2", 5,1,10,1);
}
protected override void Execute()
{
Position p;
double HH, HC, LL, LC, SellRange, BuyRange, BuyTrig, SellTrig;
bool bLongSAR=false;
int Mday,Nday;
double K1,K2;
Mday =MDayPar.ValueInt;
Nday = NDayPar.ValueInt;
K1 = (double)K1Par.ValueInt/10.0;
K2 = (double)K2Par.ValueInt/10.0;
for(int bar = 10; bar < Bars.Count; bar++)
{
HH = Highest.Series(High,Mday)[bar-1];
HC = Highest.Series(Close, Mday)[bar-1];
LL = Lowest.Series(Low, Mday)[bar-1];
LC = Lowest.Series(Close, Mday)[bar-1];
if ((HH - LC) >= (HC - LL))
SellRange = HH - LC;
else
SellRange = HC - LL;
HH = Highest.Series(High,Nday)[bar-1];
HC = Highest.Series(Close, Nday)[bar-1];
LL = Lowest.Series(Low, Nday)[bar-1];
LC = Lowest.Series(Close, Nday)[bar-1];
if ((HH - LC) >= (HC - LL))
BuyRange = HH - LC;
else
BuyRange = HC - LL;
BuyTrig = K1 * BuyRange;
SellTrig = K2 * SellRange;
if (IsLastPositionActive)
{
p = LastPosition;
bLongSAR =p.PositionType == PositionType.Long;// PositionLong( p );
if (p.PositionType == PositionType.Long)
SellAtStop( bar,p, Open[bar] - SellTrig, "");
if (p.PositionType == PositionType.Short)
CoverAtStop( bar,p, Open[bar] + BuyTrig, "");
}
else
{
//code your entry rules here
}
if (!bLongSAR)
BuyAtStop(bar, Open[bar] + BuyTrig, "");
if (bLongSAR)
ShortAtStop(bar, Open[bar] - SellTrig, "");
}
}
}
}
Сам автор системы ведет статистику на своем сайте и ведет торговлю по системе для платных подписчиков.
http://www.tradefutures.com
Результаты, если верить автору, на картинке. Это для большого портфеля фьючерсов. На верхней картинке результаты для каждого фьючерса по отдельности, а на нижней общая эквити.
Inputs: K1(.5),K2(.5),Mday(1),Nday(1);
Vars: BuyRange(0), SellRange(0);
Vars: BuyTrig(0),SellTrig(0);
Vars: HH(0),LL(0),HC(0),LC(0);
If CurrentBar > 1 Then Begin
HH = Highest(High,Mday);
HC = Highest(Close,Mday);
LL = Lowest(Low,Mday);
LC = Lowest(Close,Mday);
If (HH - LC) >= (HC - LL) Then Begin
SellRange = HH - LC;
End Else Begin
SellRange = HC - LL;
End;
HH = Highest(High,Nday);
HC = Highest(Close,Nday);
LL = Lowest(Low,Nday);
LC = Lowest(Close,Nday);
If (HH - LC) >= (HC - LL) Then Begin
BuyRange = HH - LC;
End Else Begin
BuyRange = HC - LL;
End;
BuyTrig = K1*BuyRange;
SellTrig = K2*SellRange;
If MarketPosition = 0 Then Begin
Buy at Open of next bar + BuyTrig Stop;
Sell at Open of next bar - SellTrig Stop;
End;
If MarketPosition = -1 Then Begin
Buy at Open of next bar + Buytrig Stop;
End;
If MarketPosition = 1 Then Begin
Sell at Open of next bar - SellTrig Stop;
End;
End;
{#OptVar1 1;1;10;1}
{#OptVar2 5;1;10;1}
{#OptVar3 1;1;10;1}
{#OptVar4 5;1;10;1}
var Bar, p, Mday, Nday, K1, K2: integer;
var HH, HC, LL, LC, SellRange, BuyRange, BuyTrig, SellTrig: float;
var bLongSAR: boolean;
Mday := #OptVar1;
Nday := #OptVar3;
K1 := #OptVar2/10;
K2 := #OptVar4/10;
for Bar := 10 to BarCount - 1 do
begin
HH := Highest(bar-1, #High, Mday);
HC := Highest(bar-1, #Close, Mday);
LL := Lowest(bar-1, #Low, Mday);
LC := Lowest(bar-1, #Close, Mday);
if (HH - LC) >= (HC - LL) then
SellRange := HH - LC
else
SellRange := HC - LL;
HH := Highest(bar-1, #High, Nday);
HC := Highest(bar-1, #Close, Nday);
LL := Lowest(bar-1, #Low, Nday);
LC := Lowest(bar-1, #Close, Nday);
if (HH - LC) >= (HC - LL) then
BuyRange := HH - LC
else
BuyRange := HC - LL;
BuyTrig := K1 * BuyRange;
SellTrig := K2 * SellRange;
if LastPositionActive then
begin
p := LastPosition;
bLongSAR := PositionLong( p );
if PositionLong( p ) then
begin
SellAtStop( Bar, PriceOpen(bar) - SellTrig, p, '');
end;
if PositionShort( p ) then
begin
CoverAtStop( Bar, PriceOpen(bar) + BuyTrig, p, '');
end;
end;
if not bLongSAR then
begin
BuyAtStop(bar, PriceOpen(bar) + BuyTrig, '');
end;
if bLongSAR then
begin
ShortAtStop(bar, PriceOpen(bar) - SellTrig, '');
end;
end;
{#OptVar2 5;1;10;1}
{#OptVar3 1;1;10;1}
{#OptVar4 5;1;10;1}
var Bar, p, Mday, Nday, K1, K2: integer;
var HH, HC, LL, LC, SellRange, BuyRange, BuyTrig, SellTrig: float;
var bLongSAR: boolean;
Mday := #OptVar1;
Nday := #OptVar3;
K1 := #OptVar2/10;
K2 := #OptVar4/10;
for Bar := 10 to BarCount - 1 do
begin
HH := Highest(bar-1, #High, Mday);
HC := Highest(bar-1, #Close, Mday);
LL := Lowest(bar-1, #Low, Mday);
LC := Lowest(bar-1, #Close, Mday);
if (HH - LC) >= (HC - LL) then
SellRange := HH - LC
else
SellRange := HC - LL;
HH := Highest(bar-1, #High, Nday);
HC := Highest(bar-1, #Close, Nday);
LL := Lowest(bar-1, #Low, Nday);
LC := Lowest(bar-1, #Close, Nday);
if (HH - LC) >= (HC - LL) then
BuyRange := HH - LC
else
BuyRange := HC - LL;
BuyTrig := K1 * BuyRange;
SellTrig := K2 * SellRange;
if LastPositionActive then
begin
p := LastPosition;
bLongSAR := PositionLong( p );
if PositionLong( p ) then
begin
SellAtStop( Bar, PriceOpen(bar) - SellTrig, p, '');
end;
if PositionShort( p ) then
begin
CoverAtStop( Bar, PriceOpen(bar) + BuyTrig, p, '');
end;
end;
if not bLongSAR then
begin
BuyAtStop(bar, PriceOpen(bar) + BuyTrig, '');
end;
if bLongSAR then
begin
ShortAtStop(bar, PriceOpen(bar) - SellTrig, '');
end;
end;
//+------------------------------------------------------------------+
//| dual trust .mq4 |
//| Copyright © 2009, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern double k = 1.1;
int g_ticket_84;
double trig;
bool gi_96;
void init() {
if (true) {
trig = k*MathMax(iHigh(NULL,PERIOD_D1,1)-iClose(NULL,PERIOD_D1,1),iClose(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1));
if (iClose(Symbol(), 0, 1) > (iOpen(NULL,PERIOD_D1,0)+trig)) {
gi_96 = TRUE;
g_ticket_84 = OrderSend(Symbol(), OP_BUY, 0.1, NormalizeDouble(Ask, Digits), 0, 0, 0, 0, 0, 0, Green);
} else {
if (iClose(Symbol(), 0, 1) < (iOpen(NULL,PERIOD_D1,0)-trig)) {
gi_96 = FALSE;
g_ticket_84 = OrderSend(Symbol(), OP_SELL, 0.1, NormalizeDouble(Bid, Digits), 0, 0, 0, 0, 0, 0, Green);
}
}
}
}
int start() {
if (gi_96 == FALSE) {
if (iClose(Symbol(), 0, 1) > (iOpen(NULL,PERIOD_D1,0)+trig)) {
gi_96 = TRUE;
closeAll();
g_ticket_84 = OrderSend(Symbol(), OP_BUY, 0.1, NormalizeDouble(Ask, Digits), 0, 0, 0, 0, 0, 0, Green);
}
} else {
if (iClose(Symbol(), 0, 1) < (iOpen(NULL,PERIOD_D1,0)-trig)) {
gi_96 = FALSE;
closeAll();
g_ticket_84 = OrderSend(Symbol(), OP_SELL, 0.1, NormalizeDouble(Bid, Digits), 0, 0, 0, 0, 0, 0, Red);
}
}
return (0);
}
void closeAll() {
while (OrdersTotal() > 0) {
OrderSelect(0, SELECT_BY_POS);
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 0, Blue);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 0, Blue);
}
}
//| dual trust .mq4 |
//| Copyright © 2009, MetaQuotes Software Corp. |
//| http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link "http://www.metaquotes.net"
extern double k = 1.1;
int g_ticket_84;
double trig;
bool gi_96;
void init() {
if (true) {
trig = k*MathMax(iHigh(NULL,PERIOD_D1,1)-iClose(NULL,PERIOD_D1,1),iClose(NULL,PERIOD_D1,1)-iLow(NULL,PERIOD_D1,1));
if (iClose(Symbol(), 0, 1) > (iOpen(NULL,PERIOD_D1,0)+trig)) {
gi_96 = TRUE;
g_ticket_84 = OrderSend(Symbol(), OP_BUY, 0.1, NormalizeDouble(Ask, Digits), 0, 0, 0, 0, 0, 0, Green);
} else {
if (iClose(Symbol(), 0, 1) < (iOpen(NULL,PERIOD_D1,0)-trig)) {
gi_96 = FALSE;
g_ticket_84 = OrderSend(Symbol(), OP_SELL, 0.1, NormalizeDouble(Bid, Digits), 0, 0, 0, 0, 0, 0, Green);
}
}
}
}
int start() {
if (gi_96 == FALSE) {
if (iClose(Symbol(), 0, 1) > (iOpen(NULL,PERIOD_D1,0)+trig)) {
gi_96 = TRUE;
closeAll();
g_ticket_84 = OrderSend(Symbol(), OP_BUY, 0.1, NormalizeDouble(Ask, Digits), 0, 0, 0, 0, 0, 0, Green);
}
} else {
if (iClose(Symbol(), 0, 1) < (iOpen(NULL,PERIOD_D1,0)-trig)) {
gi_96 = FALSE;
closeAll();
g_ticket_84 = OrderSend(Symbol(), OP_SELL, 0.1, NormalizeDouble(Bid, Digits), 0, 0, 0, 0, 0, 0, Red);
}
}
return (0);
}
void closeAll() {
while (OrdersTotal() > 0) {
OrderSelect(0, SELECT_BY_POS);
if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 0, Blue);
if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 0, Blue);
}
}
BDay=Optimize( "BDay", 1, 1, 16, 1 );
SDay=Optimize( "SDay", 1, 1, 16, 1 );
Kl=0.5;
HHb = HHV(Ref(High,-1),BDay);
HCb = HHV(Ref(Close,-1),BDay);
LLb = LLV(Ref(Low,-1),BDay);
LCb = LLV(Ref(Close,-1),BDay);
HHs = HHV(Ref(High,-1),SDay);
HCs = HHV(Ref(Close,-1),SDay);
LLs = LLV(Ref(Low,-1),SDay);
LCs = LLV(Ref(Close,-1),SDay);
BuyRange = IIf( (HHB - LCB) >= (HCB - LLB), HHB - LCB, HCB - LLB);
SellRange = IIf( (HHS - LCS) >= (HCS - LLS), HHS - LCS, HCS - LLS);
BuyTrig = Kl*BuyRange;
SellTrig = Kl*SellRange;
ColorCh0=colorLightGrey;
Band_Top=O+BuyTrig;
Band_Bot=O-SellTrig;
Plot(Band_Top, "Band_Top", ColorCh0, 1);
Plot(Band_Bot , "Band_Bot", ColorCh0, 1);
Buy = Cover = Cross(H,Band_Top); BuyPrice = CoverPrice = Band_Top;
Short = Sell = Cross(Band_Bot,L); ShortPrice = SellPrice = Band_Bot;
PlotShapes( (Buy == 1) * shapeHollowUpArrow, colorBrightGreen, 0,BuyPrice);
PlotShapes( (Buy == sigScaleIn ) * shapeSmallUpTriangle, colorBrightGreen, 0,BuyPrice,1);
PlotShapes( (Buy == sigScaleOut) * shapeSmallDownTriangle, colorBrightGreen, 0,BuyPrice,1);
PlotShapes( (Short == 1) * shapeHollowDownArrow, colorRed, 0, ShortPrice);
PlotShapes( (Short == sigScaleIn ) * shapeSmallDownTriangle, colorRed, 0,ShortPrice,1);
PlotShapes( (Short == sigScaleOut ) * shapeSmallUpTriangle, colorRed, 0, ShortPrice,1);
PlotShapes( (Sell== 1) * shapeHollowDownArrow, colorBlue, 0,SellPrice);
PlotShapes( (Sell == 2) * shapeSmallCircle, colorBlue, 0,SellPrice,0);// stop
PlotShapes( (Sell == 5) * shapeSmallCircle, colorLightBlue, 0,SellPrice,0);// stop
PlotShapes( (Sell == 3) * shapeSquare, colorBlue, 0, SellPrice,0);// profit
PlotShapes( (Cover == 1) * shapeHollowUpArrow, colorOrange, 0, CoverPrice);
PlotShapes( (Cover == 2) * shapeSmallCircle, colorOrange, 0, CoverPrice,0);// stop
PlotShapes( (Cover == 3) * shapeSquare, colorOrange, 0,CoverPrice);// limit
PlotShapes( (Cover == 5) * shapeSmallCircle, colorLightOrange, 0,CoverPrice,0);// limit
SDay=Optimize( "SDay", 1, 1, 16, 1 );
Kl=0.5;
HHb = HHV(Ref(High,-1),BDay);
HCb = HHV(Ref(Close,-1),BDay);
LLb = LLV(Ref(Low,-1),BDay);
LCb = LLV(Ref(Close,-1),BDay);
HHs = HHV(Ref(High,-1),SDay);
HCs = HHV(Ref(Close,-1),SDay);
LLs = LLV(Ref(Low,-1),SDay);
LCs = LLV(Ref(Close,-1),SDay);
BuyRange = IIf( (HHB - LCB) >= (HCB - LLB), HHB - LCB, HCB - LLB);
SellRange = IIf( (HHS - LCS) >= (HCS - LLS), HHS - LCS, HCS - LLS);
BuyTrig = Kl*BuyRange;
SellTrig = Kl*SellRange;
ColorCh0=colorLightGrey;
Band_Top=O+BuyTrig;
Band_Bot=O-SellTrig;
Plot(Band_Top, "Band_Top", ColorCh0, 1);
Plot(Band_Bot , "Band_Bot", ColorCh0, 1);
Buy = Cover = Cross(H,Band_Top); BuyPrice = CoverPrice = Band_Top;
Short = Sell = Cross(Band_Bot,L); ShortPrice = SellPrice = Band_Bot;
PlotShapes( (Buy == 1) * shapeHollowUpArrow, colorBrightGreen, 0,BuyPrice);
PlotShapes( (Buy == sigScaleIn ) * shapeSmallUpTriangle, colorBrightGreen, 0,BuyPrice,1);
PlotShapes( (Buy == sigScaleOut) * shapeSmallDownTriangle, colorBrightGreen, 0,BuyPrice,1);
PlotShapes( (Short == 1) * shapeHollowDownArrow, colorRed, 0, ShortPrice);
PlotShapes( (Short == sigScaleIn ) * shapeSmallDownTriangle, colorRed, 0,ShortPrice,1);
PlotShapes( (Short == sigScaleOut ) * shapeSmallUpTriangle, colorRed, 0, ShortPrice,1);
PlotShapes( (Sell== 1) * shapeHollowDownArrow, colorBlue, 0,SellPrice);
PlotShapes( (Sell == 2) * shapeSmallCircle, colorBlue, 0,SellPrice,0);// stop
PlotShapes( (Sell == 5) * shapeSmallCircle, colorLightBlue, 0,SellPrice,0);// stop
PlotShapes( (Sell == 3) * shapeSquare, colorBlue, 0, SellPrice,0);// profit
PlotShapes( (Cover == 1) * shapeHollowUpArrow, colorOrange, 0, CoverPrice);
PlotShapes( (Cover == 2) * shapeSmallCircle, colorOrange, 0, CoverPrice,0);// stop
PlotShapes( (Cover == 3) * shapeSquare, colorOrange, 0,CoverPrice);// limit
PlotShapes( (Cover == 5) * shapeSmallCircle, colorLightOrange, 0,CoverPrice,0);// limit
[LegacyColorValue = true];
Inputs: K1(.5),K2(.5),Mday(1),Nday(1);
Vars: BuyRange(0), SellRange(0);
Vars: BuyTrig(0),SellTrig(0);
Vars: HH(0),LL(0),HC(0),LC(0);
If CurrentBar > 1 Then Begin
HH = Highest(High,Mday);
HC = Highest(Close,Mday);
LL = Lowest(Low,Mday);
LC = Lowest(Close,Mday);
If (HH - LC) >= (HC - LL) Then Begin
SellRange = HH - LC;
End Else Begin
SellRange = HC - LL;
End;
HH = Highest(High,Nday);
HC = Highest(Close,Nday);
LL = Lowest(Low,Nday);
LC = Lowest(Close,Nday);
If (HH - LC) >= (HC - LL) Then Begin
BuyRange = HH - LC;
End Else Begin
BuyRange = HC - LL;
End;
BuyTrig = K1*BuyRange;
SellTrig = K2*SellRange;
If MarketPosition = 0 Then Begin
Buy Next Bar at Open of next bar + BuyTrig Stop;
Sell Short Next Bar at Open of next bar - SellTrig Stop;
End;
If MarketPosition = -1 Then Begin
Buy Next Bar at Open of next bar + Buytrig Stop;
End;
If MarketPosition = 1 Then Begin
Sell Short Next Bar at Open of next bar - SellTrig Stop;
End;
End;
Код для Multicharts
Inputs: K1(.5),K2(.5),Mday(1),Nday(1);
Vars: BuyRange(0), SellRange(0);
Vars: BuyTrig(0),SellTrig(0);
Vars: HH(0),LL(0),HC(0),LC(0);
If CurrentBar > 1 Then Begin
HH = Highest(High,Mday);
HC = Highest(Close,Mday);
LL = Lowest(Low,Mday);
LC = Lowest(Close,Mday);
If (HH - LC) >= (HC - LL) Then Begin
SellRange = HH - LC;
End Else Begin
SellRange = HC - LL;
End;
HH = Highest(High,Nday);
HC = Highest(Close,Nday);
LL = Lowest(Low,Nday);
LC = Lowest(Close,Nday);
If (HH - LC) >= (HC - LL) Then Begin
BuyRange = HH - LC;
End Else Begin
BuyRange = HC - LL;
End;
BuyTrig = K1*BuyRange;
SellTrig = K2*SellRange;
If MarketPosition = 0 Then Begin
Buy Next Bar at Open of next bar + BuyTrig Stop;
Sell Short Next Bar at Open of next bar - SellTrig Stop;
End;
If MarketPosition = -1 Then Begin
Buy Next Bar at Open of next bar + Buytrig Stop;
End;
If MarketPosition = 1 Then Begin
Sell Short Next Bar at Open of next bar - SellTrig Stop;
End;
End;
Код для Multicharts
[LegacyColorValue = TRUE];
Inputs: K1(0.5),K2(0.5),Mday(1),Nday(1);
Vars: BuyRange(0), SellRange(0);
Vars: BuyTrig(0),SellTrig(0);
Vars: HH(0),LL(0),HC(0),LC(0);
If CurrentBar > 1 Then Begin
HH = Highest(High,Mday);
HC = Highest(Close,Mday);
LL = Lowest(Low,Mday);
LC = Lowest(Close,Mday);
If (HH - LC) >= (HC - LL) Then Begin
SellRange = HH - LC;
End Else Begin
SellRange = HC - LL;
End;
HH = Highest(High,Nday);
HC = Highest(Close,Nday);
LL = Lowest(Low,Nday);
LC = Lowest(Close,Nday);
If (HH - LC) >= (HC - LL) Then Begin
BuyRange = HH - LC;
End Else Begin
BuyRange = HC - LL;
End;
BuyTrig = K1*BuyRange;
SellTrig = K2*SellRange;
If MarketPosition = 0 Then Begin
Buy at next bar Open of next bar + BuyTrig Stop;
sellshort at next bar Open of next bar - SellTrig Stop;
End;
If MarketPosition = -1 Then Begin
Buy at next bar Open of next bar + Buytrig Stop;
End;
If MarketPosition = 1 Then Begin
sellshort at next bar Open of next bar - SellTrig Stop;
End;
End;
Inputs: K1(0.5),K2(0.5),Mday(1),Nday(1);
Vars: BuyRange(0), SellRange(0);
Vars: BuyTrig(0),SellTrig(0);
Vars: HH(0),LL(0),HC(0),LC(0);
If CurrentBar > 1 Then Begin
HH = Highest(High,Mday);
HC = Highest(Close,Mday);
LL = Lowest(Low,Mday);
LC = Lowest(Close,Mday);
If (HH - LC) >= (HC - LL) Then Begin
SellRange = HH - LC;
End Else Begin
SellRange = HC - LL;
End;
HH = Highest(High,Nday);
HC = Highest(Close,Nday);
LL = Lowest(Low,Nday);
LC = Lowest(Close,Nday);
If (HH - LC) >= (HC - LL) Then Begin
BuyRange = HH - LC;
End Else Begin
BuyRange = HC - LL;
End;
BuyTrig = K1*BuyRange;
SellTrig = K2*SellRange;
If MarketPosition = 0 Then Begin
Buy at next bar Open of next bar + BuyTrig Stop;
sellshort at next bar Open of next bar - SellTrig Stop;
End;
If MarketPosition = -1 Then Begin
Buy at next bar Open of next bar + Buytrig Stop;
End;
If MarketPosition = 1 Then Begin
sellshort at next bar Open of next bar - SellTrig Stop;
End;
End;
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using WealthLab;
using WealthLab.Indicators;
namespace WealthLab.Strategies
{
public class MyStrategy : WealthScript
{
StrategyParameter MDayPar;
StrategyParameter NDayPar;
StrategyParameter K1Par;
StrategyParameter K2Par;
public MyStrategy()
{
MDayPar=CreateParameter("MDay", 5,1,10,1);
K1Par=CreateParameter("K1", 5,1,10,1);
NDayPar=CreateParameter("NDay", 5,1,10,1);
K2Par=CreateParameter("K2", 5,1,10,1);
}
protected override void Execute()
{
Position p;
double HH, HC, LL, LC, SellRange, BuyRange, BuyTrig, SellTrig;
bool bLongSAR=false;
int Mday,Nday;
double K1,K2;
Mday =MDayPar.ValueInt;
Nday = NDayPar.ValueInt;
K1 = (double)K1Par.ValueInt/10.0;
K2 = (double)K2Par.ValueInt/10.0;
for(int bar = 10; bar < Bars.Count; bar++)
{
HH = Highest.Series(High,Mday)[bar-1];
HC = Highest.Series(Close, Mday)[bar-1];
LL = Lowest.Series(Low, Mday)[bar-1];
LC = Lowest.Series(Close, Mday)[bar-1];
if ((HH - LC) >= (HC - LL))
SellRange = HH - LC;
else
SellRange = HC - LL;
HH = Highest.Series(High,Nday)[bar-1];
HC = Highest.Series(Close, Nday)[bar-1];
LL = Lowest.Series(Low, Nday)[bar-1];
LC = Lowest.Series(Close, Nday)[bar-1];
if ((HH - LC) >= (HC - LL))
BuyRange = HH - LC;
else
BuyRange = HC - LL;
BuyTrig = K1 * BuyRange;
SellTrig = K2 * SellRange;
if (IsLastPositionActive)
{
p = LastPosition;
bLongSAR =p.PositionType == PositionType.Long;// PositionLong( p );
if (p.PositionType == PositionType.Long)
SellAtStop( bar,p, Open[bar] - SellTrig, "");
if (p.PositionType == PositionType.Short)
CoverAtStop( bar,p, Open[bar] + BuyTrig, "");
}
else
{
//code your entry rules here
}
if (!bLongSAR)
BuyAtStop(bar, Open[bar] + BuyTrig, "");
if (bLongSAR)
ShortAtStop(bar, Open[bar] - SellTrig, "");
}
}
}
}
Комментариев нет:
Отправить комментарий