Jump to content

[Ask] "reverse" function in an ea


tonycashflow

Recommended Posts

Re: [Ask]

 

Hi,

 

well, it is somehow easy to add a reverse function, but that depends on the EA itself.

 

if you me to try, please post your EA here.

 

I still didn't give a lesson on a reverse coding, but for sure on the way.

 

Thanks for your comments.

 

Best of luck.

 

-- 20 Nov 2009, 12:16 --

 

Hi,

 

there is a very simple way how to do that.

 

on top external variables you put this:

 

extern bool ReverseSignal = false;

 

 

And then somewhere in the Start {} function of code, you can use either:

 

if (ReverseSignal)

{

if (myOrderType==1) { myOrderType=2; }

else { if (myOrderType==2) { myOrderType=1; } }

}

 

or

 

bool SignalBUY=false;

bool SignalSELL=false;

 

if(BUY&&(TradePerBar<=MaxTradePerBar))if(ReverseSignal )SignalSELL=true;else SignalBUY=true;

if(SELL&&(TradePerBar<=MaxTradePerBar))if(ReverseSignal )SignalBUY=true;else SignalSELL=true;

 

 

It should be easy somehow for you if you know some basic programming skills.

 

Best wishes,

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

Re: [Ask] "reverse" function in an ea

 

Ok, I have tried but I always get errors : "variable not defined"

 

Obviously i dont know what im doing...

 

I have uploaded the ea, which I think is mod of IAPE/Ilan

 

There are some strategies I want to test using reverse function.

 

Please try to add reverse feature to it.

 

Thanks

 

http://[email protected]/?iwymnxwzixq

Link to comment
Share on other sites

Re: [Ask] "reverse" function in an ea

 

Ok, I have tried but I always get errors : "variable not defined"

 

Obviously i dont know what im doing...

 

I have uploaded the ea, which I think is mod of IAPE/Ilan

 

There are some strategies I want to test using reverse function.

 

Please try to add reverse feature to it.

 

Thanks

 

http://[email protected]/?iwymnxwzixq

 

Hi,

 

Thanks for posting the EA.

 

I understand that you can't get the code the right way. It is fine then.

 

I will get back to you whenever I'm done with it.

 

Best of luck.

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

Re: [Ask] "reverse" function in an ea

 

A fast way to do is to take its current order send functions and switch them (take Ordersend opbuy (***********) and switch its places with Ordersend opsell(*******) as than test it and if it doesn't work out just alt z back into its normal state. Hope this helps.. Ohh i see what you mean its a pain in the a** because it uses 6 different order send functions..

 

-- 20 Nov 2009, 12:28 --

 

Here this should work..

/*
  Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
  Website: [url]http://purebeam.biz[/url]
  E-mail : [email][email protected][/email]
*/
int gi_76 = 1;
bool gi_80 = FALSE;
bool gi_84 = TRUE;
extern double LotExponent = 1.2;
double g_slippage_96 = 5.0;
extern double Lots = 0.1;
double gd_112 = 1.0;
extern double TakeProfit = 10.0;
extern double StopLoss = 0.0;
double gd_136 = 0.0;
double gd_144 = 0.0;
extern double Step = 7.0;
extern int MaxTrades = 20;
extern bool EquityStop = FALSE;
extern double AccountPercent = 20.0;
extern bool Trailing = FALSE;
extern bool TimeOut = FALSE;
extern double Hours = 0.0;
extern bool TimeFilter = FALSE;
extern int StartHour = 2;
extern int EndHour = 16;
extern int MagicNumber = 11111;
double g_price_208;
double gd_216;
double gd_unused_224;
double gd_unused_232;
double g_price_240;
double g_bid_248;
double g_ask_256;
double gd_264;
double gd_272;
double gd_280;
bool gi_288;
string gs_292 = "Robot Forex";
int g_time_300 = 0;
int gi_304;
int gi_308 = 0;
double gd_312;
int g_pos_320 = 0;
int gi_324;
double gd_328 = 0.0;
bool gi_336 = FALSE;
bool gi_340 = FALSE;
bool gi_344 = FALSE;
int gi_348;
bool gi_352 = FALSE;
int g_datetime_356 = 0;
int g_datetime_360 = 0;
double gd_364;
double gd_372;

int init() {
  gd_280 = MarketInfo(Symbol(), MODE_SPREAD) * Point;
  if (IsTesting() == TRUE) Display_Info();
  if (IsTesting() == FALSE) Display_Info();
  return (0);
}

int deinit() {
  return (0);
}

int start() {
  double l_ord_lots_0;
  double l_ord_lots_8;
  double l_iclose_16;
  double l_iclose_24;
  string ls_32 = "false";
  string ls_40 = "false";
  if (TimeFilter == FALSE || (TimeFilter && (EndHour > StartHour && (Hour() >= StartHour && Hour() <= EndHour)) || (StartHour > EndHour && !(Hour() >= EndHour && Hour() <= StartHour)))) ls_32 = "true";
  if (TimeFilter && (EndHour > StartHour && !(Hour() >= StartHour && Hour() <= EndHour)) || (StartHour > EndHour && (Hour() >= EndHour && Hour() <= StartHour))) ls_40 = "true";
  if (Trailing) TrailingAlls(gd_136, gd_144, g_price_240);
  if (TimeOut) {
     if (TimeCurrent() >= gi_304) {
        CloseThisSymbolAll();
        Print("Closed All due to TimeOut");
     }
  }
  if (g_time_300 == Time[0]) return (0);
  g_time_300 = Time[0];
  double ld_48 = CalculateProfit();
  if (EquityStop) {
     if (ld_48 < 0.0 && MathAbs(ld_48) > AccountPercent / 100.0 * AccountEquityHigh()) {
        CloseThisSymbolAll();
        Print("Closed All due to Stop Out");
        gi_352 = FALSE;
     }
  }
  gi_324 = CountTrades();
  if (gi_324 == 0) gi_288 = FALSE;
  for (g_pos_320 = OrdersTotal() - 1; g_pos_320 >= 0; g_pos_320--) {
     OrderSelect(g_pos_320, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
     if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
        if (OrderType() == OP_BUY) {
           gi_340 = TRUE;
           gi_344 = FALSE;
           l_ord_lots_0 = OrderLots();
           break;
        }
     }
     if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
        if (OrderType() == OP_SELL) {
           gi_340 = FALSE;
           gi_344 = TRUE;
           l_ord_lots_8 = OrderLots();
           break;
        }
     }
  }
  if (gi_324 > 0 && gi_324 <= MaxTrades) {
     RefreshRates();
     gd_264 = FindLastBuyPrice();
     gd_272 = FindLastSellPrice();
     if (gi_340 && gd_264 - Ask >= Step * Point) gi_336 = TRUE;
     if (gi_344 && Bid - gd_272 >= Step * Point) gi_336 = TRUE;
  }
  if (gi_324 < 1) {
     gi_344 = FALSE;
     gi_340 = FALSE;
     gi_336 = TRUE;
     gd_216 = AccountEquity();
  }
  if (gi_336) {
     gd_264 = FindLastBuyPrice();
     gd_272 = FindLastSellPrice();
     if (gi_344) {
        if (gi_80 || ls_40 == "true") {
           fOrderCloseMarket(0, 1);
           gd_312 = NormalizeDouble(LotExponent * l_ord_lots_8, gd_112);
        } else gd_312 = fGetLots(OP_SELL);
        if (gi_84 && ls_32 == "true") {
           gi_308 = gi_324;
           if (gd_312 > 0.0) {
              RefreshRates();
              gi_348 = OpenPendingOrder(1, gd_312, Bid, g_slippage_96, Ask, 0, 0, gs_292 + "-" + gi_308, MagicNumber, 0, HotPink);
              if (gi_348 < 0) {
                 Print("Error: ", GetLastError());
                 return (0);
              }
              gd_272 = FindLastSellPrice();
              gi_336 = FALSE;
              gi_352 = TRUE;
           }
        }
     } else {
        if (gi_340) {
           if (gi_80 || ls_40 == "true") {
              fOrderCloseMarket(1, 0);
              gd_312 = NormalizeDouble(LotExponent * l_ord_lots_0, gd_112);
           } else gd_312 = fGetLots(OP_BUY);
           if (gi_84 && ls_32 == "true") {
              gi_308 = gi_324;
              if (gd_312 > 0.0) {
                 gi_348 = OpenPendingOrder(0, gd_312, Ask, g_slippage_96, Bid, 0, 0, gs_292 + "-" + gi_308, MagicNumber, 0, Lime);
                 if (gi_348 < 0) {
                    Print("Error: ", GetLastError());
                    return (0);
                 }
                 gd_264 = FindLastBuyPrice();
                 gi_336 = FALSE;
                 gi_352 = TRUE;
              }
           }
        }
     }
  }
  if (gi_336 && gi_324 < 1) {
     l_iclose_16 = iClose(Symbol(), 0, 2);
     l_iclose_24 = iClose(Symbol(), 0, 1);
     g_bid_248 = Bid;
     g_ask_256 = Ask;
     if (!gi_344 && !gi_340 && ls_32 == "true") {
        gi_308 = gi_324;
        if (l_iclose_16 > l_iclose_24) {
           gd_312 = fGetLots(OP_SELL);
           if (gd_312 > 0.0) {
              gi_348 = OpenPendingOrder(1, gd_312, g_bid_248, g_slippage_96, g_bid_248, 0, 0, gs_292 + "-" + gi_308, MagicNumber, 0, HotPink);
              if (gi_348 < 0) {
                 Print(gd_312, "Error: ", GetLastError());
                 return (0);
              }
              gd_264 = FindLastBuyPrice();
              gi_352 = TRUE;
           }
        } else {
           gd_312 = fGetLots(OP_BUY);
           if (gd_312 > 0.0) {
              gi_348 = OpenPendingOrder(0, gd_312, g_ask_256, g_slippage_96, g_ask_256, 0, 0, gs_292 + "-" + gi_308, MagicNumber, 0, Lime);
              if (gi_348 < 0) {
                 Print(gd_312, "Error: ", GetLastError());
                 return (0);
              }
              gd_272 = FindLastSellPrice();
              gi_352 = TRUE;
           }
        }
     }
     if (gi_348 > 0) gi_304 = TimeCurrent() + 60.0 * (60.0 * Hours);
     gi_336 = FALSE;
  }
  gi_324 = CountTrades();
  g_price_240 = 0;
  double ld_56 = 0;
  for (g_pos_320 = OrdersTotal() - 1; g_pos_320 >= 0; g_pos_320--) {
     OrderSelect(g_pos_320, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
     if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
        if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
           g_price_240 += OrderOpenPrice() * OrderLots();
           ld_56 += OrderLots();
        }
     }
  }
  if (gi_324 > 0) g_price_240 = NormalizeDouble(g_price_240 / ld_56, Digits);
  if (gi_352) {
     for (g_pos_320 = OrdersTotal() - 1; g_pos_320 >= 0; g_pos_320--) {
        OrderSelect(g_pos_320, SELECT_BY_POS, MODE_TRADES);
        if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
           if (OrderType() == OP_BUY) {
              g_price_208 = g_price_240 + TakeProfit * Point;
              gd_unused_224 = g_price_208;
              gd_328 = g_price_240 - StopLoss * Point;
              gi_288 = TRUE;
           }
        }
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
           if (OrderType() == OP_SELL) {
              g_price_208 = g_price_240 - TakeProfit * Point;
              gd_unused_232 = g_price_208;
              gd_328 = g_price_240 + StopLoss * Point;
              gi_288 = TRUE;
           }
        }
     }
  }
  if (gi_352) {
     if (gi_288 == TRUE) {
        for (g_pos_320 = OrdersTotal() - 1; g_pos_320 >= 0; g_pos_320--) {
           OrderSelect(g_pos_320, SELECT_BY_POS, MODE_TRADES);
           if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
           if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) OrderModify(OrderTicket(), g_price_240, OrderStopLoss(), g_price_208, 0, Yellow);
           gi_352 = FALSE;
        }
     }
  }
  return (0);
}

double ND(double ad_0) {
  return (NormalizeDouble(ad_0, Digits));
}

int fOrderCloseMarket(bool ai_0 = TRUE, bool ai_4 = TRUE) {
  int li_ret_8 = 0;
  for (int l_pos_12 = OrdersTotal() - 1; l_pos_12 >= 0; l_pos_12--) {
     if (OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES)) {
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
           if (OrderType() == OP_BUY && ai_0) {
              RefreshRates();
              if (!IsTradeContextBusy()) {
                 if (!OrderClose(OrderTicket(), OrderLots(), ND(Bid), 5, CLR_NONE)) {
                    Print("Error close BUY " + OrderTicket());
                    li_ret_8 = -1;
                 }
              } else {
                 if (g_datetime_356 != iTime(NULL, 0, 0)) {
                    g_datetime_356 = iTime(NULL, 0, 0);
                    Print("Need close BUY " + OrderTicket() + ". Trade Context Busy");
                 }
                 return (-2);
              }
           }
           if (OrderType() == OP_SELL && ai_4) {
              RefreshRates();
              if (!IsTradeContextBusy()) {
                 if (!OrderClose(OrderTicket(), OrderLots(), ND(Ask), 5, CLR_NONE)) {
                    Print("Error close SELL " + OrderTicket());
                    li_ret_8 = -1;
                 }
              } else {
                 if (g_datetime_360 != iTime(NULL, 0, 0)) {
                    g_datetime_360 = iTime(NULL, 0, 0);
                    Print("Need close SELL " + OrderTicket() + ". Trade Context Busy");
                 }
                 return (-2);
              }
           }
        }
     }
  }
  return (li_ret_8);
}

double fGetLots(int a_cmd_0) {
  double l_lots_4;
  int l_datetime_12;
  switch (gi_76) {
  case 0:
     l_lots_4 = Lots;
     break;
  case 1:
     l_lots_4 = NormalizeDouble(Lots * MathPow(LotExponent, gi_308), gd_112);
     break;
  case 2:
     l_datetime_12 = 0;
     l_lots_4 = Lots;
     for (int l_pos_20 = OrdersHistoryTotal() - 1; l_pos_20 >= 0; l_pos_20--) {
        if (OrderSelect(l_pos_20, SELECT_BY_POS, MODE_HISTORY)) {
           if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
              if (l_datetime_12 < OrderCloseTime()) {
                 l_datetime_12 = OrderCloseTime();
                 if (OrderProfit() < 0.0) l_lots_4 = NormalizeDouble(OrderLots() * LotExponent, gd_112);
                 else l_lots_4 = Lots;
              }
           }
        } else return (-3);
     }
  }
  if (AccountFreeMarginCheck(Symbol(), a_cmd_0, l_lots_4) <= 0.0) return (-1);
  if (GetLastError() == 134/* NOT_ENOUGH_MONEY */) return (-2);
  return (l_lots_4);
}

int CountTrades() {
  int l_count_0 = 0;
  for (int l_pos_4 = OrdersTotal() - 1; l_pos_4 >= 0; l_pos_4--) {
     OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
     if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
        if (OrderType() == OP_SELL || OrderType() == OP_BUY) l_count_0++;
  }
  return (l_count_0);
}

void CloseThisSymbolAll() {
  for (int l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) {
     OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol() == Symbol()) {
        if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
           if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, g_slippage_96, Blue);
           if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, g_slippage_96, Red);
        }
        Sleep(1000);
     }
  }
}

int OpenPendingOrder(int ai_0, double a_lots_4, double a_price_12, int a_slippage_20, double ad_24, int ai_unused_32, int ai_36, string a_comment_40, int a_magic_48, int a_datetime_52, color a_color_56) {
  int l_ticket_60 = 0;
  int l_error_64 = 0;
  int l_count_68 = 0;
  int li_72 = 100;
  switch (ai_0) {
  case 2:
     for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) {
        l_ticket_60 = OrderSend(Symbol(), OP_SELLLIMIT, a_lots_4, a_price_12, a_slippage_20, StopShort(ad_24, StopLoss), TakeShort(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56);
        l_error_64 = GetLastError();
        if (l_error_64 == 0/* NO_ERROR */) break;
        if (!((l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */))) break;
        Sleep(5000);
     }
     break;
  case 4:
    for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) {
        l_ticket_60 = OrderSend(Symbol(), OP_SELLSTOP, a_lots_4, a_price_12, a_slippage_20, StopShort(ad_24, StopLoss), TakeShort(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56);
        l_error_64 = GetLastError();
        if (l_error_64 == 0/* NO_ERROR */) break;
        if (!((l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */))) break;
        Sleep(5000);
     }
     break;
  case 0:
    for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) {
        l_ticket_60 = OrderSend(Symbol(), OP_SELL, a_lots_4, Bid, a_slippage_20, StopShort(Ask, StopLoss), TakeShort(Bid, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56);
        l_error_64 = GetLastError();
        if (l_error_64 == 0/* NO_ERROR */) break;
        if (!((l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */))) break;
        Sleep(5000);
     }
     break;
  case 3: 
   for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) {
        l_ticket_60 = OrderSend(Symbol(), OP_BUYLIMIT, a_lots_4, a_price_12, a_slippage_20, StopLong(ad_24, StopLoss), TakeLong(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56);
        l_error_64 = GetLastError();
        if (l_error_64 == 0/* NO_ERROR */) break;
        if (!((l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */))) break;
        Sleep(1000);
     }
     
   
     break;
  case 5:  
  for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) {
        l_ticket_60 = OrderSend(Symbol(), OP_BUYSTOP, a_lots_4, a_price_12, a_slippage_20, StopLong(ad_24, StopLoss), TakeLong(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56);
        l_error_64 = GetLastError();
        if (l_error_64 == 0/* NO_ERROR */) break;
        if (!((l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */))) break;
        Sleep(5000);
     }
    
     break;
  case 1:  
    for (l_count_68 = 0; l_count_68 < li_72; l_count_68++) {
        RefreshRates();
        l_ticket_60 = OrderSend(Symbol(), OP_BUY, a_lots_4, Ask, a_slippage_20, StopLong(Bid, StopLoss), TakeLong(Ask, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56);
        l_error_64 = GetLastError();
        if (l_error_64 == 0/* NO_ERROR */) break;
        if (!((l_error_64 == 4/* SERVER_BUSY */ || l_error_64 == 137/* BROKER_BUSY */ || l_error_64 == 146/* TRADE_CONTEXT_BUSY */ || l_error_64 == 136/* OFF_QUOTES */))) break;
        Sleep(5000);
     }
  
  }
  return (l_ticket_60);
}

double StopLong(double ad_0, int ai_8) {
  if (ai_8 == 0) return (0);
  return (ad_0 - ai_8 * Point);
}

double StopShort(double ad_0, int ai_8) {
  if (ai_8 == 0) return (0);
  return (ad_0 + ai_8 * Point);
}

double TakeLong(double ad_0, int ai_8) {
  if (ai_8 == 0) return (0);
  return (ad_0 + ai_8 * Point);
}

double TakeShort(double ad_0, int ai_8) {
  if (ai_8 == 0) return (0);
  return (ad_0 - ai_8 * Point);
}

double CalculateProfit() {
  double ld_ret_0 = 0;
  for (g_pos_320 = OrdersTotal() - 1; g_pos_320 >= 0; g_pos_320--) {
     OrderSelect(g_pos_320, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
     if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
        if (OrderType() == OP_BUY || OrderType() == OP_SELL) ld_ret_0 += OrderProfit();
  }
  return (ld_ret_0);
}

void TrailingAlls(int ai_0, int ai_4, double a_price_8) {
  int li_16;
  double l_ord_stoploss_20;
  double l_price_28;
  if (ai_4 != 0) {
     for (int l_pos_36 = OrdersTotal() - 1; l_pos_36 >= 0; l_pos_36--) {
        if (OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES)) {
           if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
           if (OrderSymbol() == Symbol() || OrderMagicNumber() == MagicNumber) {
              if (OrderType() == OP_BUY) {
                 li_16 = NormalizeDouble((Bid - a_price_8) / Point, 0);
                 if (li_16 < ai_0) continue;
                 l_ord_stoploss_20 = OrderStopLoss();
                 l_price_28 = Bid - ai_4 * Point;
                 if (l_ord_stoploss_20 == 0.0 || (l_ord_stoploss_20 != 0.0 && l_price_28 > l_ord_stoploss_20)) OrderModify(OrderTicket(), a_price_8, l_price_28, OrderTakeProfit(), 0, Aqua);
              }
              if (OrderType() == OP_SELL) {
                 li_16 = NormalizeDouble((a_price_8 - Ask) / Point, 0);
                 if (li_16 < ai_0) continue;
                 l_ord_stoploss_20 = OrderStopLoss();
                 l_price_28 = Ask + ai_4 * Point;
                 if (l_ord_stoploss_20 == 0.0 || (l_ord_stoploss_20 != 0.0 && l_price_28 < l_ord_stoploss_20)) OrderModify(OrderTicket(), a_price_8, l_price_28, OrderTakeProfit(), 0, Red);
              }
           }
           Sleep(1000);
        }
     }
  }
}

double AccountEquityHigh() {
  if (CountTrades() == 0) gd_364 = AccountEquity();
  if (gd_364 < gd_372) gd_364 = gd_372;
  else gd_364 = AccountEquity();
  gd_372 = AccountEquity();
  return (gd_364);
}

double FindLastBuyPrice() {
  double l_ord_open_price_0;
  int l_ticket_8;
  double ld_unused_12 = 0;
  int l_ticket_20 = 0;
  for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--) {
     OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
     if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) {
        l_ticket_8 = OrderTicket();
        if (l_ticket_8 > l_ticket_20) {
           l_ord_open_price_0 = OrderOpenPrice();
           ld_unused_12 = l_ord_open_price_0;
           l_ticket_20 = l_ticket_8;
        }
     }
  }
  return (l_ord_open_price_0);
}

double FindLastSellPrice() {
  double l_ord_open_price_0;
  int l_ticket_8;
  double ld_unused_12 = 0;
  int l_ticket_20 = 0;
  for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--) {
     OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES);
     if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
     if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) {
        l_ticket_8 = OrderTicket();
        if (l_ticket_8 > l_ticket_20) {
           l_ord_open_price_0 = OrderOpenPrice();
           ld_unused_12 = l_ord_open_price_0;
           l_ticket_20 = l_ticket_8;
        }
     }
  }
  return (l_ord_open_price_0);
}

void Display_Info() {
  Comment("Robot Forex\n", "Forex Account Server:", AccountServer(), 
     "\n", "Lots:  ", Lots, 
     "\n", "Symbol: ", Symbol(), 
     "\n", "Price:  ", NormalizeDouble(Bid, 4), 
     "\n", "Date: ", Month(), "-", Day(), "-", Year(), " Server Time: ", Hour(), ":", Minute(), ":", Seconds(), 
  "\n");
}

[spoiler:26ukmy10]Never trust, never fear, never beg[/spoiler:26ukmy10]
Link to comment
Share on other sites

Re: [Ask] "reverse" function in an ea

 

A fast way to do is to take its current order send functions and switch them (take Ordersend opbuy (***********) and switch its places with Ordersend opsell(*******) as than test it and if it doesn't work out just alt z back into its normal state. Hope this helps.. Ohh i see what you mean its a pain in the a** because it uses 6 different order send functions..

 

-- 20 Nov 2009, 12:28 --

 

Here this should work..

 

It looks like it worked, I opened both the original and your modified version on same terminal and they opened trades in opposite direction at the same time. =D>

 

Thanks both for you help. Will do some further testing but im pretty sure it works.

 

-- 21 Nov 2009, 10:23 --

 

After further testing, there is a problem with your version. The original open trades always in the same direction until they are all closed. However, your modified version will sometimes open trades in opposite direction at the same time. You might have missed a line or two when you modified the code. Can you please check it out?

 

Meanwhile, Ill try to look at what you did and correct it myself.

 

Thanks

Link to comment
Share on other sites

  • 3 weeks later...

Re: [Ask] "reverse" function in an ea

 

can we apply that function to open/closed many pair in one time?

 

Hi.

 

Good day,

 

I believe you can apply this function at only main signals, which is buying and selling signals so the closing and opening will be opposite in this case if using the reverse function.

 

I hope this info is useful.

 

Best wishes,

a New Year 2011 has come, and the challenge has just started 8-)
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...