Einzelnen Beitrag anzeigen
  #13 (permalink)  
Alt 16.05.16
DariusK DariusK ist offline
Neues Mitglied
 
Registriert seit: May 2012
Beiträge: 11
DariusK befindet sich auf einem aufstrebenden Ast
Standard

Ich habe es etwas verändert, wegen dem Sleep, Die Zeit für Sleepa sollte nicht zu hoch sein, so vielleicht 1.0 oder 1.5....probiere zur Zeit real aus...es geht...


extern bool MTakeProfit=true;
extern bool MStopLoss=true;
extern double TakeProfit=30;
extern double StopLoss=30;
extern double Sleepa=1;
extern int magicNumber = 0;

//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{

int StopMultd=10;
double TP=NormalizeDouble(TakeProfit*StopMultd,Digits);
double SL=NormalizeDouble(StopLoss*StopMultd,Digits);

//-------------------------------------------------------------------+
//Check open orders
//-------------------------------------------------------------------+
if(OrdersTotal()>0){
for(int i=1; i<=OrdersTotal(); i++) // Cycle searching in orders
{
if (OrderSelect(i-1,SELECT_BY_POS)==true) // If the next is available
{
if((MTakeProfit==true)&&(TakeProfit>0)&&(OrderMagi cNumber()== magicNumber)){ // m tp
Sleep(Sleepa*1000);
// Calculate take profit
double tpb=NormalizeDouble(OrderOpenPrice()+TP*Point,Digi ts);
double tps=NormalizeDouble(OrderOpenPrice()-TP*Point,Digits);

Comment("Modifying take profit");
if((OrderType()==OP_BUY)&&(OrderTakeProfit()==0)&& (OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,OrderStopLoss(),tpb,0, CLR_NONE); }
if((OrderType()==OP_SELL)&&(OrderTakeProfit()==0)& &(OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,OrderStopLoss(),tps,0, CLR_NONE); }

} // m tp

if((MStopLoss==true)&&(StopLoss>0)&&(OrderMagicNum ber()== magicNumber)){ // m sl
Sleep(Sleepa*1000);
// Calculate stop loss
double slb=NormalizeDouble(OrderOpenPrice()-SL*Point,Digits);
double sls=NormalizeDouble(OrderOpenPrice()+SL*Point,Digi ts);

Comment("Modifying stop loss");
if((OrderType()==OP_BUY)&&(OrderStopLoss()==0)&&(O rderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,slb,OrderTakeProfit(), 0,CLR_NONE); }
if((OrderType()==OP_SELL)&&(OrderStopLoss()==0)&&( OrderSymbol()==Symbol())){ OrderModify(OrderTicket(),0,sls,OrderTakeProfit(), 0,CLR_NONE); }

}// m sl
Comment("");
}
}
}
//----
int Error=GetLastError();
if(Error==130){Alert("Wrong stops. Retrying."); RefreshRates();}
if(Error==133){Alert("Trading prohibited.");}
if(Error==2){Alert("Common error.");}
if(Error==146){Alert("Trading subsystem is busy. Retrying."); Sleep(500); RefreshRates();}

//----------
return(0);
}
//+-----------------------------------END-------------------------------+

int init()
{
//----
Alert(":-)");
//----
return(0);
}

//

Gruß
Darius