MT4 - Stop Management for specific order. - page 2

 
TJmclovin:

Brilliant! Cheers!


Edit: Wait..aren't scripts supposed to be executed just once? How can a script "manage" a trade by changing stops? Or did you mean that my EA will look for the magic numbers and than manage the trades?

So WHR has suggested you open positions using a special script because if you open a position manually it doesn't get given a magic number and you can't give it a magic number afterwards. So, by opening a position using a unique script you can give that position a unique magic number. The script then closes itself and goes away, that is correct. But you want to manage the positions with an EA, which you can do now that the position has been "marked" with its particular magic number.
 
dabbler:
So WHR has suggested you open positions using a special script because if you open a position manually it doesn't get given a magic number and you can't give it a magic number afterwards. So, by opening a position using a unique script you can give that position a unique magic number. The script then closes itself and goes away, that is correct. But you want to manage the positions with an EA, which you can do now that the position has been "marked" with its particular magic number.

Ok, that is now clear to me. Cheers. One further question: There is no possibility for giving a script input parameters am I correct?
I mean, if I'm using a script to open my orders it would be nice to set my stop loss and thus my lot size for risk management because I'm actually calculating my lot size on my initial risk in pips. So I don't say I want 20pips stop loss but go the other way around: First, I am checking my initial stop loss than I check my balance and use let's say 1% of it as the risk of this trade --> than I am going to calculate the lot size.
 
TJmclovin:

Ok, that is now clear to me. Cheers. One further question: There is no possibility for giving a script input parameters am I correct

Yes you can . . . add . . .

#property show_inputs

and the Inputs screen will be shown when you start the script.

 
RaptorUK:

Yes you can . . . add . . .

and the Inputs screen will be shown when you start the script.


Perfect. I don't know why I didn't find this by myself. But thanks again for everything! I think everything is clear to me right now. At least it seems so :) I will ask again if I encounter any more problems though :D
 
TJmclovin:
Edit: Wait..aren't scripts supposed to be executed just once? How can a script "manage" a trade by changing stops? Or did you mean that my EA will look for the magic numbers and than manage the trades?
A script doesn't have to close until it's order is closed any more than a EA must return from start().
int start(){
    // Open trade here
    while( !IsStopped() ){
        int count = 0;
        for(int iPos = OrdersTotal()-1; iPos >= 0 ; iPos--) if (
            OrderSelect(iPos, SELECT_BY_POS)                // Only my orders w/
        &&  OrderMagicNumber()  == Magic.Number             // my magic number
        &&  OrderSymbol()       == chart.symbol             // and my pair.
        ){  count++;
            // Manage trade here
        }
        if (count == 0 || IsTesting()) break;
        Sleep(1000); RefreshRates();
    }
}
 
WHRoeder:
A script doesn't have to close until it's order is closed any more than a EA must return from start().

Ahhh...yes this is indeed exactly what I've been looking for!Simple while-loop will do the job. Thanks again for the nice support guys!
Reason: