Einzelnen Beitrag anzeigen
  #1 (permalink)  
Alt 24.08.14
dieter23 dieter23 ist offline
Mitglied
 
Registriert seit: Sep 2013
Beiträge: 35
dieter23 befindet sich auf einem aufstrebenden Ast
Standard Trailing Stop setzen

Hallo Leute,
bin am verzweifeln. Bekomme es nicht gebacken eine Trailing Stop in mein Programm zu integrieren.Meine Programmierkenntnisse sind sehr bescheiden. Wäre sehr dankbar, wenn jemand helfen könnte.
Meine Startroutine sieht bisher so aus. Orders werden gesetzt, jedoch ohne Trailing Stops.
Gruß Dieter


int start()
{


Comment("Copyright © 2014 *** Robot_Dax ***"+"\n"+
"TimeStart " , TimeStart, "\n",
"TimeEnd " , TimeEnd, "\n",
"MaxPrice ", Max_Price, "\n",
"MinPrice " , Min_Price, "\n",
"Akt.Preis ", Ask, "\n");


if (MoneyManagement)
{
if (Risk<1 || Risk>100)
{
Comment("Invalid Risk Value.");
return(0);
}
else
{
Lots=MathFloor((AccountFreeMargin()*AccountLeverag e()*Risk*Point*BrokerMultiplier*100)/(Ask*MarketInfo(Symbol(),MODE_LOTSIZE)*MarketInfo( Symbol(),MODE_MINLOT)))*MarketInfo(Symbol(),MODE_M INLOT);
}
}
datetime Time_Start = StrToTime(StringConcatenate(Day(),".",Month(),".", Year()," ",TimeStart, ":00"));
datetime Time_End = StrToTime(StringConcatenate(Day(),".",Month(),".", Year()," ",TimeEnd, ":00"));
datetime Time_CloseOrder = StrToTime(StringConcatenate(Day(),".",Month(),".", Year()," ",TimeCloseOrder,":00"));

if (Time_CloseOrder>Time_End) if (CurTime()>=Time_CloseOrder) CLOSEORDERS();

int tip;
if (Orders>OrdersTotal()) tip=CloseOrder();
Orders=OrdersTotal();

if (ORDERS(0)==0 && tip==0 && (CurTime()<Time_CloseOrder || Time_CloseOrder<=Time_End) && TradeDay!=TimeDay(CurTime()))
{
int BarStart = iBarShift(NULL,0,Time_Start,false);
int BarEnd = iBarShift(NULL,0,Time_End ,false);
Max_Price=iHigh(NULL,0,iHighest(NULL,0,MODE_HIGH,B arStart-BarEnd,BarEnd));
Min_Price=iLow (NULL,0,iLowest (NULL,0,MODE_LOW, BarStart-BarEnd,BarEnd));

if (TimeCurrent()>Time_End && ObjectFind("bar0"+Time_End)==-1)
{
ObjectCreate("bar0"+Time_End, OBJ_RECTANGLE, 0, 0,0, 0,0);
ObjectSet ("bar0"+Time_End, OBJPROP_STYLE, STYLE_SOLID);
ObjectSet ("bar0"+Time_End, OBJPROP_COLOR, Blue);
ObjectSet ("bar0"+Time_End, OBJPROP_BACK, true);
ObjectSet ("bar0"+Time_End, OBJPROP_TIME1 ,Time_Start);
ObjectSet ("bar0"+Time_End, OBJPROP_PRICE1,Max_Price);
ObjectSet ("bar0"+Time_End, OBJPROP_TIME2 ,Time_End);
ObjectSet ("bar0"+Time_End, OBJPROP_PRICE2,Min_Price);
}


if(Bid > Max_Price && order == 0)
{
OrderSend(Symbol(), OP_BUY, Lots, Ask,Slippage, Ask-SL,Ask+TP, "br", Magic, 0, Green);
order=order+1;
}

if(Ask < Min_Price && order == 0)
{
OrderSend(Symbol(), OP_SELL, Lots, Bid,Slippage, Bid+SL,Bid-TP, "br", Magic, 0, Green);
order=order+1;
}

return(0);
}

if (No_Loss) No_Loss();
if (tip==1 && TradeDay!=TimeDay(CurTime()))
{
Lots=Lots*K_martin;

if (tipOrders==0) OrderSend(Symbol(),OP_SELL,Lots,Bid,Slippage,SL,TP ,NULL,Magic,Blue);
if (tipOrders==1) OrderSend(Symbol(),OP_BUY ,Lots,Ask,Slippage,SL,TP,NULL,Magic,Blue);
}
return(0);
}