Jump to content

ryujin

Members
  • Posts

    60
  • Joined

  • Last visited

Posts posted by ryujin

  1. Hi guys,

     

    Below is the latest from cable run

     

    ======

     

    /*

    Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []

    Website: http://purebeam.biz

    E-mail : [email protected]

    */

    //#import "MQ4Check.dll"

    // int getKey1();

    //#import

     

    extern int Step = 170;

    extern double FirstLot = 0.1;

    extern double IncLot = 0.0;

    extern int Magic = 2008;

    extern string PlaceTradesFrom = "00:00";

    extern string PlaceTradesTo = "23:59";

    extern double MinProfit = 15.0;

    extern string MaxLoss = "0=none; 1=pips (position with largest loss); 2=percent (all orders)";

    extern int MaxLossMethod = 1;

    extern int MaxLossPips = 100;

    extern int MaxLossPct = 5;

    double g_ord_lots_144 = 0.0;

    double g_ord_lots_152 = 0.0;

    double gd_160;

    double gd_168;

    int gi_176 = 16749022;

    int gi_unused_180 = 1774;

     

    int start() {

    int li_0;

    if (idCheck_unique() != 1) {

    li_0 = MyOrdersTotal(Magic);

    if (GetTotalProfit(Magic) >= MinProfit) {

    DeletePendingOrders(Magic);

    CloseOrders(Magic);

    }

    if (MaxLossMethod == 1 && GetMaxLossPips(Magic) >= MaxLossPips) {

    DeletePendingOrders(Magic);

    CloseOrders(Magic);

    } else {

    if (MaxLossMethod == 2 && GetTotalProfit(Magic) <= (-1.0 * AccountBalance()) * MaxLossPct / 100.0) {

    DeletePendingOrders(Magic);

    CloseOrders(Magic);

    }

    }

    GlobalVariableSet("OldBalance", AccountBalance());

    if (!IsInTimeWindow(PlaceTradesFrom, PlaceTradesTo)) {

    if (li_0 > 0) DeletePendingOrders(Magic);

    Comment("not in trading window");

    } else {

    Comment("in trading window");

    if (li_0 == 0) {

    OrderSend(Symbol(), OP_BUYLIMIT, FirstLot, Ask - Step * Point, 3, 0, 0, "", Magic, 0, Green);

    OrderSend(Symbol(), OP_SELLLIMIT, FirstLot, Bid + Step * Point, 3, 0, 0, "", Magic, 0, Red);

    }

    gd_160 = GetLastSellPrice(Magic);

    gd_168 = GetLastBuyPrice(Magic);

    if (gd_160 - Bid <= 5.0 * Point) OrderSend(Symbol(), OP_SELLLIMIT, g_ord_lots_144 + IncLot, gd_160 + Step * Point, 3, 0, 0, "", Magic, 0, Red);

    if (Ask - gd_168 <= 5.0 * Point) OrderSend(Symbol(), OP_BUYLIMIT, g_ord_lots_152 + IncLot, gd_168 - Step * Point, 3, 0, 0, "", Magic, 0, Red);

    }

    }

    return (0);

    }

     

    int DeletePendingOrders(int a_magic_0) {

    int l_ord_total_4;

    if (idCheck_unique() != 1) {

    l_ord_total_4 = OrdersTotal();

    for (int l_pos_8 = 0; l_pos_8 < l_ord_total_4; l_pos_8++) {

    OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);

    if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol() && OrderType() == OP_BUYLIMIT || OrderType() == OP_SELLLIMIT) OrderDelete(OrderTicket());

    }

    }

    return (0);

    }

     

    int CloseOrders(int a_magic_0) {

    int l_ord_total_4;

    if (idCheck_unique() != 1) {

    l_ord_total_4 = OrdersTotal();

    for (int l_pos_8 = 0; l_pos_8 < l_ord_total_4; l_pos_8++) {

    OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);

    if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol()) {

    if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 3);

    if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 3);

    }

    }

    }

    return (0);

    }

     

    int MyOrdersTotal(int a_magic_0) {

    int l_count_4;

    int l_ord_total_8;

    if (idCheck_unique() != 1) {

    l_count_4 = 0;

    l_ord_total_8 = OrdersTotal();

    for (int l_pos_12 = 0; l_pos_12 < l_ord_total_8; l_pos_12++) {

    OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES);

    if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol()) l_count_4++;

    }

    }

    return (l_count_4);

    }

     

    double GetLastBuyPrice(int a_magic_0) {

    int li_4;

    if (idCheck_unique() != 1) {

    li_4 = OrdersTotal() - 1;

    for (int l_pos_8 = li_4; l_pos_8 >= 0; l_pos_8--) {

    OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);

    if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol() && OrderType() == OP_BUYLIMIT || OrderType() == OP_BUY) {

    g_ord_lots_152 = OrderLots();

    return (OrderOpenPrice());

    }

    }

    }

    return (0);

    }

     

    double GetLastSellPrice(int a_magic_0) {

    int li_4;

    if (idCheck_unique() != 1) {

    li_4 = OrdersTotal() - 1;

    for (int l_pos_8 = li_4; l_pos_8 >= 0; l_pos_8--) {

    OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES);

    if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol() && OrderType() == OP_SELLLIMIT || OrderType() == OP_SELL) {

    g_ord_lots_144 = OrderLots();

    return (OrderOpenPrice());

    }

    }

    }

    return (100000);

    }

     

    int GetMaxLossPips(int a_magic_0) {

    int li_4;

    int li_8;

    bool li_ret_12;

    if (idCheck_unique() != 1) {

    li_ret_12 = FALSE;

    li_4 = OrdersTotal() - 1;

    for (int l_pos_16 = li_4; l_pos_16 >= 0; l_pos_16--) {

    OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);

    if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol() && OrderType() == OP_BUY || OrderType() == OP_SELL) {

    if (OrderType() == OP_BUY) li_8 = Ask - OrderOpenPrice();

    else li_8 = OrderOpenPrice() - Bid;

    if (li_8 < 0 && MathAbs(li_8) > li_ret_12) li_ret_12 = MathAbs(li_8);

    }

    }

    }

    return (li_ret_12);

    }

     

    int GetTotalProfit(int a_magic_0) {

    int li_4;

    double ld_ret_8;

    if (idCheck_unique() != 1) {

    ld_ret_8 = 0;

    li_4 = OrdersTotal() - 1;

    for (int l_pos_16 = li_4; l_pos_16 >= 0; l_pos_16--) {

    OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES);

    if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol() && OrderType() == OP_BUY || OrderType() == OP_SELL) ld_ret_8 += OrderProfit();

    }

    }

    return (ld_ret_8);

    }

     

    bool IsInTimeWindow(string as_0, string as_8) {

    string l_time2str_16;

    if (idCheck_unique() != 1) {

    l_time2str_16 = TimeToStr(TimeCurrent(), TIME_MINUTES);

    if (as_8 > as_0) return (l_time2str_16 >= as_0 && l_time2str_16 <= as_8);

    }

    return (l_time2str_16 >= as_0 || l_time2str_16 <= as_8);

    }

     

    int idCheck_unique() {

    //if (getKey1() == gi_176)

    return (0);

    //return (1);

    }

     

    ======

  2. I have post earlier a function for calculating the profit wich working for me with no problems, and i check with real and backtest and at predefined level it closes the trades.

    for not put again, just please do a search in my previous post and you can use that function.

     

    #post 204

     

    regards,

     

    Hi eggzactly,

     

    I have insert your codes inside the EA. Just want to check with you if I am correct in the EA variables declaration and the function

     

    int pmode;

     

    double Pips = TotalProfit(pmode,Magic);

    if (Pips >= MinProfit){

    CloseAllTrades(0,Magic);

    DeletePendingOrders(Magic);

    }

     

     

    Do I need to put

     

    CloseAllTrades(1, Magic);

    CloseAllTrades(2, Magic);

     

    Since this is declare on top inside the init start()

     

    What does CloseAllTrades(1, Magic); , CloseAllTrades(2, Magic); and CloseAllTrades(0, Magic); means?

  3. Hi muruku,

     

    I have tried your function

     

    double Pips = TotalProfit(Magic);

    if (Pips >= MinProfit){

    CloseAllTrades(0,Magic);

    DeletePendingOrders(Magic);

    }

     

    which called the function below.

     

    int TotalProfit(int Magic)

    {

    int total=OrdersTotal();

    int totalPips = 0;

    for (int cnt=0;cnt<total;cnt++)

    {

    OrderSelect(cnt, SELECT_BY_POS);

    int mode=OrderType();

    bool condition = false;

    if (OrderMagicNumber()== Magic)condition = true;

    if (condition)

    {

    switch (mode)

    {

    case OP_BUY:

    totalPips += MathRound((MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));

    break;

     

    case OP_SELL:

    totalPips += MathRound((OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT));

    break;

    }

    }

    }

    return(totalPips);

    }

     

    I observe my account which is floating more than $30 in profits, but the EA still did not closed all the trades?

     

    By the way, my broker is a 5 digit no, hence, I change the value for step and MinProfit to be 170 and 150

     

    int Step = 170; // org 17 .. still stick to 17

    extern double FirstLot = 0.01; // org 0.10 .. risky .. so just put 0.1

    double IncLot = 0.0; // org 0.0

    double MinProfit = 150; // org 15

     

    Would that be the cause to all orders not closed?

     

     

    Hi eggzactly,

     

    Do u think u can help with this?

  4. Hi muruku,

     

    I have tried your function

     

    double Pips = TotalProfit(Magic);

    if (Pips >= MinProfit){

    CloseAllTrades(0,Magic);

    DeletePendingOrders(Magic);

    }

     

    which called the function below.

     

    int TotalProfit(int Magic)

    {

    int total=OrdersTotal();

    int totalPips = 0;

    for (int cnt=0;cnt<total;cnt++)

    {

    OrderSelect(cnt, SELECT_BY_POS);

    int mode=OrderType();

    bool condition = false;

    if (OrderMagicNumber()== Magic)condition = true;

    if (condition)

    {

    switch (mode)

    {

    case OP_BUY:

    totalPips += MathRound((MarketInfo(OrderSymbol(),MODE_BID)-OrderOpenPrice())/MarketInfo(OrderSymbol(),MODE_POINT));

    break;

     

    case OP_SELL:

    totalPips += MathRound((OrderOpenPrice()-MarketInfo(OrderSymbol(),MODE_ASK))/MarketInfo(OrderSymbol(),MODE_POINT));

    break;

    }

    }

    }

    return(totalPips);

    }

     

    I observe my account which is floating more than $30 in profits, but the EA still did not closed all the trades?

     

    By the way, my broker is a 5 digit no, hence, I change the value for step and MinProfit to be 170 and 150

     

    int Step = 170; // org 17 .. still stick to 17

    extern double FirstLot = 0.01; // org 0.10 .. risky .. so just put 0.1

    double IncLot = 0.0; // org 0.0

    double MinProfit = 150; // org 15

     

    Would that be the cause to all orders not closed?

  5. Clevereto,

     

    you can add this type of code if you want to test the close of pending orders if ATR out of boundaries :

     

    in start put

     

    if (ATROUT()==1) { OrderDeleteLimit();} // where ATROUT the function for check the ATR Limits

     

     

    at the end of the file put

     

    void OrderDeleteLimit()

    {

    for (int i = OrdersTotal() - 1; i >= 0; i--) {

    OrderSelect(i, SELECT_BY_POS, MODE_TRADES);

    if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic && OrderCloseTime() == 0) {

    if (OrderType() == OP_BUYLIMIT ||OrderType() == OP_SELLLIMIT) OrderDelete (OrderTicket());

    }

    }

    }

     

    ------

     

    if not orders at market, you can put this

     

    if (ATROUT()==1) { "Time function not allowed to trade, like NY Session";} // where ATROUT the function for check the ATR Limits

     

    Hope this helps

     

    Regards,

     

    eggzactly

     

    HI Eggzactly,

     

    I have tried putting your code inside the EA and faced errors. Can help to assist to put the codes inside the EA?

     

    Thanks

  6. Hi,

     

    I have just checked my demo ac running this EA. There is a lot of error 130 for the EA to modify the orders?

     

    ====================================

    02:52:46 CableRunII GBPUSDsf,H1: open #12963686 buy limit 0.01 GBPUSDsf at 1.56380 ok

    03:02:37 CableRunII GBPUSDsf,H1: open #12963687 buy limit 0.01 GBPUSDsf at 1.56363 ok

    03:03:46 CableRunII GBPUSDsf,H1: open #12963688 buy limit 0.01 GBPUSDsf at 1.56346 ok

    03:03:46 CableRunII GBPUSDsf,H1: open #12963689 buy limit 0.01 GBPUSDsf at 1.56329 ok

    03:36:37 CableRunII GBPUSDsf,H1: open #12963691 buy limit 0.01 GBPUSDsf at 1.56312 ok

    03:38:12 CableRunII GBPUSDsf,H1: open #12963692 buy limit 0.01 GBPUSDsf at 1.56295 ok

    04:01:13 CableRunII GBPUSDsf,H1: open #12963693 buy limit 0.01 GBPUSDsf at 1.56278 ok

    04:01:13 CableRunII GBPUSDsf,H1: open #12963694 buy limit 0.01 GBPUSDsf at 1.56261 ok

    04:09:15 CableRunII GBPUSDsf,H1: open #12963700 buy limit 0.01 GBPUSDsf at 1.56244 ok

    04:53:13 CableRunII GBPUSDsf,H1: open #12963705 buy limit 0.01 GBPUSDsf at 1.56227 ok

    04:53:13 CableRunII GBPUSDsf,H1: open #12963706 buy limit 0.01 GBPUSDsf at 1.56210 ok

    04:55:41 CableRunII GBPUSDsf,H1: open #12963707 buy limit 0.01 GBPUSDsf at 1.56193 ok

    04:57:29 CableRunII GBPUSDsf,H1: open #12963708 buy limit 0.01 GBPUSDsf at 1.56176 ok

    06:05:49 CableRunII GBPUSDsf,H1: open #12963730 buy limit 0.01 GBPUSDsf at 1.56159 ok

    07:20:00 CableRunII GBPUSDsf,H1: open #12963750 buy limit 0.01 GBPUSDsf at 1.56142 ok

    07:27:25 CableRunII GBPUSDsf,H1: open #12963757 buy limit 0.01 GBPUSDsf at 1.56125 ok

    07:29:58 CableRunII GBPUSDsf,H1: open #12963759 buy limit 0.01 GBPUSDsf at 1.56108 ok

    07:31:55 CableRunII GBPUSDsf,H1: open #12963760 buy limit 0.01 GBPUSDsf at 1.56091 ok

    07:44:12 CableRunII GBPUSDsf,H1: #12963681 Error: 130 Function: NewOrder(2,0.01,1.5609,0,0) 0

    07:44:12 CableRunII GBPUSDsf,H1: #12963681 Error: 130 Function: NewOrder(2,0.01,1.5609,0,0) 1

    07:44:12 CableRunII GBPUSDsf,H1: #12963681 Error: 130 Function: NewOrder(2,0.01,1.5609,0,0) 2

    07:44:12 CableRunII GBPUSDsf,H1: #12963681 Error: 130 Function: NewOrder(2,0.01,1.5609,0,0) 3

    07:44:12 CableRunII GBPUSDsf,H1: #12963681 Error: 130 Function: NewOrder(2,0.01,1.5609,0,0) 4

    07:44:12 CableRunII GBPUSDsf,H1: #12963681 Error: 130 Function: NewOrder(2,0.01,1.5609,0,0) 5

    07:44:12 CableRunII GBPUSDsf,H1: #12963681 Error: 130 Function: NewOrder(2,0.01,1.5609,0,0) 6

    07:44:12 CableRunII GBPUSDsf,H1: #12963681 Error: 130 Function: NewOrder(2,0.01,1.5609,0,0) 7

     

    ============================================================

     

    Can someone fixed this?

×
×
  • Create New...