PureBytes Links
Trading Reference Links
|
Hi Afl experts,
Is there any afl to match this mt4 code of Trendmagic?
Can you please code an afl to match this mt4 code ?
----------------
Trendmagic mt4
-------------
int g_period_76 = 5;
int g_period_80 = 3;
int g_slowing_84 = 3;
int g_period_88 = 2;
int g_period_92 = 12;
double gd_96 = 0.003;
double gd_104 = 0.018;
int g_period_112 = 19;
int g_period_116 = 50;
bool gi_120 = FALSE;
extern double Lots = 0.1;
double gd_132 = 80.0;
double gd_140 = 20.0;
extern bool RiskMM = TRUE;
extern double RiskPercent = 2.0;
extern double MinLots = 0.01;
extern double MaxLots = 100.0;
int gi_176 = 23;
extern int StopLoss = 70;
extern int TakeProfit = 30;
int g_timeframe_188 = PERIOD_M1;
int g_period_192 = 14;
double gd_196 = 7.0;
extern int MaxOrders = 100;
int g_slippage_208 = 3;
int g_magic_212 = 19091;
int g_magic_216 = 19092;
bool gi_220 = FALSE;
int gi_224 = 20160;
datetime g_time_228;
datetime g_time_232;
double gd_unused_252 = 0.0;
double gd_unused_260 = 1.0;
double gd_unused_268 = 1.0;
int init() {
return (0);
}
int start() {
double l_istochastic_8;
double l_istochastic_16;
double l_istochastic_24;
double l_istochastic_32;
double l_irsi_40;
double l_irsi_48;
double l_ibearspower_56;
double l_ibearspower_64;
double l_isar_72;
double l_isar_80;
string ls_88;
string ls_96;
string ls_104;
string ls_112;
double l_price_120;
double l_price_128;
double ld_176;
double l_lots_184;
double l_lots_192;
int l_ticket_200;
int l_ticket_204;
if (g_period_192 > 0) MoveTrailingStop();
int li_0 = 1;
for (int l_shift_4 = 1; l_shift_4 <= li_0; l_shift_4++) {
l_istochastic_8 = iStochastic(NULL, 0, g_period_76, g_period_80, g_slowing_84, MODE_SMA, 0, MODE_MAIN, l_shift_4 + 1);
l_istochastic_16 = iStochastic(NULL, 0, g_period_76, g_period_80, g_slowing_84, MODE_SMA, 0, MODE_SIGNAL, l_shift_4 + 1);
l_istochastic_24 = iStochastic(NULL, 0, g_period_76, g_period_80, g_slowing_84, MODE_SMA, 0, MODE_MAIN, l_shift_4);
l_istochastic_32 = iStochastic(NULL, 0, g_period_76, g_period_80, g_slowing_84, MODE_SMA, 0, MODE_SIGNAL, l_shift_4);
l_irsi_40 = iRSI(NULL, 0, g_period_88, PRICE_CLOSE, l_shift_4 + 1);
l_irsi_48 = iRSI(NULL, 0, g_period_88, PRICE_CLOSE, l_shift_4);
l_ibearspower_56 = iBearsPower(NULL, 0, g_period_92, PRICE_CLOSE, l_shift_4 + 1);
l_ibearspower_64 = iBearsPower(NULL, 0, g_period_92, PRICE_CLOSE, l_shift_4);
l_isar_72 = iSAR(NULL, 0, gd_96, gd_104, l_shift_4 + 1);
l_isar_80 = iSAR(NULL, 0, gd_96, gd_104, l_shift_4);
ls_88 = "false";
ls_96 = "false";
if (l_istochastic_24 > l_istochastic_32 && l_irsi_48 > 50.0 && l_ibearspower_64 > 0.0 && Open[l_shift_4] > l_isar_80 && iMA(Symbol(), 0, g_period_112, 0, MODE_SMA, PRICE_CLOSE, l_shift_4) > iMA(Symbol(), 0, g_period_116, 0, MODE_SMA, PRICE_CLOSE, l_shift_4 +
1) && gi_120 == FALSE || (gi_120 && Close[0] > Open[0])) ls_88 = "true";
if (l_istochastic_24 > l_istochastic_32 && l_irsi_48 < 50.0 && l_ibearspower_64 < 0.0 && Open[l_shift_4] < l_isar_80 && iMA(Symbol(), 0, g_period_112, 0, MODE_SMA, PRICE_CLOSE, l_shift_4) < iMA(Symbol(), 0, g_period_116, 0, MODE_SMA, PRICE_CLOSE, l_shift_4 +
1) && gi_120 == FALSE || (gi_120 && Close[0] < Open[0])) ls_96 = "true";
ls_104 = "false";
ls_112 = "false";
if (ls_88 == "true") {
if (gi_220) ls_112 = "true";
else ls_104 = "true";
}
if (ls_96 == "true") {
if (gi_220) ls_104 = "true";
else ls_112 = "true";
}
}
if (RiskMM) CalculateMM();
int l_datetime_216 = 0;
if (gi_224 > 0) l_datetime_216 = TimeCurrent() + 60 * gi_224 - 5;
if (CountOrders(OP_BUY, g_magic_212) + CountOrders(OP_SELL, g_magic_212) + CountOrders(OP_BUY, g_magic_216) + CountOrders(OP_SELL, g_magic_216) < MaxOrders) {
if (ls_104 == "true" && NewBarBuy()) {
if (StopLoss > 0) l_price_120 = Low[l_shift_4] - (gi_176 + StopLoss) * Point - NormalizeDouble(iATR(NULL, 0, 14, 1) / 10.0 / 2.0, Digits);
else l_price_120 = 0;
if (TakeProfit > 0) l_price_128 = High[l_shift_4] + (gi_176 + TakeProfit) * Point;
else l_price_128 = 0;
ld_176 = Lots;
if (ld_176 < MinLots) ld_176 = MinLots;
if (ld_176 > MaxLots) ld_176 = MaxLots;
l_lots_184 = NormalizeDouble(ld_176 * (gd_132 / 100.0), 2);
l_lots_192 = NormalizeDouble(ld_176 * (gd_140 / 100.0), 2);
l_ticket_200 = OrderSend(Symbol(), OP_BUYSTOP, l_lots_184, High[l_shift_4] + gi_176 * Point, g_slippage_208, l_price_120, l_price_128, "The Forex Magic Machine Advance Version", g_magic_212, l_datetime_216, Blue);
l_ticket_204 = OrderSend(Symbol(), OP_BUYSTOP, l_lots_192, High[l_shift_4] + gi_176 * Point, g_slippage_208, l_price_120, 0, "The Forex Magic Machine Advance Version", g_magic_216, l_datetime_216, Blue);
}
if (ls_112 == "true" && NewBarSell()) {
if (StopLoss > 0) l_price_120 = High[l_shift_4] + (gi_176 + StopLoss) * Point + NormalizeDouble(iATR(NULL, 0, 14, 1) / 10.0 / 2.0, Digits);
else l_price_120 = 0;
if (TakeProfit > 0) l_price_128 = Low[l_shift_4] - (gi_176 + TakeProfit) * Point;
else l_price_128 = 0;
ld_176 = Lots;
if (ld_176 < MinLots) ld_176 = MinLots;
if (ld_176 > MaxLots) ld_176 = MaxLots;
l_lots_184 = NormalizeDouble(ld_176 * (gd_132 / 100.0), 2);
l_lots_192 = NormalizeDouble(ld_176 * (gd_140 / 100.0), 2);
l_ticket_200 = OrderSend(Symbol(), OP_SELLSTOP, l_lots_184, Low[l_shift_4] - gi_176 * Point, g_slippage_208, l_price_120, l_price_128, "The Forex Magic Machine Advance Version", g_magic_212, l_datetime_216, Red);
l_ticket_204 = OrderSend(Symbol(), OP_SELLSTOP, l_lots_192, Low[l_shift_4] - gi_176 * Point, g_slippage_208, l_price_120, 0, "The Forex Magic Machine Advance Version", g_magic_216, l_datetime_216, Red);
}
}
int li_unused_220 = 0;
if (l_ticket_200 < 0 && l_ticket_204 < 0) {
if (GetLastError() == 134/* NOT_ENOUGH_MONEY */) {
li_unused_220 = 1;
Print("Not enough money!");
}
return (-1);
}
return (0);
}
int CountOrders(int a_cmd_0, int a_magic_4) {
int l_count_8 = 0;
for (int l_pos_12 = 0; l_pos_12 < OrdersTotal(); l_pos_12++) {
OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES);
if (OrderSymbol() == Symbol())
if (OrderType() == a_cmd_0 && OrderMagicNumber() == a_magic_4 || a_magic_4 == 0) l_count_8++;
}
return (l_count_8);
}
void MoveTrailingStop() {
int l_ord_total_4 = OrdersTotal();
for (int l_pos_0 = 0; l_pos_0 < l_ord_total_4; l_pos_0++) {
OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
if (OrderType() <= OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == g_magic_216) {
if (OrderType() == OP_BUY && NormalizeDouble(Ask - OrderOpenPrice(), Digits) > NormalizeDouble(iATR(NULL, g_timeframe_188, g_period_192, 1) * gd_196, Digits)) {
if (g_period_192 > 0 && Ask > NormalizeDouble(OrderOpenPrice(), Digits)) {
if (NormalizeDouble(OrderStopLoss(), Digits) < NormalizeDouble(Bid - NormalizeDouble(iATR(NULL, g_timeframe_188, g_period_192, 1) * gd_196, Digits), Digits) || OrderStopLoss() == 0.0) {
OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid - NormalizeDouble(iATR(NULL, g_timeframe_188, g_period_192, 1) * gd_196, Digits), Digits), OrderTakeProfit(), 0, Blue);
return;
}
}
}
if (OrderType() == OP_SELL && NormalizeDouble(OrderOpenPrice() - Bid, Digits) > NormalizeDouble(iATR(NULL, g_timeframe_188, g_period_192, 1) * gd_196, Digits)) {
if (g_period_192 > 0 && Bid < NormalizeDouble(OrderOpenPrice(), Digits)) {
if (NormalizeDouble(OrderStopLoss(), Digits) > NormalizeDouble(Ask + NormalizeDouble(iATR(NULL, g_timeframe_188, g_period_192, 1) * gd_196, Digits), Digits) || OrderStopLoss() == 0.0) {
OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask + NormalizeDouble(iATR(NULL, g_timeframe_188, g_period_192, 1) * gd_196, Digits), Digits), OrderTakeProfit(), 0, Red);
return;
}
}
}
}
}
}
int NewBarBuy() {
if (g_time_228 < Time[0]) {
g_time_228 = Time[0];
return (1);
}
return (0);
}
int NewBarSell() {
if (g_time_232 < Time[0]) {
g_time_232 = Time[0];
return (1);
}
return (0);
}
void CalculateMM() {
double l_minlot_0 = MarketInfo(Symbol(), MODE_MINLOT);
double l_maxlot_8 = MarketInfo(Symbol(), MODE_MAXLOT);
Lots = AccountFreeMargin() / 100000.0 * RiskPercent;
Lots = MathMin(l_maxlot_8, MathMax(l_minlot_0, Lots));
if (l_minlot_0 < 0.1) Lots = NormalizeDouble(Lots, 2);
else {
if (l_minlot_0 < 1.0) Lots = NormalizeDouble(Lots, 1);
else Lots = NormalizeDouble(Lots, 0);
}
if (Lots < l_minlot_0) Lots = l_minlot_0;
if (Lots > l_maxlot_8) Lots = l_maxlot_8;
}
==============================================
thanks in advance
rvlv
------------------------------------
**** IMPORTANT PLEASE READ ****
This group is for the discussion between users only.
This is *NOT* technical support channel.
TO GET TECHNICAL SUPPORT send an e-mail directly to
SUPPORT {at} amibroker.com
TO SUBMIT SUGGESTIONS please use FEEDBACK CENTER at
http://www.amibroker.com/feedback/
(submissions sent via other channels won't be considered)
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|