Problem with EA code 2 (SL manager) - page 4

 
diostar:

Chances are this may offer some assistance, I hope.

Initially, my symbols was 4 digits, all trailing stops, stop/limit orders modify, went just as expected. Then my broker decided to go fractional. I made the necessary changes and saw my pips went like -3.4, -4.5, 0.1, 4.6, 7.3, etc, etc. I thought this was ok, but actually not: Suppose I set my limit=7, and say, new tick 1,tick 2,tick 3 happen sequentially:

1) 7.3>limit, then order is modified... broker fills 1 slippage off...

2) 7.5>limit, then order is modified....broker fills 0 slippage...

3) 7.1>limit, then order is modified...broker fills 2 slippage off...

So all in all, I get my orders modifed 3 times for all 3 ticks. having realise this, I decided to use MathRound() to round those to nearest integer, so 1,2,3 becomes

1) mathround(7.3) =7 >limit, NOT TRUE, not modified

2) mathround(7.5)=8 >limit, TRUE, order is modified

3) mathround(7.1)=7>limit, NOT TRUE, not modified

Actually Im still working on how to improve the above...so far they are working ok, but I think there must be better ways, than mine.


Awesome Diostar, that is very very useful information to me actually, especially that bit I highlighed.

So if I fix my problem, the best I can hope for is:

every time my conditions are satisfied at gap 00, 01, 02 etc, the best I can hope for is 1,2,3 (respectively) scroll thoughs of each hey. So at gap 03 it will modify my order 02,01,00, then 01,00,02 then 00,02,01 until all the orders are modified? If I scroll them forwards the same thing, but different order etc...

I think I might be ok if this happens actually... however I might find the same as you later on and want to tighten it up, but I am happy to tackle one bridge at a time.. Thanks for the foresight though!!

still about to try that forumula...

 
that formula went well too, thanks for the support there Diostar, I was chasing my tail around for ages learning code, thanks..
 

As always the way hey, in hindsight to think of a different solution.....

Just for my learning, would the below block of worked as an alternative work-around to my problem before?


//---------------------------old attempt where it spammed modifies--------------------------------------
//---------------------------I got around this problem another way before-------------------------------
void ModifySellBlock()
{
    for (int i=OrdersTotal()-1; i >= 0; i--)
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES))
    {
        if (OrderType() == OP_SELL && OrderSymbol() == Symbol() && OrderMagicNumber() == SELL_Magic01)
        { 
            double Level_00_SL = Bid + Stoploss_Level_00*PipValue*Point;
            if (Stoploss_Level_00 == 0) Level_00_SL = 0;
            double Level_00_TP = Bid - Takeprofit_Level_00*PipValue*Point;
            if (Takeprofit_Level_00 == 0) Level_00_TP = 0;
            bool ret00 = OrderModify(OrderTicket(), OrderOpenPrice(), Level_00_SL, Level_00_TP, 0, Modify_Order_Colour);
            if (ret00 == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
    }
    
}

//-----------------------------however I am wondering now that I have fixed it------------------
//------------------------------would this of worked below?-------------------------------------

void ModifySellBlock()
{
    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[30][2];
    for (int i = 0; i < orderstotal; i++)
    {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
        if (OrderType() != OP_SELL || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
        {
            continue;
        }
        ordticket[orders][0] = OrderOpenTime();
        ordticket[orders][1] = OrderTicket();
        orders++;
    }
    if (orders > 1)
    {
        ArrayResize(ordticket,orders);
        ArraySort(ordticket);
    }
    for (i = 0; i < orders; i++)
    {
        if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)
        {
            double Level_00_SL = Bid + Stoploss_Level_00*PipValue*Point;
            if (Stoploss_Level_00 == 0) Level_00_SL = 0;
            double Level_00_TP = Bid - Takeprofit_Level_00*PipValue*Point;
            if (Takeprofit_Level_00 == 0) Level_00_TP = 0;
            bool ret00 = OrderModify(OrderTicket(), OrderOpenPrice(), Level_00_SL, Level_00_TP, 0, Modify_Order_Colour);
            if (ret00 == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
    }
    
}

//--------------------------any problems with this block?----------------------------------------------
 
 
//-----------------------------however I am wondering now that I have fixed it------------------
//------------------------------would this of worked below?-------------------------------------

void ModifySellBlock()
{
    int orderstotal = OrdersTotal();
    int orders = 0;
    int ordticket[30][2];<-----then, arrayinitialize
    
    for (int i = 0; i < orderstotal; i++)
    {
        OrderSelect(i, SELECT_BY_POS, MODE_TRADES);<-----if(orderselect...

        if (OrderType() != OP_SELL || OrderSymbol() != Symbol() || OrderMagicNumber() != 1)
        {
            continue;
        }
        ordticket[orders][0] = OrderOpenTime();
        ordticket[orders][1] = OrderTicket();
        orders++;
    }
    if (orders > 1)<----orders >0
    {
        ArrayResize(ordticket,orders);
        ArraySort(ordticket);
    }
    for (i = 0; i < orders; i++)
    {
        if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET) == true)<---if (OrderSelect(ordticket[i][1], SELECT_BY_TICKET)

        {
            double Level_00_SL = Bid + Stoploss_Level_00*PipValue*Point;
            if (Stoploss_Level_00 == 0) Level_00_SL = 0;
            double Level_00_TP = Bid - Takeprofit_Level_00*PipValue*Point;
            if (Takeprofit_Level_00 == 0) Level_00_TP = 0;      
         
            can consider if(SL>0 || TP>0){
          
            bool ret00 = OrderModify(OrderTicket(), OrderOpenPrice(), Level_00_SL, Level_00_TP, 0, Modify_Order_Colour);
            if (ret00 == false)
            Print("OrderModify() error - ", ErrorDescription(GetLastError()));
        }
    }
    
}
 
diostar:


Thanks for your time with that Diostar. At the time, I did not have the knowledge to have even come up with this idea. Even now I sort of remoddled it from a few peices of code as I am still learning how to make ARRAYS...

I honestly can not believe how hard it was to make a section of code, that just SELECTS ALL ORDERS, and MODIFIES THEM ONCE... if the data flow was sent here EVERYTICK...

I apprecaite your time with your additions, I will give them a go... Hey also Diostar, I believe I am noticing what you said before too, thanks for the foresight so I know it was not my code.... I do see scrolling through the modifies (* #orders I have going), and I do notice slippage coming into it... i will keep you posted if I get around it, possibly with the above code as a start to be honest, thanks again ;)

 
Funky:


Thanks for your time with that Diostar. At the time, I did not have the knowledge to have even come up with this idea. Even now I sort of remoddled it from a few peices of code as I am still learning how to make ARRAYS...

I honestly can not believe how hard it was to make a section of code, that just SELECTS ALL ORDERS, and MODIFIES THEM ONCE... if the data flow was sent here EVERYTICK...

I apprecaite your time with your additions, I will give them a go... Hey also Diostar, I believe I am noticing what you said before too, thanks for the foresight so I know it was not my code.... I do see scrolling through the modifies (* #orders I have going), and I do notice slippage coming into it... i will keep you posted if I get around it, possibly with the above code as a start to be honest, thanks again ;)

Your welcome. Slippage, just like the spread, do off-quote the outcome in any modification price, sl, tp. But I always ordersend() with slippage zero, still. It may be good to have 1,2 points, but so far, so good.

Reason: