Help about stop trading strategy
Forums › ProRealTime English forum › ProOrder support › Help about stop trading strategy
- This topic has 10 replies, 5 voices, and was last updated 3 months ago by robertogozzi.
-
-
03/20/2023 at 12:49 AM #211754
Hello!
Is it possible to program the strategy to turn off after two losses. So if there are two losses regardless of time or if these are consecutive, the strategy is closed for that particular day.
Or if the loss is a certain amount, let’s say 50 dollars, the strategy is turned off for that particular day.
Thanks in advance and best regards!03/20/2023 at 5:15 AM #211755My code will use the variable TradeON to flag periods when the strategy is freezed. Each new day trading is restored to full functionality:
123456789101112131415161718192021222324MaxLosses = 2 //after 2 losses stop tradingMaxLoss = 50 //after 50 € loss stop tradingOnce TradeON = 1Once MyProfit = 0If IntraDayBarIndex = 0 thenTradeON = 1Tally = 0MyProfit = StrategyProfitEndifIf StrategyProfit < StrategyProfit[1] thenTally = Tally + 1If Tally = MaxLosses thenTradeON = 0EndifEndifIf (MyProfit - StrategyProfit) >= MaxLoss thenTradeON = 0EndifIf MyLongConditions and TradeuON thenBUY 1 Contract at MarketEndifIf MyShortConditions and TradeON thenSELLSHORT 1 Contract at MarketEndif1 user thanked author for this post.
03/20/2023 at 1:40 PM #211793Link to above code saved as Log 359 here …
1 user thanked author for this post.
03/20/2023 at 8:19 PM #21184203/20/2023 at 8:19 PM #21184309/03/2024 at 9:07 AM #23703909/03/2024 at 11:13 AM #237040There you go:
12345678910111213141516171819202122ONCE Pause = 500 //wait 500 bars before trading againONCE Losses = 0ONCE TradeON = 1IF StrategyProfit > StrategyProfit[1] THENLosses = 0ELSIF StrategyProfit < StrategyProfit[1] THENLosses = Losses + 1LossBAR = BarIndexIF Losses = 2 THENLosses = 0TradeON = 0ENDIFENDIFIF (BarIndex -LossBAR) = Pause THENTradeON = 1ENDIF//IF MyLongConditions AND TradeON THENBUY 1 CONTRACT AT MARKETELSIF MyShortConditions AND TradeON THENSELLSHORT 1 CONTRACT AT MARKETENDIF1 user thanked author for this post.
09/06/2024 at 7:58 PM #237258Hi robertogozzi
I need some coding help. What I want do is: if the last 3 trades were winning , dont take any trade for the next 10 bars How could I code that?
09/07/2024 at 10:44 AM #237272There you go:
123456789101112131415161718192021222324252627282930ONCE Pause = 10 //wait 10 bars before trading againONCE MaxWins = 3 //pause after 3 consecutive winsONCE Wins = 0ONCE TradeON = 1IF StrategyProfit > StrategyProfit[1] THENWins = Wins + 1IF Wins = MaxWins THENTradeON = 0winBAR = BarIndexWins = 0ENDIFELSIF StrategyProfit < StrategyProfit[1] THENWins = 0ENDIFIF (BarIndex - winBAR) = Pause THENTradeON = 1ENDIF//MyLongConditions = Not OnMarket AND Close CROSSES OVER Average[20,0](close)MyShortConditions = Not OnMarket AND Close CROSSES UNDER Average[20,0](close)//IF MyLongConditions AND TradeON THENBUY 1 CONTRACT AT MARKETELSIF MyShortConditions AND TradeON THENSELLSHORT 1 CONTRACT AT MARKETENDIFSET STOP %LOSS 0.5SET TARGET %PROFIT 1//graph Wins coloured("Green")//graph TradeON coloured("Red")09/07/2024 at 11:47 AM #237277thank you thats help my code alooot
I have just one more idea..
What I want do is: its like a trailing stop but not on the position it will be on the portfolio i will give you an example:
lets say i gain 1000$ and the trade is closed if he open a trade again i want him to secure 500$ from the last trade if he touch it he will shut down the system.
also Every time I win multiples of 500, I want the device to stop at a rate of 500.
09/07/2024 at 12:34 PM #237281This seems to work as expected:
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061ONCE Pause = 10 //wait 10 bars before trading againONCE MaxWins = 3 //pause after 3 consecutive winsONCE Wins = 0ONCE TradeON = 1ONCE GainTreshold = 1000 //Gain treshold above which a 50% profit is locked inONCE myStrategyProfit = 0ONCE myGainStopLevel = 0// exit if the locked in profit is reachedIF OnMarket AND (myGainStopLevel > 0) THENtempProfit = positionperf * positionprice * PipValueIF (StrategyProfit + tempProfit) <= myGainStopLevel THENSELL AT MARKETEXITSHORT AT MARKETQuitENDIFENDIF//check the wins and update the locked in profit, if large enoughIF StrategyProfit > StrategyProfit[1] THENWins = Wins + 1IF Wins = MaxWins THENTradeON = 0winBAR = BarIndexWins = 0ENDIF//check if locked in profit has to be updatedIF StrategyProfit > 0 THEN//set tha base for the calculationsBaseProfit = StrategyProfit[1]//if the previous StrategyProfit was negative set the BaseProfit to 0,//to avoid an incorrect addition, due to subtracting a negative valueIF StrategyProfit[1] < 0 THENBaseProfit = 0ENDIFGain = StrategyProfit - BaseProfitIF Gain >= GainTreshold THEN//lock in additional 50% profitsmyGainStopLevel = BaseProfit + round(Gain / 2)ENDIFENDIFELSIF StrategyProfit < StrategyProfit[1] THENWins = 0ENDIF//set trading again after pausingIF (BarIndex - winBAR) = Pause THENTradeON = 1ENDIF//MyLongConditions = Not OnMarket AND Close CROSSES OVER Average[20,0](close)MyShortConditions = Not OnMarket AND Close CROSSES UNDER Average[20,0](close)//IF MyLongConditions AND TradeON THENBUY 1 CONTRACT AT MARKETELSIF MyShortConditions AND TradeON THENSELLSHORT 1 CONTRACT AT MARKETENDIFSET STOP %LOSS 0.5SET TARGET %PROFIT 1//graph Wins coloured("Green")//graph TradeON coloured("Red")graph StrategyProfit coloured("Fuchsia")graph myGainStopLevel coloured("Blue") -
AuthorPosts
Find exclusive trading pro-tools on