Hallo Allemaal,
Hieronder staat het Stoploss systeem. Wat ik graag zou willen is dat er eerst een bepaalde winst wordt behaald en dat dan de trailingstop pas gaat werken. Als voorbeeld, een systeem staat op 30 punten winst en daarna loopt de winst weg. Dan wil ik de positie met 5 punten winst sluiten. Ik heb van Pierre al begrepen dat je de Breakeven en de Trailingstop moet combineren maar ik krijg het niet voor elkaar. Wie wil/kan mij helpen?
value function StopLoss (value xStopLoss=5,value xBreakEven=0,
?value xTrailingStop=0,value xProfitStop=0) begin
?{--- caluculate current loss and profit ---}
?value xLoss,xProfit,xBest,xPrevPosition=0;
?xLoss := -100*OpenPositionProfit/(AbsValue(CurrentContracts)*AbsValue(AvgEntryPrice)*BigPointValue);
?xProfit := -xLoss;
?{--- keep track of best profit in trade ---}
?value xMarketPosition;
?xMarketPosition := MarketPosition;
?if xMarketPosition<>xPrevPosition then xBest := 0;
?if xProfit>xBest then xBest := xProfit;
?{--- check for stops ---}
?value xStopNow;
?xStopNow = false;
?if xStopLoss<>0 and xLoss>xStopLoss then xStopNow := true;
?if xBreakEven<>0 and xBest>xBreakEven and xLoss>0 then xStopNow := true;
?if xTrailingStop<>0 and xBest-xProfit>xTrailingStop then xStopNow := true;
?if xProfitStop<>0 and xProfit>xProfitStop then xStopNow := true;
?{--- exit trade if any stop is hit ---}
?if xStopNow=true then begin
? ?ExitLong;
? ?ExitShort;
? ?end;
?{--- keep track of position ---}
?xPrevPosition := xMarketPosition;
?end;
Bedankt voor de moeite!
Mark