Вы упускаете торговые возможности:
- Бесплатные приложения для трейдинга
- 8 000+ сигналов для копирования
- Экономические новости для анализа финансовых рынков
Регистрация
Вход
Вы принимаете политику сайта и условия использования
Если у вас нет учетной записи, зарегистрируйтесь
StrategyName = 'Aroon-MA- Stoch for NFA';
var //declaration of the variables
History: TCandleHistory;
Account: TAccount;
AroonSum, AroonSumPast, Amount, OrigAmount, AmountMult, Point: Double;
StopLoss, TakeProfit, BuyOpen, SellOpen, MA1, AroonUpper, AroonLower, Switch, TraderRange, i, StochTop, StochBottom: Integer;
Aroon: TIndicatorAroon;
Stochastic: TIndicatorStochastic;
CountOrd:integer;
EntryLimitOrder, EntryStopOrder: TOrder;
procedure OnCreate;
begin
AddCandleHistorySetting(@History, 'History', '', CI_15_Minutes, 100); //setting up the chart history
History.OnNewCandleEvent := @OnNewCandle; //indicating the procedure to run when a new candle opens
AddIntegerSetting(@TakeProfit, 'TakeProfit', 12); //setting up limit in pips
AddIntegerSetting(@StopLoss, 'StopLoss', 99); //setting up stop in pips
AddIntegerSetting(@MA1, 'Average of Aroon', 5); //simple moving average of the aroon
AddIntegerSetting(@AroonUpper, 'Aroon Upper Line', 10); //the Upper of two overbought/oversold lines
AddIntegerSetting(@Switch, 'Switch', 1); //for reversing buy and sell on the signal - "1" or "any other number
AddFloatSetting(@AmountMult, 'Amount Multiplier', 2); //multiplies the number of lots if the close is less than 0
AddFloatSetting(@Amount, 'Amount(Lots)', 1); //the number of lots
AddIntegerSetting(@TraderRange, 'Trader Range', 0); //setting up the trader range in pips
AddAccountSetting(@Account, 'Account', ''); //the account number
AddIntegerSetting(@StochTop, 'Stoch Top', 80); //setting up the specific top level
//that will be used
AddIntegerSetting(@StochBottom, 'Stoch Bottom', 20); //setting up the specific bottom level
//that will be used
Aroon := TIndicatorAroon.Create(History, 'Aroon');
Aroon.Period := 2;
Aroon.IsOscillator := True;
Stochastic := TIndicatorStochastic.Create(History, 'Stochastic');
Stochastic.Period := 5;
Stochastic.AveragePeriod := 3;
Stochastic.Slow := False;
end;
procedure OnStart;
begin
AroonLower:=AroonUpper-AroonUpper-AroonUpper;
SellOpen:=0;
BuyOpen:=0;
AroonSum:=0;
OrigAmount:=Amount;
end;
// this procedure runs when a new candle opens
procedure OnNewCandle;
begin
Point := History.Instrument.PointSize;
AroonSumPast:=AroonSum;
AroonSum:=0;
MA1:=MA1+1;
for i:=MA1-1 downto 1 do
begin
try
AroonSum:=AroonSum + Aroon.Graph.Last(i);
except
end;
end;
MA1:=MA1-1;
AroonSum:=AroonSum/MA1;
//// Begin Switch ***************************************************
if (Switch = 1) then
begin
if (AroonSum > AroonLower)
and (AroonSumPast <= AroonLower)
and (Stochastic.GraphD.Last(1)>StochBottom) and (Stochastic.GraphD.Last(4)<StochBottom)then
begin
if (CountOrd=0) then
begin
CreateOrder(History.Instrument, Account, Amount, bsBuy, NullRate, NullRate, TraderRange, 'AroonMATradeBuy');
CreateEntryOrder(History.Instrument, Account, Amount, bsSell, History.Instrument.Sell + Point*TakeProfit, NullRate, NullRate, otELimit, 'AroonMATradeProfit');
CreateEntryOrder(History.Instrument, Account, Amount, bsSell, History.Instrument.Sell - Point*StopLoss, NullRate, NullRate, otEStop, 'AroonMATradeStop');
CountOrd:=2;
end;
end;
if (AroonSum < AroonUpper)
and (AroonSumPast >= AroonLower)
and (Stochastic.GraphD.Last(1)<StochTop) and (Stochastic.GraphD.Last(4)>StochTop) then
begin
if (CountOrd=0) then
begin
CreateOrder(History.Instrument, Account, Amount, bsSell, NullRate, NullRate, TraderRange, 'AroonMATradeSell');
CreateEntryOrder(History.Instrument, Account, Amount, bsBuy, History.Instrument.Buy + Point*StopLoss, NullRate, NullRate, otEStop, 'AroonMATradeStop');
CreateEntryOrder(History.Instrument, Account, Amount, bsBuy, History.Instrument.Buy - Point*TakeProfit, NullRate, NullRate, otELimit, 'AroonMATradeProfit');
CountOrd:=1;
end;
end;
end;
//// Switch Middle ***************************************************
if (Switch <> 1) then
begin
if (AroonSum < AroonLower)
and (AroonSumPast >= AroonLower)
and (Stochastic.GraphD.Last(1)>StochBottom) and (Stochastic.GraphD.Last(4)<StochBottom)then
begin
if (CountOrd=0) then
begin
CreateOrder(History.Instrument, Account, Amount, bsBuy, NullRate, NullRate, TraderRange, 'AroonMATradeBuy');
CreateEntryOrder(History.Instrument, Account, Amount, bsSell, History.Instrument.Sell + Point*TakeProfit, NullRate, NullRate, otELimit, 'AroonMATradeProfit');
CreateEntryOrder(History.Instrument, Account, Amount, bsSell, History.Instrument.Sell - Point*StopLoss, NullRate, NullRate, otEStop, 'AroonMATradeStop');
CountOrd:=1;
end;
end;
if (AroonSum > AroonUpper)
and (AroonSumPast <= AroonLower)
and (Stochastic.GraphD.Last(1)<StochTop) and (Stochastic.GraphD.Last(4)>StochTop) then
begin
if (CountOrd=0) then
begin
CreateOrder(History.Instrument, Account, Amount, bsSell, NullRate, NullRate, TraderRange, 'AroonMATradeSell');
CreateEntryOrder(History.Instrument, Account, Amount, bsBuy, History.Instrument.Buy + Point*StopLoss, NullRate, NullRate, otEStop, 'AroonMATradeStop');
CreateEntryOrder(History.Instrument, Account, Amount, bsBuy, History.Instrument.Buy - Point*TakeProfit, NullRate, NullRate, otELimit, 'AroonMATradeProfit');
CountOrd:=2;
end;
end;
end;
//// End Switch ***************************************************
end;
// this procedure runs when some changes occur in the Open Positions list
procedure OnTradeChange(const Action: TDataModificationType; const Trade: TTrade);
begin
// if a trade closed
if (Action=dmtDelete) then
begin
if (CountOrd = 1) then
begin
if ((Trade.CloseRate - Trade.OpenRate) < 0) then
begin
Amount:=Round(Amount*AmountMult);
end;
if ((Trade.CloseRate - Trade.OpenRate) >= 0) then
begin
Amount:=OrigAmount;
end;
end;
if (CountOrd = 2) then
begin
if ((Trade.OpenRate - Trade.CloseRate) < 0) then
begin
Amount:=Round(Amount*AmountMult);
end;
if ((Trade.OpenRate - Trade.CloseRate) >= 0) then
begin
Amount:=OrigAmount;
end;
end;
end;
end;
procedure OnOrderChange(const Action: TDataModificationType; const Order: TOrder);
begin
case Action of
dmtInsert:
begin
if Order.Tag = 'AroonMATradeStop' then EntryStopOrder := Order
else if Order.Tag = 'AroonMATradeProfit' then EntryLimitOrder := Order;
end;
dmtDelete:
begin
if CountOrd = 0 then Exit;
if Order = EntryStopOrder then begin EntryLimitOrder.Remove; CountOrd:=0;end
else if Order = EntryLimitOrder then begin EntryStopOrder.Remove; CountOrd:=0; end;
end;
end;
end;