NOT SURE HOW TO USE THE OPTMIZE
Forums › ProRealTime English forum › ProOrder support › NOT SURE HOW TO USE THE OPTMIZE
- This topic has 7 replies, 3 voices, and was last updated 5 days ago by GraHal.
-
-
11/22/2024 at 3:50 PM #240659
IV ADD THE FILE Basically what I’ve done is all I want to do is optimize the risk management i’ve put a basic 20 moving average price goes above it by price goes below itself but all I really want to do is try to work out how to use the optimizer at the same time so any help I would appreciate it
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155// Prevent multiple order// Prevent multiple orders in the same directiondefparam cumulateorders = falseONCE N = 1PointsToKeep = 10 // How much pips/points to secure above or below entry price when breakeven is activated// Reset variables when no trades are activeIF NOT ONMARKET THENbreakevenLevel = 0newSL = 0ENDIF// --- Long Trade Logic ---indicator1 = ExponentialAverage[20](close)c1 = (close CROSSES OVER indicator1) // Define indicator for long// Condition for long entryIF c1 AND NOT OnMarket THEN// Define ATR-Based Stops and Targets for Long TradesTp = AverageTrueRange[14](CLOSE) * A // Take-profit level 1Tp2 = AverageTrueRange[14](CLOSE) * B // Take-profit level 2Tp3 = AverageTrueRange[14](CLOSE) * C // Take-profit level 3St = AverageTrueRange[14](CLOSE) * D // Stop-lossTs = AverageTrueRange[14](CLOSE) * E // Trailing stop activation levelstartBreakeven = Tptrailingstart = Tstrailingstep = St * pipsizeBUY 4 PERPOINT AT MARKETSET STOP PLOSS St * pipsizeN = 1ENDIF// Manage Breakeven for Long TradesIF LONGONMARKET AND abs(CountOfPosition) = 3 AND close - TRADEPRICE(N) >= startBreakeven * pipsize THENbreakevenLevel = TRADEPRICE(N) + PointsToKeep * pipsizeENDIF// Partial Profit-Taking for Long TradesIF LONGONMARKET AND CLOSE >= (TRADEPRICE(N) + Tp) AND abs(CountOfPosition) = 4 THENSELL 1 PERPOINT AT MARKETN = 2ENDIFIF LONGONMARKET AND CLOSE >= (TRADEPRICE(N) + Tp2) AND abs(CountOfPosition) = 3 THENSELL 1 PERPOINT AT MARKETN = 3ENDIFIF LONGONMARKET AND CLOSE >= (TRADEPRICE(N) + Tp3) AND abs(CountOfPosition) = 2 THENSELL 1 PERPOINT AT MARKETN = 4ENDIF// Trailing Stop Management for Long TradesIF LONGONMARKET THENIF newSL = 0 AND close - TRADEPRICE(N) >= trailingstart * pipsize THENnewSL = high - trailingstep * pipsizeENDIFIF newSL > 0 AND close - newSL >= trailingstep * pipsize THENnewSL = high - trailingstep * pipsizeENDIFENDIF// Exit at Breakeven or Trailing Stop for Long TradesIF breakevenLevel > 0 THENSELL AT breakevenLevel STOPENDIFIF newSL > 0 THENSELL AT newSL STOPENDIF// --- Short Trade Logic ---indicator2 = ExponentialAverage[20](close)Sc1 = (close CROSSES UNDER indicator2)// Define indicator for short (same as long, used inversely)// Condition for short entryIF Sc1 AND NOT OnMarket THEN// Define ATR-Based Stops and Targets for Short TradesTp = AverageTrueRange[14](CLOSE) * A // Take-profit level 1Tp2 = AverageTrueRange[14](CLOSE) * B // Take-profit level 2Tp3 = AverageTrueRange[14](CLOSE) * C // Take-profit level 3St = AverageTrueRange[14](CLOSE) * D // Stop-lossTs = AverageTrueRange[14](CLOSE) * E // Trailing stop activation levelstartBreakeven = Tptrailingstart = Tstrailingstep = St * pipsizeSELLSHORT 4 PERPOINT AT MARKETSET STOP PLOSS St //* pipsizeN = 1ENDIF// Manage Breakeven for Short TradesIF SHORTONMARKET AND abs(CountOfPosition) = 3 AND TRADEPRICE(N) - close >= startBreakeven * pipsize THENbreakevenLevel = TRADEPRICE(N) - PointsToKeep * pipsizeENDIF// Partial Profit-Taking for Short TradesIF SHORTONMARKET AND CLOSE <= (TRADEPRICE(N) - Tp) AND abs(CountOfPosition) = 4 THENEXITSHORT 1 PERPOINT AT MARKETN = 2ENDIFIF SHORTONMARKET AND CLOSE <= (TRADEPRICE(N) - Tp2) AND abs(CountOfPosition) = 3 THENEXITSHORT 1 PERPOINT AT MARKETN = 3ENDIFIF SHORTONMARKET AND CLOSE <= (TRADEPRICE(N) - Tp3) AND abs(CountOfPosition) = 2 THENEXITSHORT 1 PERPOINT AT MARKETN = 4ENDIF// Trailing Stop Management for Short TradesIF SHORTONMARKET THENIF newSL = 0 AND TRADEPRICE(N) - close >= trailingstart * pipsize THENnewSL = low - trailingstep * pipsizeENDIFIF newSL > 0 AND TRADEPRICE(N) - newSL >= trailingstep * pipsize THENnewSL = low - trailingstep * pipsizeENDIFENDIF// Exit at Breakeven or Trailing Stop for Short TradesIF breakevenLevel > 0 THENEXITSHORT AT breakevenLevel STOPENDIFIF newSL > 0 THENEXITSHORT AT newSL STOPENDIF// --- Visualization for Long and Short Trades ---GraphOnPrice newSL coloured("red") AS "Trailing Stop" // Trailing stop is now red for clarityGraphOnPrice breakevenLevel coloured("orange") AS "Breakeven Level" // Breakeven level remains orange// Visualization for Long TradesIF LONGONMARKET THENGraphOnPrice (TradePrice(N) + Tp) coloured("lightgreen") AS "Long Exit 1" // TP1 (light green)GraphOnPrice (TradePrice(N) + Tp2) coloured("green") AS "Long Exit 2" // TP2 (green)GraphOnPrice (TradePrice(N) + Tp3) coloured("darkgreen") AS "Long Exit 3" // TP3 (dark green)GraphOnPrice (TradePrice(N) - St) coloured("red") AS "Stop" // Stop-loss (red)ENDIF// Visualization for Short TradesIF SHORTONMARKET THENGraphOnPrice (TradePrice(N) - Tp) coloured("lightblue") AS "Short Exit 1" // TP1 (light blue)GraphOnPrice (TradePrice(N) - Tp2) coloured("blue") AS "Short Exit 2" // TP2 (blue)GraphOnPrice (TradePrice(N) - Tp3) coloured("darkblue") AS "Short Exit 3" // TP3 (dark blue)GraphOnPrice (TradePrice(N) + St) coloured("red") AS "Stop" // Stop-loss (red)ENDIF11/22/2024 at 4:04 PM #240662These should be useful …
https://www.youtube.com/watch?v=qCbWAJLyZFQ
https://www.youtube.com/watch?v=Pu1P7o3syHM
2 users thanked author for this post.
11/22/2024 at 4:05 PM #240663For example :
Comment-out your St in line 23 (//).
Now add the variable/parameter St to the Optimizer Variables.
Let it iterate over the points you want to test (e.g. from 5 to 20, step 0.5).
Press Backtest.Have the checkbox “Tick by Tick mode” checked.
Helps ?
PS: Keep in mind that you overrule the St variable on line 85. It is a bit difficult for me to find another candidate in your code.
Edit : PointsToKeep may be a good one !2 users thanked author for this post.
11/22/2024 at 6:24 PM #240668On this system I’m not very sure what are the from the testing what is the best variables and the inundate are outdated is quite confusing for me and if you look at the left there’s a big section where it’s just one part one code and then all the other parts are broken down into different bits in and out of date or something
11/22/2024 at 6:37 PM #240670But Patrick, you engaged Walk Forward (see the tabs below). You should select Off there. Unless you want to test “walk forward” of course. But I don’t think you want that.
1 user thanked author for this post.
11/22/2024 at 6:52 PM #240672You have made active ‘Walk Forward’. If you make Walk Forward as Inactive then you will have a straightforward Optimiser … which I’m sure you will easily se how it works/
1 user thanked author for this post.
11/22/2024 at 9:35 PM #240677THANNK YOU BOTH THIS FEELS LIKE IT ONLY GOING TO GET HARDER FROM HERE OUT
11/22/2024 at 10:02 PM #240679 -
AuthorPosts
Find exclusive trading pro-tools on