R. Gozzi- trail
Forums › ProRealTime English forum › ProOrder support › R. Gozzi- trail
- This topic has 7 replies, 2 voices, and was last updated 2 years ago by robertogozzi.
Tagged: Break Even, BreakEven, percent, Percentage, step, stop, trailing, trailing stop
-
-
04/13/2022 at 12:42 PM #191683
Is there av version of R. Gozzi- trail with % and diffrent values for short and long?
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475//--------------------------------------------------------------------------------------------DirectionSwitch = (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) //TrP Exit (GozziIF Not OnMarket OR DirectionSwitch THENTrailStart = TS//40 // Start trailing profitsPointToKeep = PK//0.2 // 20% Profit percentage to keep when setting BreakEvenStepSize = SS//5 // Point to increase PercentagePerCentInc = PC//0.2 // 20% PerCent increment after each StepSize ChunkRoundTO = -0.5 //-0.5 rounds always to Lower integer, 0 defaults PRT behaviourPriceDistance = 10* pipsize //6minimun distance from current pricemaxProfitL = 0 //0 eller 2050maxProfitS = 0ProfitPerCent = PointToKeep //reset to desired default valueSellPriceX = 0SellPrice = 0ExitPriceX = 9999999ExitPrice = 9999999ELSEIF PositionPrice <> PositionPrice[1] AND (ExitPrice + SellPrice) <> 9999999 THEN //go on only if Trailing Stop had already started trailingIF LongOnMarket THENnewSlL = PositionPrice + ((close - PositionPrice) * ProfitPerCent) //calculate new SLSellPriceX = max(max(SellPriceX,SellPrice),newSlL)SellPrice = max(max(SellPriceX,SellPrice),PositionPrice + (maxProfitL * pipsize)) //set exit price to whatever grants greater profits, comopared to the previous oneELSIF ShortOnMarket THENnewSlS = PositionPrice - ((PositionPrice - close) * ProfitPerCent)ExitPriceX = min(min(ExitPriceX,ExitPrice),newSlS)ExitPrice = min(min(ExitPriceX,ExitPrice),PositionPrice - (maxProfitS * pipsize))ENDIFENDIFENDIF//---------------------------------------------------------------------------------------------------------------------------------------------------IF LongOnMarket AND close > (PositionPrice + (maxProfitL * pipsize)) THEN //LONG positions// compute the value of the Percentage of profits, if any, to lock in for LONG tradesprofitL = (close - PositionPrice) / pipsize //convert price to pipsIF profitL >= TrailStart THEN // go ahead only if N+ pipsDiff1 = abs(TrailStart - profitL) //difference from current profit and TrailStartChunks1 = max(0,round((Diff1 / StepSize) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = PointToKeep + (PointToKeep * (Chunks1 * PerCentInc)) //compute new size of ProfitPerCentProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%maxProfitL = max(profitL * ProfitPerCent, maxProfitL)ENDIFELSIF ShortOnMarket AND close < (PositionPrice - (maxProfitS * pipsize)) THEN //SHORT positionsprofitS = (PositionPrice - close) / pipsizeIF profitS >= TrailStart THENDiff2 = abs(TrailStart - profitS)Chunks2 = max(0,round((Diff2 / StepSize) + RoundTO))ProfitPerCent = PointToKeep + (PointToKeep * (Chunks2 * PerCentInc))ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))maxProfitS = max(profitS * ProfitPerCent, maxProfitL)ENDIFENDIF//--------------------------------------------------------------------------------------------------------------------------------------------------------------IF maxProfitL THEN //LONG positions - Place pending STOP order when maxProftiL > 0 (LONG positions)SellPrice = max(SellPrice,PositionPrice + (maxProfitL * pipsize)) //convert pips to priceIF abs(close - SellPrice) > PriceDistance THENIF close >= SellPrice THENSELL AT SellPrice STOPELSESELL AT SellPrice LIMITENDIFELSESELL AT MarketENDIFENDIFIF maxProfitS THENExitPrice = min(ExitPrice,PositionPrice - (maxProfitS * pipsize)) //SHORT positionsIF abs(close - ExitPrice) > PriceDistance THENIF close <= ExitPrice THENEXITSHORT AT ExitPrice STOPELSEEXITSHORT AT ExitPrice LIMITENDIFELSEEXITSHORT AT MarketENDIFENDIF04/13/2022 at 3:13 PM #191707There you go:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113MA = 50IF close crosses over average[MA,0] AND Not OnMarket THENBUY at marketELSIF close crosses UNDer average[MA,0] AND Not OnMarket THENSELLSHORT at marketendifSET TARGET pPROFIT 300SET STOP pLOSS 150//--------------------------------------------------------------------------------------------DirectionSwitch = (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) //TrP Exit (Gozzi//--------------------------------------------------------------------------------------------// MyEquity must be defined somewhere in your code (even to ZERO if its use is not planned)ONCE MyEquity = 10000//initial Capital (only if UseEquity = 1)ONCE UsePerCentage = 0 //0=use Pips (default), 1=use PercentagesONCE UseEquity = 0 //0=use price (default), 1=use Equity (initial Capital+StrategyProfit, defined by MyEquity)//IF Not OnMarket OR DirectionSwitch THENStartPerCentL = 0.25 //0.25% to start triggering Trailing Stop (when UsePerCentage=1)StepPerCentL = 50 //50% (of the 0.25% above) as a Trqiling Step (when UsePerCentage=1) (set to 100 to make StepSize=TrailStart, set to 200 to make it twice TrailStart)StartPerCentS = 0.25 //0.25% to start triggering Trailing Stop (when UsePerCentage=1)StepPerCentS = 50 //50% (of the 0.25% above) as a Trqiling Step (when UsePerCentage=1) (set to 100 to make StepSize=TrailStart, set to 200 to make it twice TrailStart)//TrailStartL = TS//40 //Start trailing profits from this point (when UsePerCentage=0)TrailStartS = TS//40 //Start trailing profits from this point (when UsePerCentage=0)MinStartL = 10 //10 Minimum value for TrailStart (when UseEquity=1, to prevent TrailStart from// dropping below ZERO when Equity turns negative)MinStartS = 10 //10 Minimum value for TrailStart (when UseEquity=1, to prevent TrailStart fromMinStartL = 10 //10 Minimum value for TrailStart (when UseEquity=1, to prevent TrailStart fromIF UsePerCentage THENTrailStartL= (close / PipSize) * StartPerCentL / 100 //use current price (CLOSE) for calculationsTrailStartS= (close / PipSize) * StartPerCentS / 100 //use current price (CLOSE) for calculationsIF UseEquity THEN //alternative calculations using EQUITYTrailStartL= Max(MinStartL,(MyEquity / PipValue) * StartPerCentL / 100) //MyEquity is the variable (feel free to use a different name) retaining your current equityTrailStartS= Max(MinStartS,(MyEquity / PipValue) * StartPerCentS / 100) //MyEquity is the variable (feel free to use a different name) retaining your current equityENDIFENDIFPointToKeep = PK//0.2 // 20% Profit percentage to keep when setting BreakEvenStepSizeL = SS//5 // Point to increase PercentageStepSizeS = SS//5 // Point to increase Percentage//IF UsePerCentage THENStepSizeL = TrailStartL * StepPerCentL / 100StepSizeS = TrailStartS * StepPerCentS / 100ENDIF//PerCentInc = PC//0.2 // 20% PerCent increment after each StepSize ChunkRoundTO = -0.5 //-0.5 rounds always to Lower integer, 0 defaults PRT behaviourPriceDistance = 10* pipsize //6minimun distance from current pricemaxProfitL = 0 //0 eller 2050maxProfitS = 0ProfitPerCent = PointToKeep //reset to desired default valueSellPriceX = 0SellPrice = 0ExitPriceX = 9999999ExitPrice = 9999999ELSEIF PositionPrice <> PositionPrice[1] AND (ExitPrice + SellPrice) <> 9999999 THEN //go on only if Trailing Stop had already started trailingIF LongOnMarket THENnewSlL = PositionPrice + ((close - PositionPrice) * ProfitPerCent) //calculate new SLSellPriceX = max(max(SellPriceX,SellPrice),newSlL)SellPrice = max(max(SellPriceX,SellPrice),PositionPrice + (maxProfitL * pipsize)) //set exit price to whatever grants greater profits, comopared to the previous oneELSIF ShortOnMarket THENnewSlS = PositionPrice - ((PositionPrice - close) * ProfitPerCent)ExitPriceX = min(min(ExitPriceX,ExitPrice),newSlS)ExitPrice = min(min(ExitPriceX,ExitPrice),PositionPrice - (maxProfitS * pipsize))ENDIFENDIFENDIF//---------------------------------------------------------------------------------------------------------------------------------------------------IF LongOnMarket AND close > (PositionPrice + (maxProfitL * pipsize)) THEN //LONG positions// compute the value of the Percentage of profits, if any, to lock in for LONG tradesprofitL = (close - PositionPrice) / pipsize //convert price to pipsIF profitL >= TrailStartL THEN // go ahead only if N+ pipsDiff1 = abs(TrailStartL - profitL) //difference from current profit and TrailStartChunks1 = max(0,round((Diff1 / StepSizeL) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = PointToKeep + (PointToKeep * (Chunks1 * PerCentInc)) //compute new size of ProfitPerCentProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%maxProfitL = max(profitL * ProfitPerCent, maxProfitL)ENDIFELSIF ShortOnMarket AND close < (PositionPrice - (maxProfitS * pipsize)) THEN //SHORT positionsprofitS = (PositionPrice - close) / pipsizeIF profitS >= TrailStartS THENDiff2 = abs(TrailStartS - profitS)Chunks2 = max(0,round((Diff2 / StepSizeS) + RoundTO))ProfitPerCent = PointToKeep + (PointToKeep * (Chunks2 * PerCentInc))ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))maxProfitS = max(profitS * ProfitPerCent, maxProfitL)ENDIFENDIF//--------------------------------------------------------------------------------------------------------------------------------------------------------------IF maxProfitL THEN //LONG positions - Place pending STOP order when maxProftiL > 0 (LONG positions)SellPrice = max(SellPrice,PositionPrice + (maxProfitL * pipsize)) //convert pips to priceIF abs(close - SellPrice) > PriceDistance THENIF close >= SellPrice THENSELL AT SellPrice STOPELSESELL AT SellPrice LIMITENDIFELSESELL AT MarketENDIFENDIFIF maxProfitS THENExitPrice = min(ExitPrice,PositionPrice - (maxProfitS * pipsize)) //SHORT positionsIF abs(close - ExitPrice) > PriceDistance THENIF close <= ExitPrice THENEXITSHORT AT ExitPrice STOPELSEEXITSHORT AT ExitPrice LIMITENDIFELSEEXITSHORT AT MarketENDIFENDIF04/13/2022 at 9:27 PM #19173304/19/2022 at 5:35 PM #191915Roberto. I got this error: “stoped by broker due to many atempts to place order”
Nasdaq 1EUR
Timeframe 15MDo u know whats wrong?
See attached picture123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475//--------------------------------------------------------------------------------------------DirectionSwitch = (LongOnMarket AND ShortOnMarket[1]) OR (LongOnMarket[1] AND ShortOnMarket) //TrP Exit (GozziIF Not OnMarket OR DirectionSwitch THENTrailStart = 0.9 // Start trailing profitsPointToKeep = 0.81 // PK20% Profit percentage to keep when setting BreakEvenStepSize = 1 // Point to increase PercentagePerCentInc = 0.9 // 20% PerCent increment after each StepSize ChunkRoundTO = -0.8 //-0.5 rounds always to Lower integer, 0 defaults PRT behaviourPriceDistance = 10* pipsize //6minimun distance from current pricemaxProfitL = 0 //0 eller 2050maxProfitS = 0ProfitPerCent = PointToKeep //reset to desired default valueSellPriceX = 0SellPrice = 0ExitPriceX = 9999999ExitPrice = 9999999ELSEIF PositionPrice <> PositionPrice[1] AND (ExitPrice + SellPrice) <> 9999999 THEN //go on only if Trailing Stop had already started trailingIF LongOnMarket THENnewSlL = PositionPrice + ((close - PositionPrice) * ProfitPerCent) //calculate new SLSellPriceX = max(max(SellPriceX,SellPrice),newSlL)SellPrice = max(max(SellPriceX,SellPrice),PositionPrice + (maxProfitL * pipsize)) //set exit price to whatever grants greater profits, comopared to the previous oneELSIF ShortOnMarket THENnewSlS = PositionPrice - ((PositionPrice - close) * ProfitPerCent)ExitPriceX = min(min(ExitPriceX,ExitPrice),newSlS)ExitPrice = min(min(ExitPriceX,ExitPrice),PositionPrice - (maxProfitS * pipsize))ENDIFENDIFENDIF//---------------------------------------------------------------------------------------------------------------------------------------------------IF LongOnMarket AND close > (PositionPrice + (maxProfitL * pipsize)) THEN //LONG positions// compute the value of the Percentage of profits, if any, to lock in for LONG tradesprofitL = (close - PositionPrice) / pipsize //convert price to pipsIF profitL >= TrailStart THEN // go ahead only if N+ pipsDiff1 = abs(TrailStart - profitL) //difference from current profit and TrailStartChunks1 = max(0,round((Diff1 / StepSize) + RoundTO)) //number of STEPSIZE chunksProfitPerCent = PointToKeep + (PointToKeep * (Chunks1 * PerCentInc)) //compute new size of ProfitPerCentProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent)) //make sure ProfitPerCent doess not exceed 100%maxProfitL = max(profitL * ProfitPerCent, maxProfitL)ENDIFELSIF ShortOnMarket AND close < (PositionPrice - (maxProfitS * pipsize)) THEN //SHORT positionsprofitS = (PositionPrice - close) / pipsizeIF profitS >= TrailStart THENDiff2 = abs(TrailStart - profitS)Chunks2 = max(0,round((Diff2 / StepSize) + RoundTO))ProfitPerCent = PointToKeep + (PointToKeep * (Chunks2 * PerCentInc))ProfitPerCent = max(ProfitPerCent[1],min(100,ProfitPerCent))maxProfitS = max(profitS * ProfitPerCent, maxProfitL)ENDIFENDIF//--------------------------------------------------------------------------------------------------------------------------------------------------------------IF maxProfitL THEN //LONG positions - Place pending STOP order when maxProftiL > 0 (LONG positions)SellPrice = max(SellPrice,PositionPrice + (maxProfitL * pipsize)) //convert pips to priceIF abs(close - SellPrice) > PriceDistance THENIF close >= SellPrice THENSELL AT SellPrice STOPELSESELL AT SellPrice LIMITENDIFELSESELL AT MarketENDIFENDIFIF maxProfitS THENExitPrice = min(ExitPrice,PositionPrice - (maxProfitS * pipsize)) //SHORT positionsIF abs(close - ExitPrice) > PriceDistance THENIF close <= ExitPrice THENEXITSHORT AT ExitPrice STOPELSEEXITSHORT AT ExitPrice LIMITENDIFELSEEXITSHORT AT MarketENDIFENDIF04/19/2022 at 8:45 PM #191926It seems you are using a 1-second TF, so every second a pending order is placed when trailing is triggered. It seems that IG cannot process further oreders because in a single bar could not adress the prior request.
It often occurs to me, as well. But I am using a 5-minute TF, which should be a TF large enough not to make this happen, but it does, however.
So far I couldn’t get any clue how to solve it, despite some email messages.
04/19/2022 at 8:49 PM #19192704/20/2022 at 10:13 AM #191943Is there a combiantion of these vakkues thats not possible to use in live-trading?
123456TrailStart = 0.9 // Start trailing profitsPointToKeep = 0.81 // PK20% Profit percentage to keep when setting BreakEvenStepSize = 1 // Point to increase PercentagePerCentInc = 0.9 // 20% PerCent increment after each StepSize ChunkRoundTO = -0.8 //-0.5 rounds always to Lower integer, 0 defaults PRT behaviourPriceDistance = 10* pipsize //6minimun distance from current price04/20/2022 at 1:04 PM #191949No, they seem all correct.
Try GRAPHing the variables involved to spot any weird value.
-
AuthorPosts