|
Startseite | Registrieren | Hilfe | Benutzerliste | Kalender | Suchen | Heutige Beiträge | Alle Foren als gelesen markieren |
Programmierung MQL4 Hier gehts rund ums Programmieren in MQL4. |
|
Themen-Optionen | Thema durchsuchen | Ansicht |
|
|||
Zitat:
|
|
|||
Zitat:
es ist so, wenn ich jetzt per Hand eine order aufmache setzt er erst den TP dann den SL und dann beide...ist ja auch logisch, wegen des programms...reihenfolge....ich werde es vielleicht noch erweitern...trailing stop oder so...so kann man bedenkenlos per hand order aufmachen und dann warten....gruß. ps. öffne eine order mit 0,01 und dann warte ....bei mir funktioniert....gruß |
|
|||
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 |
Lesezeichen |
Stichworte |
mql4, programmierung, programmierung metatrader, sl, stoploss, trailingstop |
Themen-Optionen | Thema durchsuchen |
Ansicht | |
|
|