أخي العزيز ...
وجدت لك إجابة كاملة لطلبك فأرجو أن تكون واضحة لديك وهي كالتالي ...
There are three functions with pre-defined names in MQL4:
init() is a function to be called during the module initialization. If it is not available, no function will be called at initialization.
start() is the basic function. For experts, it is called after the next tick has income. For custom indicators, it is called at recalculation after the indicator has been attached to the chart, at opening of the client terminal (if the indicator is attached to the chart), and after the next tick has income, as well. For scripts, it is executed immediately after the script has been attached to the chart and initialized. If there is no start() function in the module, the module (expert, script, or custom indicator) cannot be launched.
deinit() is a function to be called during deinitialization of the module. If it is not available, no function will be called at deinitialization.
Pre-defined functions can have some parameters. However, no parameters will be taken from outside when these functions are called by the client terminal, but the default values will be used. Functions of start(), init(), and deinit() can be called from any point of the module according to the common rules, equally to other functions.
It is not recommended to call start() function from init() function or to perform trade operations, as chart data, market prices, etc. can be incomplete by the moment of the module initialization. The init() and deinit() functions must finish their working as soon as possible and, in no case, shall they loop when trying to start its full-fledged working before the start() function is called.
أما بالنسبة للستوب المتحرك فأنا شخصيا أستخدم الكود التالي كقالب جاهز وأعمل عليه التغيرات الطفيفة لكي يتلائم مع طلبي ...
كود PHP:
[left]extern double TrStop = 20;
...
...
...
void Start(){
...
...
...
if (ExistPositions()){ // دالة تعمل في حالة وجود صفقة مفتوحة من زوج معين
Comment("\nT R A D I N G !!!");
if(TrStop !=0){ // يجب أن يكون الستوب المتحرك لايساوي صفر وإلا هذا يعني بأننا لانستخدمه
TrailingPositionsBuy(TrStop);
TrailingPositionsSell(TrStop);
}
}//end of Start()
bool ExistPositions() { //دالة للكشف عن وجود صفقة مفتوحة من زوج معين أم لا
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
return(True);
}
}
}
return(false);
}
void TrailingPositionsBuy(int trailingStop) { //الستوب المتحرك في حالة اللونق
for (int i=0; i<OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
if (OrderType()==OP_BUY) {
if (Bid-OrderOpenPrice()>trailingStop*Point) {
if (OrderStopLoss()<Bid-trailingStop*Point)
ModifyStopLoss(Bid-trailingStop*Point);
}
}
}
}
}
}
void TrailingPositionsSell(int trailingStop) { //الستوب المتحرك في حالة الشورت
for (int i=0; i<OrdersTotal(); i++) {
if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
if (OrderSymbol()==Symbol() && OrderMagicNumber()==MAGIC) {
if (OrderType()==OP_SELL) {
if (OrderOpenPrice()-Ask>trailingStop*Point) {
if (OrderStopLoss()>Ask+trailingStop*Point || OrderStopLoss()==0)
ModifyStopLoss(Ask+trailingStop*Point);
}
}
}
}
}
}
void ModifyStopLoss(double ldStopLoss) { //دالة تعديل الستوب يتم مناداتها من دالة الستوب المتحرك
bool fm;
fm = OrderModify(OrderTicket(),OrderOpenPrice(),ldStopLoss,OrderTakeProfit(),0,CLR_NONE);
if (fm && UseSound) PlaySound("falsh.wav");
}
[/left]
[right][/right]
أرجو أن تكون هذه الإجابة كافية لديك.
عموما البرمجة أسهل ما يتصور الكثيرون ... بس تتطلب لو لديك فكرة مسبقة عن إحدى لغات البرمجة وبالأخص لغة السي والباقي يأتي لوحده إن شاء الله.
وفقكم الله