plz convert this EA back to MQL for EA 2 ,,,

Posted By kkptra Sunday, July 03, 2016
Add to Favorites0
Author Message
kkptra
 Posted Sunday, July 03, 2016
Supreme Being

Supreme Being - (187 reputation)Supreme Being - (187 reputation)Supreme Being - (187 reputation)Supreme Being - (187 reputation)Supreme Being - (187 reputation)Supreme Being - (187 reputation)Supreme Being - (187 reputation)Supreme Being - (187 reputation)Supreme Being - (187 reputation)

Group: Forum Members
Last Active: Tuesday, July 19, 2016
Posts: 3, Visits: 10
187
hi, I have a converted ActFX (from Mql file), conversion done error-less but ACtFx code is not opening any order,,, and do not have the MQL file... can anyone help to to convert back this converted Actfx code to MQL code..

Here is EA which was successfully converted, but no trades at all.

Please provide the MQL file for below.
Here is the code for EA 2:


uses 'LibMQL4.actlib';
const StrategyName = 'TSD v12.3.mq4';
const copyright_1 = 'Copyright © 2009, http://www.forex-tsd.com';
const link_2 = 'http://www.forex-tsd.com';
var MagicNumber: Variant = 10001;
var Lots: Real = 1.0;
var TakeProfit: Variant = 100;
var TrailingStop: Variant = 60;
var Slippage: Variant = 5;
var UseTimeLimit: Boolean = true;
var UseAutomaticMM: Boolean = true;
var Risk: Real = 1.5;
var _: String = 'Does it allow multiple trades per bar';
var OneTradePerBar: Boolean = false;
var __: String = 'Setting for friday positions close';
var CloseOnFriday: Boolean = false;
var FridayCloseHour: Variant = 21;
var FridayCloseMinute: Variant = 59;
var StartMinute1: Real = 0;
var EndMinute1: Real = 0;
var StartMinute2: Real = 0;
var EndMinute2: Real = 0;
var StartMinute3: Real = 0;
var EndMinute3: Real = 0;
var StartMinute4: Real = 0;
var EndMinute4: Real = 0;
var StartMinute5: Real = 0;
var EndMinute5: Real = 0;
var StartMinute6: Real = 0;
var EndMinute6: Real = 0;
var StartMinute7: Real = 0;
var EndMinute7: Real = 0;
var PriceOpen: Real = 0;
var NewPrice: Real = 0;
var newbar: Real = 0;

function OnNewCandle : Variant;
var pipMultiplier: Real;
var i: Integer;
var symbolFound: Boolean;
var withinTimeLimit: Boolean;
var TradesThisSymbol: Variant;
var OsMAPrevious: Real;
var OsMAPrevious2: Real;
var Force: Real;
var ForcePos: Boolean;
var ForceNeg: Boolean;
var OsMADirection: Real;
var tp: Real;
var ts: Real;
var sl: Real;
var ticket: Variant;
begin
if ((Digits = 3) or (Digits = 5)) then
pipMultiplier := 10

else pipMultiplier := 1;
if (CloseOnFriday) and (TimeDayOfWeek (TimeCurrent ()) = 5) then
begin
if (TimeHour (TimeCurrent ()) > FridayCloseHour) or ((TimeHour (TimeCurrent ()) = FridayCloseHour) and (TimeMinute (TimeCurrent ()) >= FridayCloseMinute)) then
begin
for i := OrdersTotal () - 1
downto 0 do begin
OrderSelect (i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol () <> Symbol ()) then
continue;

if (OrderMagicNumber () <> MagicNumber) then
continue;

if (OrderType () = OP_BUYSTOP) then
begin
OrderDelete (OrderTicket (), CLR_NONE);
continue;

end;

if (OrderType () = OP_SELLSTOP) then
begin
OrderDelete (OrderTicket (), CLR_NONE);
continue;

end;

if (OrderType () = OP_BUY) then
begin
OrderClose (OrderTicket (), OrderLots (), Ask, 0, CLR_NONE);
continue;

end;

if (OrderType () = OP_SELL) then
begin
OrderClose (OrderTicket (), OrderLots (), Bid, 0, CLR_NONE);
continue;

end;

end;
Result := (0);
Exit;
end;

end;

symbolFound := (false);
if (checkSymbol ('USDCHF')) then
begin
setMinutes (0, 1, 8, 9, 16, 17, 24, 25, 32, 33, 40, 41, 48, 49);
symbolFound := true;

end;

if (checkSymbol ('GBPUSD')) then
begin
setMinutes (2, 3, 10, 11, 18, 19, 26, 27, 34, 35, 42, 43, 50, 51);
symbolFound := true;

end;

if (checkSymbol ('USDJPY')) then
begin
setMinutes (4, 5, 12, 13, 20, 21, 28, 29, 36, 37, 44, 45, 52, 53);
symbolFound := true;

end;

if (checkSymbol ('EURUSD')) then
begin
setMinutes (6, 7, 14, 15, 22, 23, 30, 31, 38, 39, 46, 47, 54, 59);
symbolFound := true;

end;

if (not symbolFound) then
begin
Result := (0);
Exit;
end;

if UseTimeLimit then
withinTimeLimit := (((Minute () >= StartMinute1) and (Minute () <= EndMinute1)) or ((Minute () >= StartMinute2) and (Minute () <= EndMinute2)) or ((Minute () >= StartMinute3) and (Minute () <= EndMinute3)) or ((Minute () >= StartMinute4) and (Minute () <= EndMinute4)) or ((Minute () >= StartMinute5) and (Minute () <= EndMinute5)) or ((Minute () >= StartMinute6) and (Minute () <= EndMinute6)) or ((Minute () >= StartMinute7) and (Minute () <= EndMinute7)))

else withinTimeLimit := true;
if (not withinTimeLimit) then
begin
Result := (0);
Exit;
end;

TradesThisSymbol := (0);
begin
for i := OrdersTotal () - 1
downto 0 do begin
OrderSelect (i, SELECT_BY_POS, MODE_TRADES);
if (OrderMagicNumber () <> MagicNumber) then
continue;

if (OrderSymbol () <> Symbol ()) then
continue;

Inc (TradesThisSymbol);

end;

end;
OsMAPrevious := (iOsMA (NULL, PERIOD_W1, 12, 26, 9, PRICE_CLOSE, 1));
OsMAPrevious2 := (iOsMA (NULL, PERIOD_W1, 12, 26, 9, PRICE_CLOSE, 2));
Force := (iForce (NULL, PERIOD_D1, 2, MODE_EMA, PRICE_CLOSE, 1));
ForcePos := (Force > 0);
ForceNeg := (Force < 0);
if OsMAPrevious > OsMAPrevious2 then
OsMADirection := (1);

if OsMAPrevious < OsMAPrevious2 then
OsMADirection := - 1;

if (OsMAPrevious = OsMAPrevious2) then
OsMADirection := 0;

if (not IsTesting ()) or ((IsTesting ()) and (IsVisualMode ())) then
Comment ('TSD for MT4 ver beta 0.3 - DO NOT USE WITH REAL MONEY YET', '', '', 'Weekly OsMAPrevious = ', OsMAPrevious, '', 'Weekly OsMAPrevious2 = ', OsMAPrevious2, '', 'Weekly OsMADirection = ', OsMADirection, '', '', 'Daily Force = ', Force, '', 'Is Daily Force Bullish = ', ForcePos, '', 'Is Daily Force Bearish = ', ForceNeg, '', '', 'Total Orders = ', OrdersTotal (), '', 'Trades this Symbol(', Symbol (), ') = ', TradesThisSymbol, '', '', 'New Bar Time is ', MQLTimeToStr (newbar), '', '', 'Daily High[1] = ', High (1), '', 'Daily High[2] = ', High (2), '', 'Daily Low[1] = ', Low (1), '', 'Daily Low[2] = ', Low (2), '', '', 'Current Ask Price + 16 pips = ', (Ask + (16 * Point * pipMultiplier)), '', 'Current Bid Price - 16 pips = ', Bid - (16 * Point * pipMultiplier));

tp := (NormalizeDouble ((TakeProfit * Point * pipMultiplier), Digits));
ts := (NormalizeDouble ((TrailingStop * Point * pipMultiplier), Digits));
if (newbar <> iTime (NULL, 0, 0)) then
begin
newbar := iTime (NULL, 0, 0);
if (TradesThisSymbol < 1) and (canOpenTrade (Period ())) then
begin
RefreshRates ();
if (OsMADirection = 1) and (ForceNeg) then
begin
sl := (Low (1) - 1.0 * Point * pipMultiplier);
PriceOpen := High (1) + 1.0 * Point * pipMultiplier;
if PriceOpen > (Ask + 16.0 * Point * pipMultiplier) then
begin
OrderSend (Symbol (), OP_BUYSTOP, (PriceOpen - sl), PriceOpen, Slippage, sl, PriceOpen + tp, 'Buy Entry Order placed at ' + TimeCurrent (), MagicNumber, 0, Green);
Result := (0);
Exit;
end

else begin
NewPrice := Ask + 16.0 * Point * pipMultiplier;
OrderSend (Symbol (), OP_BUYSTOP, (NewPrice - sl), NewPrice, Slippage, sl, NewPrice + tp, 'Buy Entry Order placed at ' + TimeCurrent (), MagicNumber, 0, Green);
Result := (0);
Exit;
end;

end;

if (OsMADirection = - 1) and (ForcePos) then
begin
sl := High (1) + 1.0 * Point * pipMultiplier;
PriceOpen := Low (1) - 1.0 * Point * pipMultiplier;
if PriceOpen < (Bid - 16.0 * Point * pipMultiplier) then
begin
OrderSend (Symbol (), OP_SELLSTOP, (sl - PriceOpen), PriceOpen, Slippage, sl, PriceOpen - tp, 'Sell Entry Order placed at ' + TimeCurrent (), MagicNumber, 0, Green);
Result := (0);
Exit;
end

else begin
NewPrice := Bid - 16 * Point * pipMultiplier;
ticket := (OrderSend (Symbol (), OP_SELLSTOP, (sl - NewPrice), NewPrice, Slippage, sl, NewPrice - tp, 'Sell Entry Order placed at ' + TimeCurrent (), MagicNumber, 0, Green));
Result := (0);
Exit;
end;

end;

end;

if TradesThisSymbol > 0 then
begin
begin
for i := OrdersTotal () - 1
downto 0 do begin
OrderSelect (i, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol () <> Symbol ()) then
continue;

if (OrderMagicNumber () <> MagicNumber) then
continue;

RefreshRates ();
if (OrderType () = OP_BUYSTOP) then
begin
if (OsMADirection = - 1) then
begin
OrderDelete (OrderTicket ());
Result := (0);
Exit;
end;

if ((High (1) < High (2))) then
if (High (1) > (Ask + 16.0 * Point * pipMultiplier)) then
begin
OrderModify (OrderTicket (), (High (1) + 1.0 * Point * pipMultiplier), Low (1) - 1.0 * Point * pipMultiplier, OrderTakeProfit (), 0, Cyan);
Result := (0);
Exit;
end

else begin
OrderModify (OrderTicket (), (Ask + 16.0 * Point * pipMultiplier), Low (1) - 1.0 * Point * pipMultiplier, OrderTakeProfit (), 0, Cyan);
Result := (0);
Exit;
end;

end;

if (OrderType () = OP_SELLSTOP) then
begin
if (OsMADirection = 1) then
begin
OrderDelete (OrderTicket ());
Result := (0);
Exit;
end;

if ((Low (1) > Low (2))) then
if (Low (1) < (Bid - 16.0 * Point * pipMultiplier)) then
begin
OrderModify (OrderTicket (), (Low (1) - 1.0 * Point * pipMultiplier), High (1) + 1.0 * Point * pipMultiplier, OrderTakeProfit (), 0, Cyan);
Result := (0);
Exit;
end

else begin
OrderModify (OrderTicket (), (Bid - 16.0 * Point * pipMultiplier), High (1) + 1.0 * Point * pipMultiplier, OrderTakeProfit (), 0, Cyan);
Result := (0);
Exit;
end;

end;

end;

end;

end;

end;

if TradesThisSymbol > 0 then
begin
begin
for i := OrdersTotal () - 1
downto 0 do begin
if (OrderSelect (i, SELECT_BY_POS, MODE_TRADES) = false) then
break;

if (OrderSymbol () <> Symbol ()) then
continue;

if (OrderMagicNumber () <> MagicNumber) then
continue;

RefreshRates ();
if (OrderType () = OP_BUY) then
begin
if Ask - OrderOpenPrice () > (ts) then
begin
if OrderStopLoss () < (Ask - ts) then
begin
OrderModify (OrderTicket (), OrderOpenPrice (), (Ask - ts), Ask + tp, 0, Cyan);
Result := (0);
Exit;
end;

end;

end;

if (OrderType () = OP_SELL) then
begin
if OrderOpenPrice () - Bid > (ts) then
begin
if OrderStopLoss () > (Bid + ts) then
begin
OrderModify (OrderTicket (), OrderOpenPrice (), (Bid + ts), Bid - tp, 0, Cyan);
Result := (0);
Exit;
end;

end;

end;

end;

end;

end;

Result := (0);
Exit;
end;

function getLots (range : Real) : Real;
var step: Real;
var minLot: Real;
var maxLot: Real;
var lots: Real;
begin
RefreshRates ();
step := (MarketInfo (Symbol (), MODE_LOTSTEP));
minLot := (MarketInfo (Symbol (), MODE_MINLOT));
maxLot := (MarketInfo (Symbol (), MODE_MAXLOT));
lots := (Lots);
if UseAutomaticMM then
if Risk > 0 then
lots := AccountFreeMargin () * (Risk / 100.0) / (range * MarketInfo (Symbol (), MODE_TICKVALUE) / Point);

Result := (MathMax (MathMin (lots, maxLot), minLot));
Exit;
end;

function canOpenTrade (timeFrame : Variant) : Boolean;
var periodCount: Variant;
var startTime: Integer;
var endTime: Integer;
var i: Integer;
begin
periodCount := (0);
startTime := (iTime (Symbol (), timeFrame, iBarShift (Symbol (), timeFrame, iTime (NULL, 0, 0))));
endTime := (startTime + timeFrame * 60 - 1);
if (not OneTradePerBar) then
for i := OrdersHistoryTotal () - 1
downto 0 do begin
if (OrderSelect (i, SELECT_BY_POS, MODE_HISTORY) = false) then
break;

if (OrderMagicNumber () <> MagicNumber) then
continue;

if (OrderSymbol () <> Symbol ()) then
continue;

if (OrderOpenTime () < startTime) or (OrderOpenTime () > endTime) then
continue;

Inc (periodCount);

end;

Result := (periodCount = 0);
Exit;
end;

function checkSymbol (compareToWhat : String) : Boolean;
begin
Result := (StringFind (Symbol (), compareToWhat) > - 1);
Exit;
end;

procedure setMinutes (sminute1 : Variant; eminute1 : Variant; sminute2 : Variant; eminute2 : Variant; sminute3 : Variant; eminute3 : Variant; sminute4 : Variant; eminute4 : Variant; sminute5 : Variant; eminute5 : Variant; sminute6 : Variant; eminute6 : Variant; sminute7 : Variant; eminute7 : Variant);
var Result: Variant;
begin
StartMinute1 := sminute1;
EndMinute1 := eminute1;
StartMinute2 := sminute2;
EndMinute2 := eminute2;
StartMinute3 := sminute3;
EndMinute3 := eminute3;
StartMinute4 := sminute4;
EndMinute4 := eminute4;
StartMinute5 := sminute5;
EndMinute5 := eminute5;
StartMinute6 := sminute6;
EndMinute6 := eminute6;
StartMinute7 := sminute7;
EndMinute7 := eminute7;

end;

procedure OnCreate;
begin
Settings.AddAccount(@Account, 'Account', '30');
Settings.AddCandleHistory(@History, 'Candle History', 'EURUSD', CI_15_Minutes, 100);
History.OnNewCandleEvent := @OnNewCandle;
Settings.AddInteger(@MagicNumber, 'MagicNumber', MagicNumber);
Settings.AddFloat(@Lots, 'Lots', Lots);
Settings.AddInteger(@TakeProfit, 'TakeProfit', TakeProfit);
Settings.AddInteger(@TrailingStop, 'TrailingStop', TrailingStop);
Settings.AddInteger(@Slippage, 'Slippage', Slippage);
Settings.AddCheckbox(@UseTimeLimit, 'UseTimeLimit', UseTimeLimit);
Settings.AddCheckbox(@UseAutomaticMM, 'UseAutomaticMM', UseAutomaticMM);
Settings.AddFloat(@Risk, 'Risk', Risk);
Settings.AddString(@_, '_', _);
Settings.AddCheckbox(@OneTradePerBar, 'OneTradePerBar', OneTradePerBar);
Settings.AddString(@__, '__', __);
Settings.AddCheckbox(@CloseOnFriday, 'CloseOnFriday', CloseOnFriday);
Settings.AddInteger(@FridayCloseHour, 'FridayCloseHour', FridayCloseHour);
Settings.AddInteger(@FridayCloseMinute, 'FridayCloseMinute', FridayCloseMinute);

end;

Similar Topics

Expand / Collapse

Reading This Topic

Expand / Collapse

Back To Top