Can someone post code they use for trailing stops
My programming skills are a bit rusty
Trailing Stop
- Terranin
- Site Admin
- Posts: 833
- Joined: Sat Oct 21, 2006 4:39 pm
Re: Trailing Stop
southsider wrote:Can someone post code they use for trailing stops
My programming skills are a bit rusty
Here it is some code in Delphi:
Code: Select all
Procedure TS;
var
i:integer;
begin
if OrdersTotal>0 then
for i:=0 to OrdersTotal do
{1} begin
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType=tp_Buy) then
begin
if (OrderStopLoss=0) and (Bid-OrderOpenPrice>TrailingStop*Point) then ModifyOrder(OrderTicket,OrderOpenPrice,Bid-TrailingStop*Point,0);
if (OrderStopLoss>0) and (RoundTo(Bid-TrailingStop*Point,-4)>RoundTo(OrderStopLoss,-4)) then
begin
if Bid-OrderStoploss>(TrailingStop+TrailingStep)*Point then ModifyOrder(OrderTicket,OrderOpenPrice,Bid-TrailingStop*Point,0);
end;
end;
if (OrderType=tp_Sell) then
begin
if (OrderStopLoss=0) and (OrderOpenPrice-Ask>Trailingstop*Point) then ModifyOrder(OrderTicket,OrderOpenPrice,Ask+TrailingStop*Point,0);
if (OrderStopLoss>0) and (RoundTo(Ask+TrailingStop*Point,-4)< RoundTo(OrderStopLoss,-4)) then
begin
if (OrderStopLoss-Ask)>(TrailingStop+TrailingStep)*Point then ModifyOrder(OrderTicket,OrderOpenPrice,Ask+TrailingStop*Point,0);
end;
end;
{1} end;
end;
Uses TrailingStop and TralingStep parameters equal to same parameters in order dialog window.
Hasta la vista
Mike
Mike
-
- Posts: 1
- Joined: Sat Nov 13, 2010 6:42 pm
trailing stop parameter definition
what are the following:
-Trailing Stop, Points
-Step of change, Points
-Trailing Stop, Points
-Step of change, Points
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
-
- Posts: 5
- Joined: Thu Apr 19, 2012 6:27 am
- Location: UG
Re: Trailing Stop
Terranin wrote:and (RoundTo(Bid-TrailingStop*Point,-4)>RoundTo(OrderStopLoss,-4)) then
begin
What's the '-4' for? I cant find any code for trailing stops in the FT manual, and have tried to learn RoundTo from google finds, but need the equivalent of above expression in C++ or MQL, please?
-
- Posts: 905
- Joined: Sat Jul 11, 2009 10:54 am
-4 means that the result of RoundTo function will be with 4 digits after point, in MQL you can use "NormalizeDouble" function
Code: Select all
NormalizeDouble(X, 4)
Check our other product here:
http://www.forexcopier.com
http://www.forexcopier.com
-
- Posts: 5
- Joined: Thu Apr 19, 2012 6:27 am
- Location: UG
Re: Trailing Stop
Terranin wrote:
Here it is some code in Delphi:Code: Select all
Procedure TS;
var
i:integer;
begin
if OrdersTotal>0 then
for i:=0 to OrdersTotal do
{1} begin
OrderSelect(i,SELECT_BY_POS,MODE_TRADES);
if (OrderType=tp_Buy) then
begin
if (OrderStopLoss=0) and (Bid-OrderOpenPrice>TrailingStop*Point) then ModifyOrder(OrderTicket,OrderOpenPrice,Bid-TrailingStop*Point,0);
if (OrderStopLoss>0) and (RoundTo(Bid-TrailingStop*Point,-4)>RoundTo(OrderStopLoss,-4)) then
begin
if Bid-OrderStoploss>(TrailingStop+TrailingStep)*Point then ModifyOrder(OrderTicket,OrderOpenPrice,Bid-TrailingStop*Point,0);
end;
end;
if (OrderType=tp_Sell) then
begin
if (OrderStopLoss=0) and (OrderOpenPrice-Ask>Trailingstop*Point) then ModifyOrder(OrderTicket,OrderOpenPrice,Ask+TrailingStop*Point,0);
if (OrderStopLoss>0) and (RoundTo(Ask+TrailingStop*Point,-4)< RoundTo(OrderStopLoss,-4)) then
begin
if (OrderStopLoss-Ask)>(TrailingStop+TrailingStep)*Point then ModifyOrder(OrderTicket,OrderOpenPrice,Ask+TrailingStop*Point,0);
end;
end;
{1} end;
end;
Uses TrailingStop and TralingStep parameters equal to same parameters in order dialog window.
Can anyone code this trailing stop code in MQL?
Who is online
Users browsing this forum: No registered users and 12 guests